Entity Framework eager loading GREAT GrandChildren

943 views Asked by At

There are hundreds of examples of loading Entity Framework objects with the include statement but they stop short of Great GrandChild objects.

I have a complex object linked to about 48 tables, some of which go beyond the simple parent.child.grandchild code provided. Specifically I have a pattern object with a child entities that holds address entities that holds address field entities. (Among other entities it is holding.)

Here is the usual solution to the address grand child:

context.StagingPatternSet.Include( sp => sp.StagingPatternEntities.Select( e => e.StagingPatternAddresses ).ToList();

but how does one add the StagingPatternAddressFields to the list which is child to StagingPatternAddresses. Linq has nothing to add beyond the first select that I can find.

Linq to SQL has a wonderful extension that lets me define it with the DataLoadOptions...

var dlo = new DataLoadOptions();
dlo.LoadWith<StagingPattern>( p => p.StagingPatternEntities );
dlo.LoadWith<StagingPatternEntity>( e => e.StagingPatternAddresses );
dlo.LoadWith<StagingPatternAddress>( a => a.StagingPatternAddressFields );

but alas, this is not available to context DbSets. You set it to the LoadOptions of your SQL db. I would most appreciate if anyone has an elegant solution to this problem.

Kent

0

There are 0 answers