How to Generate dynamic IpredicateExpresion , IRelationPredicate and Ipredicate

Posts   
 
    
e.mousavi
User
Posts: 1
Joined: 15-Feb-2008
# Posted on: 15-Feb-2008 11:09:28   

Hello !

how can i create some predicate for fetching typelists or entity collection that is creating dynamically

for example i have this Query that i want to write it by using ipredicateeexpresion in llbl by the way i have an array that contions all of Ids

like int[] Id = new int[6] ; Id={1,2,3,4,5,6}

select * from Table1 where (( Id = 1 or Id = 2 or Id = 3 or Id = 4 ) and Id = 5 ) or Id = 6

so how can i generate this run time

Walaa avatar
Walaa
Support Team
Posts: 14995
Joined: 21-Aug-2005
# Posted on: 15-Feb-2008 14:29:53   

If I got it right, the query should be written as:

SELECT * FROM Table1 
WHERE (Id IN (1, 2, 3, 4 ) AND Id = 5 ) 
OR Id = 6

And this can be formulated by LLBLGen as follows:

int[] values= new int[4] ;
values  = {1,2,3,4}

PredicateExpression innerfilter = new PredicateExpression();
innerfilter.Add(Table1Fields.Id == values);
innerfilter.Add(Table1Fields.Id == 5)

PredicateExpression filter = new PredicateExpression();
filter.Add(innerFilter);
filter.AddWithOr(Table1Fields.Id == 6);