Predicate IN Statement

Posts   
 
    
shahab
User
Posts: 4
Joined: 24-Feb-2006
# Posted on: 24-Feb-2006 06:24:32   

I have a requirement where I need to execute the follwing sql statement but for some reason I can't get it any help or directions would be most appreciated;

select columnA from TableA where ColumnA not IN (select ColumnA from TableB) or ColumnC=1

=== I have followed the example in the help file but I can't get it going

here is the code : Dim b As RelationPredicateBucket = New RelationPredicateBucket

b.PredicateExpression.Add(New FieldCompareSetPredicate( _ EntityFieldFactory.Create(DAL.TableA.ColumnA), Nothing, _ EntityFieldFactory.Create(DAL.TableB.ColumnA), Nothing, _ SetOperator.In, _ PredicateFactory.CompareValue(DAL.TableB.ColumnA, _ ComparisonOperator.Equal, False)))

Walaa avatar
Walaa
Support Team
Posts: 14995
Joined: 21-Aug-2005
# Posted on: 24-Feb-2006 07:37:52   
IPredicateExpression filter = new PredicateExpression();            
filter.Add(new FieldCompareSetPredicate(EntityFieldFactory.Create(TableAIndex.columnA), null, EntityFieldFactory.Create(TableBFieldIndex.ColumnA), null,SetOperator.In, null, true));
filter.AddWithOr(PredicateFactory.CompareValue(TableAFieldIndex.ColumnC, ComparisonOperator.Equal, 1));
RelationPredicateBucket Bucket = new RelationPredicateBucket();
Bucket.PredicateExpression.Add(filter);

please note the last parameter in the FieldCompareSetPredicate should be true (negate flag) since you want NOT IN, set it to false if you only need IN, Also the interntal filter you are using is applied to the internal Query, I set it to null since you don't need it as shown by your example.

shahab
User
Posts: 4
Joined: 24-Feb-2006
# Posted on: 24-Feb-2006 14:34:51   

Thanks very much for your help.It worked like a charm smile