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

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

I have an Item. Item has a Category.

Category has ID, Name, Parent

15条回答
  •  醉梦人生
    2020-11-28 22:17

    Instead of using the Include method you could use Load.

    You could then do a for each and loop through all the children, loading their children. Then do a for each through their children, and so on.

    The number of levels down you go will be hard coded in the number of for each loops you have.

    Here is an example of using Load: http://msdn.microsoft.com/en-us/library/bb896249.aspx

提交回复
热议问题