Method to return PrefetchPath object with two roots

Posts   
 
    
Gabbo
User
Posts: 56
Joined: 12-Jun-2006
# Posted on: 12-Mar-2013 18:24:35   

Hi,

In the following article:

http://www.llblgening.com/archive/2009/10/prefetchpaths-in-depth/

It's inferred that one can create a method to return a PrefetchPath object:

Code (LINQ2LLBL – PathEdges variant)

var qq = (from o in metaData.PurchaseOrder where o.PurchaseOrderId == 4002 select o).WithPath(myOrderPath).First();

Where the **myOrderPath **variable returns the following PrefetchPath:

new PathEdge<ShipMethodEntity>(
    PurchaseOrderEntity.PrefetchPathShipMethod),
new PathEdge<EmployeeEntity>(
    PurchaseOrderEntity.PrefetchPathEmployee)

Is it possible to use the same PathEdge syntax above in a function or variable assignment? If so, what would it look like? If not, does that mean the "standard" LLBLGen prefetch path syntax would be used?

Thanks!

daelmo avatar
daelmo
Support Team
Posts: 8245
Joined: 28-Nov-2005
# Posted on: 13-Mar-2013 06:39:17   

Actually the prefetch path you are talking about is created using an IPrefetchPath2:

// prepare prefetch (order -> shipMethod,  order -> employee)
IPrefetchPath2 myOrderPath = new PrefetchPath2((int)EntityType.PurchaseOrderEntity);
myOrderPath.Add(PurchaseOrderEntity.PrefetchPathShipMethod);
myOrderPath.Add(PurchaseOrderEntity.PrefetchPathEmployee);
...
var qq = (from o in metaData.PurchaseOrder
         where o.PurchaseOrderId == 4002
         select o).WithPath(myOrderPath).First();

... from LLBLGen'ing:

LLBLGen'ing wrote:

... Note that we are passing a PrefetchPath object to the WithPath method extension. This demonstrates that the IPrefetchPats are totally reusable, even in path-edged linq2llbl code.

So, to answer your question: yes, you can use that PrefetchPath instance as a variable or as a return type in a method and re-use it in a PathEdge's LINQ2LLBL query or with a LLBLGen API object:

private IPrefetchPath2 GiveMeTheOrderPath()
{
     IPrefetchPath2 pathToReturn= new PrefetchPath2((int)EntityType.PurchaseOrderEntity);
     pathToReturn.Add(PurchaseOrderEntity.PrefetchPathShipMethod);
     pathToReturn.Add(PurchaseOrderEntity.PrefetchPathEmployee);

     return myOrderPath;
}

...
var orderPath = GiveMeTheOrderPath();
adapter.FetchEntityCollection(myOrders, null, orderPath );
...
var qq = (from o in metaData.PurchaseOrder
         select o).WithPath(orderPath ).First();
David Elizondo | LLBLGen Support Team