Filter on prefetched entities based on root value

Posts   
 
    
jshy
User
Posts: 1
Joined: 21-Sep-2010
# Posted on: 21-Sep-2010 22:56:17   

Is this possible: filter on the prefetched entities by a value from the root entity?

To use the customer - order example, get all customers that ordered something on their birthdays and only those orders

I tried the following but did not work. I always get all orders vs just the orders on the birthdays.

EntityCollection<Customer> customers = new EntityCollectioni<Customer>(); PrefetchPath2 prefetch = new PrefetchPath2((int)EntityType.CustomerEntity);

RelationCollection relations = new RelationCollection(); relations.Add(CustomerEntity.Relations.OrderEntityUsingCustomerId);

IPredicate filter = new PredicateExpression(OrderFields.Date == CustomerFields.Birthday); prefetch.Add(CustomerEntity.PrefetchPath.Orders, 100, filter, relations);

MTrinder
User
Posts: 1461
Joined: 08-Oct-2008
# Posted on: 21-Sep-2010 23:01:04   

I don't think this is possible the way you are trying to do it. What SQL does this generate...?

You could use a ScalarQueryExpression in the Order filter to get the value of the birthdate for the related customer - see http://www.llblgen.com/documentation/2.6/Using%20the%20generated%20code/gencode_expressionsaggregates.htm#scalarqueryexpressions for details.

Matt