0
我想知道是否有人可以告訴我如何解決關於使用FluentAPI來映射幾個表的問題。映射不尋常的表關係
我有父表有我們的密鑰稱爲ID 然後有兩個字段idA & idB的子表。
父表中的主鍵鏈接到idA或idB,而不是兩者。
public Parent()
{
this.ChildA = new HashSet<Child>();
this.ChildA = new HashSet<Child>();
}
public virtual ICollection<Child> ChildA { get; set; }
public virtual ICollection<Child> ChildB{ get; set; }
}
public Child()
public virtual Parent parent { get; set; }
}
有很多我可以做的關係/表設計,因爲它是遺留的,不能改變。只需要瞭解用於解決此問題的正確FluentAPI。上面的例子,它是我所設想的將需要與類似的東西...
modelBuilder.Entity<Child>().HasRequired<Parent>(p => p.parent).WithMany(q => q.childs).HasForeignKey(r => r.idA);
modelBuilder.Entity<Child>().HasRequired<Parent>(p => p.parent).WithMany(q => q.childs).HasForeignKey(r => r.idB);
子表根本沒有PK。只是這個愚蠢的參考頭痛。謝謝,我會給這個好去處,非常感謝你的幫助。 –