Prefetch Path exception...

Posts   
 
    
ABOH
User
Posts: 148
Joined: 06-Sep-2011
# Posted on: 05-Oct-2011 09:18:42   

Hello,

I am trying to prefetch the the following tree, but my query causes the following exception. I've read "Linq to LLBLGen Pro, Prefetch paths" in order to create my query, but it keeps failing. Can you please tell me what is wrong?

Thank you for your help,

Mike


The prefetch path element at index 0 in the passed in prefetch path for root entity type 0 is meant for root entity type 1 which isn't a subtype of 0. 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.

PREFETCH TREE NEEDED:
Customer CustomerProducts Product Vendor Licenses

RELATIONSHIPS: Customer (1) ---- (n) CustomerProduct (n) ---- (1) Product Product (n) ---- (1) Vendor Product (1) ---- (n) License

QUERY: var adapter = new DataAccessAdapter(); LinqMetaData linq = new LinqMetaData(adapter); var customers = (from c in linq.Customer select c).WithPath ( new PathEdge<CustomerProductEntity> ( CustomerProductEntity.PrefetchPathProduct, new PathEdge<ProductEntity>(ProductEntity.PrefetchPathVendor), new PathEdge<ProductEntity>(ProductEntity.PrefetchPathLicenses) ) );

Walaa avatar
Walaa
Support Team
Posts: 14993
Joined: 21-Aug-2005
# Posted on: 05-Oct-2011 09:55:43   

You are not specifying the correct Prefetchath for each return Type. Please check the following doc example:

var q = (from c in metaData.Customer where c.Country=="Germany" select c) .WithPath( new PathEdge<OrderEntity>( CustomerEntity.PrefetchPathOrders, new PathEdge<OrderDetailsEntity>(OrderEntity.PrefetchPathOrderDetails), new PathEdge<EmployeeEntity>(OrderEntity.PrefetchPathEmployee)));

ABOH
User
Posts: 148
Joined: 06-Sep-2011
# Posted on: 05-Oct-2011 11:51:37   

Hi Walaa,

Thank you for your quick response... I am new to LLBLGEN and, unfortunately, do not understand your response. The example that you gave is the one that I have been using from your user's manual in my attempts to figure out the prefetch path. Can you please provide more details? I am sure that it will help others who are learning about LLBLGEN's method to prefetch.

Thanks,

Mike

Walaa avatar
Walaa
Support Team
Posts: 14993
Joined: 21-Aug-2005
# Posted on: 05-Oct-2011 12:16:37   

Explaining the example I've posted.

The main entity you are fetching is the Customer Entity. That's why the first prefetchPath must starts from the CustomerEntity.

CustomerEntity.PrefetchPathOrders

And since it's there to prefetch Orders, the expected type for this PathEdge is the OrderEntity. This should explain this part:

new PathEdge<OrderEntity>(
                    CustomerEntity.PrefetchPathOrders

Similarly since this pathEdge is fetching Orders, if you need to sub-Prefetch another entities, you should strat from the OrderEntity.

This explains the list of SubPaths used with the OrderEntity

new PathEdge<OrderDetailsEntity>(OrderEntity.PrefetchPathOrderDetails),
new PathEdge<EmployeeEntity>(OrderEntity.PrefetchPathEmployee)));

So in short the above code was fetching Customers, and prefetching the Orders. And Sub-Prefetching OrderDetails and the Employees of the Orders.

ABOH
User
Posts: 148
Joined: 06-Sep-2011
# Posted on: 05-Oct-2011 12:58:07   

Hi Walaa,

Thank you very much for the detailed explanation! It was very helpful! I've adjusted our query and it is working properly. In case another user wants to see our final query, here it is:

var customers = (from c in linq.Customer select c).WithPath ( new PathEdge<CustomerProductEntity> ( CustomerEntity.PrefetchPathCustomerProducts,

    new PathEdge<ProductEntity>
    (
        CustomerProductEntity.PrefetchPathProduct,

        new PathEdge<VendorEntity>(ProductEntity.PrefetchPathVendor),

        new PathEdge<LicenseEntity>(ProductEntity.PrefetchPathLicenses)
    )
)

);