Question

I'm trying to configure the proper syntax for breeze.js when mixing AND and OR predicates. I did not see an example on the breeze site and could not find one anywhere else.

Basically I want to do something like this in my WHERE clause:

(
age > 30  AND
sex == 'M' AND
jobStartDate >= '1/1/2000'
)

OR

(
exemptStatus == 1
)

this will bring back entities that match the 3 criteria OR are exempt. I'm using EF6 with ODATA syntax.

Thanks

Was it helpful?

Solution

Try this:

    var Predicate = breeze.Predicate;
    var baseQuery = EntityQuery.from("Something");
    var pred1 = new Predicate("age", ">", 30);
    var pred2 = new Predicate("sex", "==", 'M');
    var pred3 = new Predicate("jobStartDate", ">=", new Date(2000,1,1));
    var pred4 = new Predicate("exemptStatus", "==", 1);
    var compositePred = pred1.and(pred2).and(pred3).or(pred4);
    var query = baseQuery.where(compositePredicate);
    myEntityManager.executeQuery(query);

or

    var compositePred = Predicate.and(pred1, pred2, pred3).or(pred4);
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top