Fetching Collection with Predicate on Parent and Child

Posts   
 
    
Angus
User
Posts: 44
Joined: 08-Jul-2005
# Posted on: 09-Jul-2010 22:06:43   

Ok I’m feeling kind of dumb here as I think this should be easy to do but I’m having trouble thinking today. flushed

I'm using LLBLGenPro 2.6 SQL Server 2005 Adapter Pattern

Here is the problem I’m trying to solve.

Let’s use the standard Northwind db as an example.

We have two tables ‘Customer’ and ‘Orders’

I’m trying to fetch a collection of Customers with their Orders.

I’m creating a prefetch from Customer -> Orders.
I want to filer the collection based on two criteria. One on the Customer and 1 on the Order

For example I want to get back only the Customers in ‘Germany’ who had placed Orders on a specific date, let’s say ‘6/28/2009’

So in the final result I don’t want any customers that are not in Germany. I do not want customers in Germany who don’t have any orders. I don’t want customers in Germany who did not place any orders on ‘6/28/2009’.

Thanks for any help you can give.

Angus
User
Posts: 44
Joined: 08-Jul-2005
# Posted on: 09-Jul-2010 22:40:09   

OK... Brain is working again... stuck_out_tongue_winking_eye

Here is the code that works.


var filter = new RelationPredicateBucket();
filter.PredicateExpression.AddWithAnd(CustomerFields.Country == "Germany"); 
filter.PredicateExpression.AddWithAnd(OrderFields.OrderDate == "6/28/2009");
filter.Relations.Add(OrderEntity.Relations.CustomerEntityUsingCustomerId);

It was the last line


filter.Relations.Add(OrderEntity.Relations.CustomerEntityUsingCustomerId);

that I was leaving out the was causing the issue.

I just thought I would post this in case anyone else had a similar issue with their thinking.

Thanks -Chris