2

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

Kent G
  • 21
  • 3
  • Why don't you just add another select on `e.StagingPatternAddresses`? Note that you can also do `context.StagingPatternSet.Include("StagingPatternEntities.StagingPatternAddresses.StagingPatternAddressFields");`. – Jeroen Vannevel Jun 16 '15 at 16:31
  • Confirmed, that the second Linq Select works. I seem to have been trying to place the second select in the wrong place. but the line now reads: ctx.pattern.Include( sp => sp.StagingPatternEntities.Select( e => e.StagingPatternAddresses.Select( a => a.StagingPatternAddressFields) ) )The performance on the text version is pitifully slow, and the reason I don't want to do that. Thanks – Kent G Jun 16 '15 at 16:57
  • Alright, good to hear. I'll mark it as a duplicate then. – Jeroen Vannevel Jun 16 '15 at 17:10
  • possible duplicate of [Entity Framework - Include Multiple Levels of Properties](http://stackoverflow.com/questions/10822656/entity-framework-include-multiple-levels-of-properties) – Jeroen Vannevel Jun 16 '15 at 17:10
  • 1
    @JeroenVannevel, your comment should be the answer. But it’s not a duplicate, because other question goes to grandchildren only. – Michael Freidgeim Sep 04 '18 at 13:42

0 Answers0