Issue with prefetch path and related entity

Posts   
 
    
nbrake
User
Posts: 30
Joined: 18-May-2008
# Posted on: 14-Feb-2012 14:50:39   

Hi there!

I am using 3.1 Final September 30th, 2011, downloaded today. I am using Adapter with dot.net 4.0. SD.LLBLGen.Pro.ORMSupportClasses.NET20.dll is 3.1.11.1129 SD.LLBLGen.Pro.LinqSupportClasses.NET35.dll is 3.1.11.1115 SD.LLBLGen.Pro.DQE.SqlServer.NET20.dll is 3.1.11.0706

I have the following structure: - User - Order - OrderDetail

A user can edit an order as well as an order-detail, and so I have FKs (Model only) that assign user to order as well as order-detail. when I fetch an order, I need to "prefetch" all the users that edited the order and all its order-details elements. This is the definition of the prefetch path I am using:

IPrefetchPath2 prefetchPath = new PrefetchPath2((int)EntityType.Order)
    {
OrderEntity.PrefetchPathOrderDetails.SubPath.Add(OrderDetailEntity.PrefetchPathUser),
OrderEntity.PrefetchPathUser
    }

When I run the query I am getting the following exception

The prefetch path element at index 1 in the passed in prefetch path for root entity type 1 is meant for root entity type 3 which isn't a subtype of 1. This means that you've added a prefetch path node to a Path of an unrelated entity, for example adding OrderDetailsEntity.PrefetchPathProduct to a prefetch path for CustomerEntity.

How do I need to describe the prefetch path in order for this query to work?

Thank you for your support!

daelmo avatar
daelmo
Support Team
Posts: 8245
Joined: 28-Nov-2005
# Posted on: 14-Feb-2012 19:53:20   

Hi there,

The ...SubPath.Add(... returns an IPrefetchPathElement that, as a matter of fact, is the User node, which is then added to the main path and that is invalid. Do it this way instead:

IPrefetchPath2 prefetchPath = new PrefetchPath2((int)EntityType.Order);

// add order-user
prefetchPath.Add(OrderEntity.PrefetchPathUser);

// add order-orderDetail-user
var detailPath = OrderEntity.PrefetchPathOrderDetails;
detailPath.SubPath.Add(OrderDetailEntity.PrefetchPathUser);
prefetchPath.Add(detailPath);
David Elizondo | LLBLGen Support Team
nbrake
User
Posts: 30
Joined: 18-May-2008
# Posted on: 14-Feb-2012 20:39:34   

Thank you very much for your assistance! This worked!!