[英]Creating Navigation Property without foreign key?
我正在嘗試使用現有數據庫為我的數據模型創建導航屬性。 數據具有共享密鑰(如外鍵),但是在數據庫中未指定共享密鑰。 看起來像這樣:
[Table("Alpha")]
public class Alpha
{
public int AlphaID { get; set; }
public int AlphaGroupID { get; set; }
public int? ParentAlphaID { get; set; }
public int? CodeID { get; set; }
public int? BracketCodeID { get; set; }
public string Title { get; set; }
}
[Table("AlphaGroup")]
public class AlphaGroup
{
[Column("AlphaGroupID")]
public int AlphaGroupID { get; set; }
public string Title { get; set; }
public string TitleAddon { get; set; }
}
AlphaGroupID必須是AlphaGroupID的導航屬性,但不是外鍵。 有沒有辦法做到這一點?
一種方法可以在父類中使用icollection,例如您的示例:
public virtual ICollection<AlphaGroup> AlphaGroup { get; set; }
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.