0
我有一個用戶模型與市,鎮,區表的導航屬性:導航性能
public class User
{
...
public virtual Location_City City { get; set; }
public virtual Location_Town Town { get; set; }
public virtual Location_District District { get; set; }
}
我想在一個單獨的類組這些屬性,並重新使用該類相反,如下圖所示:
public class Location
{
public virtual Location_City City { get; set; }
public virtual Location_Town Town { get; set; }
public virtual Location_District District { get; set; }
}
public class User
{
...
public Location Location { get; set; }
public Location ContactPersonLocation {get; set;}
}
我試圖其中I除去虛擬從位置類,並設置各種組合用戶類的導航屬性的位置屬性,而不是,但我收到以下錯誤:
EntityType 'Location' has no key defined. Define the key for this EntityType. Locations: EntityType: EntitySet 'Locations' is based on type 'Location' that has no keys defined.
是否有可能有導航屬性在一個單獨的類或是否需要創建一個單獨的表?
謝謝,我確實創建了一個聯結表:) –