New Posts New Posts RSS Feed: Include child of child
  FAQ FAQ  Forum Search   Calendar   Register Register  Login Login

Include child of child

 Post Reply Post Reply
Author
scottarlp View Drop Down
Newbie
Newbie


Joined: 07-Apr-2011
Posts: 26
Post Options Post Options   Quote scottarlp Quote  Post ReplyReply Direct Link To This Post Topic: Include child of child
    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
Back to Top
DenisK View Drop Down
IdeaBlade
IdeaBlade


Joined: 25-Aug-2010
Posts: 715
Post Options Post Options   Quote DenisK Quote  Post ReplyReply Direct Link To This Post 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();


Hope this helps.


Back to Top
 Post Reply Post Reply

Forum Jump Forum Permissions View Drop Down