Print Page | Close Window

Include child of child

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=3107
Printed Date: 12-Apr-2026 at 12:24pm


Topic: Include child of child
Posted By: scottarlp
Subject: Include child of child
Date Posted: 23-Nov-2011 at 9:57am
I've got what is probably a silly problem. I want to include the child of a child in my query. The problem appears to be the fact that my grandchild is m:1 and the only syntax I see examples for (and work) are for 1:m. I have the following type of data.
 
Order - Standard type of order example.
Order Detail - 1:m with Order, the line items of an order.
Product - Referenced by Order Detail as m:1 (Order Detail : Product).
 
I've got a query something like the following.
 
var query =
manager.Order
.Include(Order.PathFor(order => order.OrderDetails);
 
This works fine and fetches from the db once as expected. However, I'm trying to display product for the Order Detail in a grid and since it's not included (or in cache at the time), it does a lazy call for every record to retrieve the Product record.
 
In the examples of using 1:m includes, it looks like you can do this:
 
var query =
manager.Order
.Include(Order.PathFor(order => order.OrderDetails)
.Include(Order.PathFor(order => order.OrderDetails.Products);
 
But since that relationship is m:1, you don't get an option for the Products relation. Is there some other way other than just flat querying the Product table to load it in cache (in my real example, it's actually several related tables).
 
Thanks,
Scott



Replies:
Posted By: DenisK
Date Posted: 23-Nov-2011 at 12:42pm
Hi Scott;

In this case, we actually need to use the non-strongly typed version of Include.

manager.Orders.Include("OrderDetails.Product").Execute();

Please see  http://drc.ideablade.com/xwiki/bin/view/Documentation/include-related-entities - http://drc.ideablade.com/xwiki/bin/view/Documentation/include-related-entities  for more details.

Hope this helps.





Print Page | Close Window