1

I've a Following hierarchy of entitites

 class ClassA { ICollection<ClassB> classBs { get; set; } } class ClassB { ClassC classC { get; set; } ClassD classD { get; set; } } class ClassC { } class ClassD { } 

I want that when I load an instance of classA, then all the related instance of classB and their related instances of ClassC and classD should get populated. The code written in my repositories is something like:

 context.ClassAs.Include(c => c.classBs) 

This returns all the related instances of classBs, but the classB has classC and ClassD, which doesn't get populated. I looked at some resources online, but it didn't show how to eager load this simple kind of hierarchy. Any help would be really appreciated.

1 Answer 1

2

One solution would be to use Select to include only children of children you want loaded, e.g.

context.ClassAs .Include(c => c.classBs.Select(c=>c.ClassC)) .Include(c => c.classBs.Select(d=>d.ClassD)) 
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.