2016-11-30 48 views

回答

0

您可以創建一個主複合鍵

public class YourEntity 
{ 
[Column(Order = 0), Key, ForeignKey("FieldFromAnotherTable_1")] 
public int FieldFromAnotherTable_1_ID { get; set; } 

[Column(Order = 1), Key, ForeignKey("FieldFromAnotherTable_2")] 
public int FieldFromAnotherTable_2_ID { get; set; } 

public virtual Type1 FieldFromAnotherTable_1{ get; set; } 
public virtual Type2 FieldFromAnotherTable_2{ get; set; } 

} 
+0

非常感謝你:)你的評論後,我發現如何做到這一點 – Katniss

0

您可以標記從其它表的ID`s與關鍵屬性。 EF會看到這一點,並從這些列中創建一個主鍵。

此外,您還可以閱讀這篇文章Creating Composite Key Entity Framework

+0

感謝您的幫助:) – Katniss