[英]more than one navigation to the same entity
當有2個導航時,我有2個實體之間的連接問題。
具體來說,我有以下幾類:
public class TableA
{
public TableA()
{
ListBs = new List<TableB>();
}
[Key]
public int Id { get; set; }
public TableB MainB { get; set; }
public virtual ICollection<TableB> ListBs { get; set; }
}
public class TableB
{
[Key]
public int Id { get; set; }
public virtual TableA refA { get; set; }
[Required]
public string Text { get; set; }
}
此特定類的方案反映了以下內容:TableA具有TableB對象的列表,並且還具有1個主TableB對象(當然也在列表中)。 另外,TableB對象可能實際上不具有對TableA的引用
提取工作。 但是當我嘗試插入新項目時,我得到以下異常:
無法確定相關操作的有效排序。 由於外鍵約束,模型要求或存儲生成的值,可能存在依賴關系。
知道我哪里弄錯了嗎?
使用此代碼:
public class TableA
{
public TableA()
{
ListBs = new List<TableB>();
}
[Key]
public int Id { get; set; }
public int TableB_Id { get; set; }
[InverseProperty("TableA_Mains")]
[ForeignKey("TableB_Id")]
public TableB MainB { get; set; }
[InverseProperty("refA")]
public virtual ICollection<TableB> ListBs { get; set; }
}
public class TableB
{
[Key]
public int Id { get; set; }
public int TableA_Id { get; set; }
[Foreignkey("TableA_Id")]
[InverseProperty("ListBs")]
public virtual TableA refA { get; set; }
[Required]
public string Text { get; set; }
[InverseProperty("MainB")]
public virtual ICollection<TableA> TableA_Mains { get; set; }
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.