Print Page | Close Window

Eager Loading Entire Graph

Printed From: IdeaBlade
Category: DevForce
Forum Name: DevForce 2010
Forum Discription: For .NET 4.0
URL: http://www.ideablade.com/forum/forum_posts.asp?TID=2085
Printed Date: 21-Sep-2025 at 5:13am


Topic: Eager Loading Entire Graph
Posted By: mdcalhoun
Subject: Eager Loading Entire Graph
Date Posted: 23-Aug-2010 at 1:48pm
Hello,
 
Is there a way to easily load the entire entity graph for a specific object?
 
For example,
 
Deal has N Deal Versions.
Deal Version has N Price Groups.
Price Group has N Price Items.
Price Item has N Products
 
I'd like to do a single query for a deal that brings back Deal and all children (Version, Price Group, Price Item).
 
Thanks,
Matt



Replies:
Posted By: ting
Date Posted: 23-Aug-2010 at 6:27pm
Hi Matt,
 
The code should look like this:
 
entityManager.Deals.Where(...)
  .Include("DealVersions")
  .Include("DealVersions.PriceGroups")
  .Include("DealVersions.PriceGroups.PriceItems")
  .Include("DealVersions.PriceGroups.PriceItems.Products")
 
The first path can also be written in a strongly typed manner:
  .Include(Deals.PathFor(deal => deal.DealVersions))
 
However, this doesn't work when navigating through collections, so you have to do the rest by string.
 



Print Page | Close Window