Difference between PrefetchPathToUse and FilterToUse.Relations

Posts   
 
    
benjam47
User
Posts: 13
Joined: 09-Apr-2008
# Posted on: 23-Sep-2008 00:13:18   

Hi,

I was having an issue for a while using the LLBLGen Adapter datasource control to a RadGrid where sorting columns on related fields was not working because the generated SQL was not joining the related fields, even though I had set up a PrefetchPathToUse.

A search on this forum resolved this problem by having me add Relations to .FilterToUse as well.

Can someone help me understand the difference between the two? I thought that establishing the PrefetchPathToUse would have required LLBL to creation the relationship implicitely.

Thanks,

Cory

daelmo avatar
daelmo
Support Team
Posts: 8245
Joined: 28-Nov-2005
# Posted on: 23-Sep-2008 07:13:47   

Hi Cory,

FilterToUse FilterToUse is the IRelationalPredicateBucket (IPredicateExpression + IRelationCollection) used to filter the main collection. To sort or filter on related entities/entitycollections, the relationCollection is needed to build the WHERE clause correctly. For example: you want to retrieve all OrderDetails whose related products are discounted... Note that you don't want to prefetch (fetch additional entity/entitycollection and attach it to OrderDetails results):

EntityCollection<OrderDetailEntity> details = new EntityCollection<OrderDetailEntity>();
IRelationPredicateBucket filter = new RelationPredicateBucket();

// needed to relate customers and products
filter.Relations.Add(OrderDetailEntity.Relations.ProductEntityUsingProductId);

// To be able to reach products in the filter, the above relation is needed
filter.PredicateExpression.Add(ProductFields.Discounted == true);

PrefetchPath When you prefetch, a different query is performed. So it is another history. Including a prefetchPath doesn't necessarily means that you want to include relations (JOINS) in your query. Indeed, you may want to perform additional filter/sort on the attached prefetchPath.

For example, you want to retrieve all Customers and their orders (just that, you don't want to filter or sort):

EntityCollection<CustomerEntity> customers = new EntityCollection<CustomerEntity>();

IPrefetchPath2 path = new PrefetchPath2((int) EntityType.CustomerEntity);
path.Add(CustomerEntity.PrefetchPathOrders);

You of course, could filter/sort the customer collection, you also could filter/sort the orders path. However they are different retrievals simple_smile

David Elizondo | LLBLGen Support Team
benjam47
User
Posts: 13
Joined: 09-Apr-2008
# Posted on: 24-Sep-2008 06:46:25   

Thank you.

So, am I correct in saying that a FilterToUse.Relations is used to filter/sort based on related data but not retrieve it, and a PrefetchPathToUse is used to actually retrieve the related data into the EntityCollection? And therefore, depending on your situation, you will use one or the other or both?

Cory

daelmo avatar
daelmo
Support Team
Posts: 8245
Joined: 28-Nov-2005
# Posted on: 24-Sep-2008 06:51:38   

Yes, you are correct simple_smile

David Elizondo | LLBLGen Support Team
benjam47
User
Posts: 13
Joined: 09-Apr-2008
# Posted on: 24-Sep-2008 07:22:39   

Got it. Thanks.