0

我有三个类AddressUserApplication。两者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);
    }
4

0 回答 0