CFFPartDisp
モデル内のエンティティクラスとして公開する必要があります。CFFPart
質問のFluentマッピング間およびFluentマッピングとのリンクテーブルとして使用することはできませんDisp
。との間の関係は、多対多の関係CFFPart
ではありません(厳密なEFの意味で)。代わりに、中間エンティティとしてDisp
2つの1対多の関係を作成する必要があります。次に、この中間エンティティCFFPartDisp
間の関係を3番目の関係としてリンクできます。CFFPartDisp
Expert
エンティティは次のCFFPartDisp
ようになります。
public class CFFPartDisp
{
public int ID { get; set; }
public int CFFPartID { get; set; }
public CFFPart CFFPart { get; set; }
public int DispID { get; set; }
public Disp Disp { get; set; }
public ICollection<Expert> Experts { get; set; }
}
CFFPart
およびエンティティには、以下Disp
を参照するコレクションが必要ですCFFPartDisp
。
public class CFFPart
{
public int ID { get; set; }
public ICollection<CFFPartDisp> CFFPartDisps { get; set; }
}
public class Disp
{
public int ID { get; set; }
public ICollection<CFFPartDisp> CFFPartDisps { get; set; }
}
また、との間の多対多の関係を確立するためのExpert
コレクションも必要です。CFFPartDisp
CFFPartDisp
Expert
public class Expert
{
public int ID { get; set; }
public ICollection<CFFPartDisp> CFFPartDisps { get; set; }
}
これらのエンティティを使用して、次の3つの関係を作成できます。
modelBuilder.Entity<CFFPartDisp>()
.HasRequired(cpd => cpd.CFFPart)
.WithMany(cp => cp.CFFPartDisps)
.HasForeignKey(cpd => cpd.CFFPartID);
modelBuilder.Entity<CFFPartDisp>()
.HasRequired(cpd => cpd.Disp)
.WithMany(cp => cp.CFFPartDisps)
.HasForeignKey(cpd => cpd.DispID);
modelBuilder.Entity<CFFPartDisp>()
.HasMany(cpd => cpd.Experts)
.WithMany(e => e.CFFPartDisps)
.Map(m =>
{
m.MapLeftKey("CFFPartDispID");
m.MapRightKey("ExpertID");
m.ToTable("CFFpartDisPExpert");
});