2
モデルにはアイテムエンティティがあります。 また、(を使用してを使用している)他のアイテムに依存するアイテムがあります。多対多の関係。例:同じテーブル(EF7 /コア)を参照する多対多リレーションシップの定義
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; }
}