I have multi-leveled entities with the following hierarchy: Parent-> RootChildren -> Children -> Children -> .....
Class Parent
{
public int Id {get; set;}
public virtual Child RootChildren {get; set;}
}
Class Child
{
public virtual List<Child> Children {get; set;}
}
Now, I want to include entity which include all the child as nested way.
I tried the following but it didn't work:
var parents = dbContext.Parent
.Where(p => p.Id == id)
.Select(r => r.RootChildren)
.Include(c => c.Children)
.ToList();
It gives me result for first children but does not include all the nested children present in the tree.
Any piece of advise or information would be highly appreciated. Thanks!
ThenInclude(...)
docs.microsoft.com/en-us/ef/core/querying/related-data