Entity Framework 1-1(必填)关系是否自动执行级联删除?

Is Cascade Delete automatically performed in Entity Framework 1-1 (required) Relationships?

正在搜索 Entity Framework 的级联行为,如果注意到 this 答案。简而言之,OP 正在寻找一种在 Entity Framework 中对 1-0 / 1-1 关系执行级联删除的方法,最佳答案包含 Fluent API 应用 WillCascadeOnDelete(true); 的片段在数据库上下文的模型构建器上。

在所选答案中,用户 (CodeMonkey) 提到:

(...) Some have suggested [Required] for cascading delete. This indeed works, but of course, only if it is actually required

我的问题是,如果关系设置为 1-1(使用 [Required] 或什至不将关系设置为 EntityTypeConfiguration 的可选关系)且具有必需的依赖项,则默认执行级联删除,而无需必须将其设置为 Fluent API,如评论中所述?

If a foreign key on the dependent entity is not nullable, then Code First sets cascade delete on the relationship. If a foreign key on the dependent entity is nullable, Code First does not set cascade delete on the relationship, and when the principal is deleted the foreign key will be set to null. The multiplicity and cascade delete behavior detected by convention can be overridden by using the fluent API.

Code First Conventions