我有三个类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);
}