Filtering on collection

Posts   
 
    
Nozza
User
Posts: 1
Joined: 29-Feb-2008
# Posted on: 29-Feb-2008 16:33:36   

Hi,

I am looking to prefetch using the contents of a collection as a filter.

My database has a table of Subscribers which is linked to a Countries table.

In code, I have a collection of countries and want to query for subscribers who are not in these countries.

So, for example: Ben is from USA. Stan is from UK. Joe is from Sweden. Peter is from Germany.

I have a collection with two countries in it: Sweden and USA.

I want the subscribers who are not from Sweden and the USA. My query should return Stan and Peter.

How can I do this with LLBL?

Thanks, Tim

daelmo avatar
daelmo
Support Team
Posts: 8245
Joined: 28-Nov-2005
# Posted on: 29-Feb-2008 18:36:23   

You should use FieldCompareRangePredicate (Ref: LLBLGenPro Help - Using the generated code - (Adapter | SelfServicing ) - Filtering and sorting - The predicate system - The predicate classes - FieldCompareRangePredicate).

IRelationPredicateBucket bucket = new RelationPredicateBucket();
System.Collections.ArrayList values = new System.Collections.ArrayList();           

// fill the values variable with your in-memory collection
foreach (CountryEntity country in countries)
{
    values.Add(country.CountryId);                              
}

// note the 3th parameter, this indicates that the predicate is negate (NOT IN).
bucket.PredicateExpression.Add(new FieldCompareRangePredicate(
    SubscriberFields.CountryId, null, true, values));

// fetch results
// ...
David Elizondo | LLBLGen Support Team