Deep load all child entities

Sep 9, 2014 at 11:51 AM

What is best practice to deep load all child entities of an entity?

It is possible to use .Include(x=>x.childEntities) for one level, but I would like to load the childChildEntities of the childEntities

  • List<ChildEntitiy> ChildEntities
ChildEntity (How To load)
  • List<ChildChildEntity> ChildChildEntities
Sep 9, 2014 at 1:28 PM
Marked as answer by skuggbo on 9/9/2014 at 5:28 AM
Nov 25, 2014 at 9:29 PM
I am recently trying to implement this pattern. I looked at the example referenced in the link above (the third example), but I still don't understand how to get a fully hydrated Category object with the Products collection hydrated. Any help would be greatly appreciated.

Nov 25, 2014 at 11:22 PM
Please download and run the integration tests, as this use case is actually one of the tests.

Marked as answer by lelong37 on 11/25/2014 at 3:22 PM
Nov 26, 2014 at 2:10 PM
Thank you, lelong37. That is exactly what I was looking for.
Dec 9, 2014 at 9:44 PM
I am trying to extract an object with a collection of a child objects with a conditional Include but I get the error below. I am able to replicate error with Northwind database. Please see my modified query that causes error with Northwind (I added a "Where" on "Include" of "Orders". Any help would be appreciated.


Additional information: The Include path expression must refer to a navigation property defined on the type. Use dotted paths for reference navigation properties and the Select operator for collection navigation properties.

var query = unitOfWork.RepositoryAsync<Customer>()
.Query(c => c.CustomerID == "BOLID")
.Include(o => o.Orders.Where(o2 => o2.EmployeeID == 4))

Customer customer = query.Result.FirstOrDefault<Customer>();