How does Entity Framework work with recursive hierarchies? Include() seems not to work with it

前端 未结 15 1728
再見小時候
再見小時候 2020-11-28 21:53

I have an Item. Item has a Category.

Category has ID, Name, Parent

15条回答
  •  挽巷
    挽巷 (楼主)
    2020-11-28 22:32

    You chould rather introduce a mapping table that maps each Category a parent and a child, instead of adding the parent and child property to the cargo itself.

    Depending on how often you need that information it can be queried on demand. Via unique constraints in the db you can avoid an infinite amount of relationships beeing possible.

提交回复
热议问题