我有三个课程:Address
,User
和Application
。 User
和Application
都有一个地址字段。
用户:
[Required, ForeignKey("HomeAddress")]
public int HomeAddressId { get; set; }
public virtual Address HomeAddress { get; set; }
应用:
[Required, ForeignKey("PresentAddress")]
public int PresentAddressId { get; set; }
public virtual Address PresentAddress { get; set; }
我正在编写以下代码来解决“循环或多个级联路径”问题。我想删除Application
的级联删除。以下代码是否正确?
protected override void OnModelCreating(DbModelBuilder modelBuilder)
{
modelBuilder.Entity<Application>()
.HasRequired(x => x.PresentAddress)
.WithMany()
.HasForeignKey(x => x.PresentAddressId)
.WillCascadeOnDelete(false);
}