How to use implement predicate and ,or in nested way

Posts   
 
    
Posts: 87
Joined: 17-May-2011
# Posted on: 29-Jul-2011 08:45:44   

Hi there

I have query which I need to execute in a nested "and, or" form e.g. select * from students where student.isactive=true and(student.name like '%XYz%' or student.fathername like '%XYz%') and student.age > 13

Kindly tell me how to implement this in self service with predicate expression.

Walaa avatar
Walaa
Support Team
Posts: 14950
Joined: 21-Aug-2005
# Posted on: 29-Jul-2011 11:17:34   

PredicateExpressions have AddWithOr() and AddWithAnd() which can accept predicates, and also can accept another PredicateExpression (nested).

Posts: 87
Joined: 17-May-2011
# Posted on: 01-Aug-2011 08:20:20   

Can you please elaborate it?

Walaa avatar
Walaa
Support Team
Posts: 14950
Joined: 21-Aug-2005
# Posted on: 01-Aug-2011 09:00:45   

Here is a simple example:

var filter = new PredicateExpression(CustomerFields.Country == "UK");

var subFilter = new PredicateExpression(CustomerFileds.Country == "US");
subFilter.AddWithAnd(CustomerFileds.Type == "VIP");

filter.AddWithOr(subFilter);

The above would produce:

WHERE
Country = 'UK'
OR 
(Country = 'US' AND Type = 'VIP')