dave walker
dave walker

Reputation: 3108

Breeze implementation of 'AND' and 'OR' in the where method

Breeze can query for condition1 AND condition2 by using multiple where statements. But can it query for condition1 OR condition2?

If not, what is the recommended way of achieving the same effect when using Breeze?

I am currently thinking the only way to do this is to perform the query on the server with a special action method, which creates some problems.

Upvotes: 1

Views: 116

Answers (2)

dave walker
dave walker

Reputation: 3108

OK, the problem is the Breeze API and Docs are a little lacking with some typos.

The answer is to use the 'or' method of the Predicate class to create a new Predicate object that is passed to the where method.

Given 3 predicates you 'or' them together like so:

var newPred = p1.or(p2, p3);

or

var preds = [p2, p3];
var newPred = p1.or(preds);

or fluent method:

var p4 = Predicate.create("ShipCity", "startswith", "F")
.or("Size", "gt", 2000);

or using the static 'or' method

var newPred = Predicate.or(p1, p2, p3);

Upvotes: 2

Carlo Moretto
Carlo Moretto

Reputation: 365

Use the Predicate like this sample:

var p1 = new breeze.Predicate("IsArchived", "==", false);
var p2 = breeze.Predicate("IsDone", "==", false);
var predicate = p1.and(p2);

var query = new EntityQuery("Todos").where(predicate);

Documentation is available here: http://www.breezejs.com/documentation/query-filter

Upvotes: 2

Related Questions