[英]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.