【发布时间】:2016-03-24 10:12:56
【问题描述】:
模型具有 item 实体。 并且会有一些项目依赖于(使用)其他项目。多对多的关系。示例:
Item A is used by Item B, C, and F.
Item B is used by Item C, F and H.
如何正确定义不同项目之间的方向关系?
物品:
public class Item
{
public int Id
{ get; set;}
public string Name
{get; set;}
}
我定义依赖项的第一种方法是:
public class ItemDependency
{
[Key]
public int Id
{ get; set; }
[ForeignKey("ItemParentId")]
public Item ItemParent { get; set; }
public int ItemParentId{ get; set; }
[ForeignKey("ItemDependentId")]
public Item ItemDependentId { get; set; }
public int ItemDependentId { get; set; }
}
【问题讨论】:
标签: c# .net entity-framework many-to-many entity-framework-core