I've got an
as well as
When I do a LINQ to Entities search for a certain
it doesn't return the associated data.
even if I use the
method. However, it does not include the whole category, including its parent and children. I am capable.
but this object resembles a tree; it has a recursive structure, and I'm not sure how far it will go.
How can I get EF to completely load the
the parent with their parent and children, and so on, with parent and children?
For performance reasons, this is just something that would be required for one particular object, the Category, and not for the whole program.
Rather of employing the
technique you could choose
The children's children may then be loaded by doing a for each and looping through all the children. Do a favor for each, then for their offspring, and so on.
The amount of for each loops you have will have the number of levels down hard programmed in.
Here is an instance of using
If you are certain that you want the whole hierarchy loaded, I would suggest designing a stored procedure whose purpose is to return every item in a hierarchy while returning the initial object you request (and its children subsequently).
After then, let the EF's relationship maintenance make sure that everyone is connected.
For example, consider:
// the GetCategoryAndHierarchyById method is an enum Category c = ctx.GetCategoryAndHierarchyById(1).ToList().First();
If your stored method is properly constructed, materializing every object in the hierarchy (i.e.
) ought to trigger EF relationship fixup.
After that, all of the children of the item you want (First()), as well as the children of those children, should be loaded. No MARS issues either since everything would be filled in from that one stored procedure call.
Hope this is useful.