Prefetch paths and selected sub-entities

Posts   
 
    
shennig
User
Posts: 48
Joined: 14-Nov-2006
# Posted on: 16-Jan-2007 14:46:08   

Hi, i have a problem with prefetch path. i describe it in an example:

i want to select customer entities which have orders from 'London'. i also want to fetch the corresponding order entities for that customer entities - but also only those orders from 'London'. if customer x have two orders - one from 'Paris' and one from 'London' - i want this customer and the customer entity should have the order from 'London' but not from 'Paris'.

How could i realize this in Selfservicing oder Adapter manner?

i have tried this:



CustomerCollection oCustomers = new CustomerCollection();

IPrefetchPath prefetchPath = new PrefetchPath((int)EntityType.CustomerEntity);
prefetchPath.Add(CustomerEntity.PrefetchPathOrders);

RelationCollection relationsToUse = new RelationCollection();
relationsToUse.Add(CustomerEntity.Relations.OrdersEntityUsingCustomerid);

IPredicateExpression filter = new PredicateExpression();
filter.Add(OrdersFields.Place == 'London');

oCustomers .GetMulti(filter,0, null, relationsToUse, prefetchPath);


but i get also the order from 'Paris'. what's my fault?

thanks,

shennig

jbb avatar
jbb
User
Posts: 267
Joined: 29-Nov-2005
# Posted on: 16-Jan-2007 15:10:27   

Hello,

if you want to filter the content of your prefetchpath, you have to apply a filter to the prefetchpath directly. If you don't use a filter on a prefetchpath, the filter is apply for the root entity so you will have all client that have a command on london but not only on london. You could apply your filter like this :

CustomerCollection oCustomers = new CustomerCollection();

IPrefetchPath prefetchPath = new PrefetchPath((int)EntityType.CustomerEntity);
prefetchPath.Add(CustomerEntity.PrefetchPathOrders).filter=(OrdersFields.Place == 'London');

RelationCollection relationsToUse = new RelationCollection();
relationsToUse.Add(CustomerEntity.Relations.OrdersEntityUsingCustomerid);

IPredicateExpression filter = new PredicateExpression();
filter.Add(OrdersFields.Place == 'London');

oCustomers .GetMulti(filter,0, null, relationsToUse, prefetchPath);
shennig
User
Posts: 48
Joined: 14-Nov-2006
# Posted on: 16-Jan-2007 15:23:30   

thanks a lot.

that works!