EF 实体关系

  1. 基于共享主键的一对一:

    this.HasRequired(t => t.TRDConInfo)
    .WithOptional(t => t.TRDFoundationProjCheck);

  2. 一对多

    this.HasRequired(t => t.ComponentBelong)
    .WithMany(t => t.TRDConInfos)
    .HasForeignKey(d => d.ComponentBelongID);

  3. 多对多

    this.HasMany(t => t.Contract)
    .WithMany(t => t.DesignChangeAudit)
    .Map(m => {
    m.ToTable("T_Change_DesignAudit_Contract");
    m.MapLeftKey("DesignChangeAuditID");
    m.MapRightKey("ContractID");
    });

原文地址:https://www.cnblogs.com/zhangliming/p/4388198.html