predicate expression question

Posts   
 
    
e106199
User
Posts: 175
Joined: 09-Sep-2006
# Posted on: 29-Jun-2011 23:19:37   

Hi, i am trying to accomplish something like:

status = 1 AND year = 2 AND withdrawal = null AND admission <= today

OR

status = 1 AND year = 2 AND withdrawal != null AND withdrawal >= today

how can i build my expression here?

thanks

daelmo avatar
daelmo
Support Team
Posts: 8245
Joined: 28-Nov-2005
# Posted on: 30-Jun-2011 05:18:31   

e106199 wrote:

status = 1 AND year = 2 AND withdrawal = null AND admission <= today

Above is one predicate:

IPredicateExpression expr1 = new PredicateExpression(
   TransFields.Year == 2
   & TransFields.WithDrawal == null
   & TransFields.Admission <= DateTime.Now);

e106199 wrote:

status = 1 AND year = 2 AND withdrawal != null AND withdrawal >= today

this is another predicate:

IPredicateExpression expr2 = new PredicateExpression(
   TransFields.Status == 1
   & TransFields.Year == 2
   & TransFields.WithDrawal != null
   & TransFields.Admission >= DateTime.Now);

Then add those to the main filter:

IPredicateExpression filter = new PredicateExpression();
filter.Add(expr1);
filter.AddWithOr(expr2);

You also could use parenthesis:

IPredicateExpression expr1 = new PredicateExpression(
   ( TransFields.Year == 2
     & TransFields.WithDrawal == null
     & TransFields.Admission <= DateTime.Now )  |
   ( TransFields.Status == 1
   & TransFields.Year == 2
   & TransFields.WithDrawal != null
   & TransFields.Admission >= DateTime.Now) );

(more info...).

David Elizondo | LLBLGen Support Team