Show:

Predicate Class

Used to define a 'where' predicate for an EntityQuery. Predicates are immutable, which means that any method that would modify a Predicate actually returns a new Predicate.

Item Index

Methods

Methods

<ctor> Predicate

(
  • property
  • operator
  • value
)

Predicate constructor

Parameters:

  • property String

    A property name, a nested property name or an expression involving a property name.

  • operator FilterQueryOp | String
  • value Object
    • This will be treated as either a property expression or a literal depending on context. In general,
            if the value can be interpreted as a property expression it will be, otherwise it will be treated as a literal. 
            In most cases this works well, but you can also force the interpretation by making the value argument itself an object with a 'value' property and an 'isLiteral' property set to either true or false.
            Breeze also tries to infer the dataType of any literal based on context, if this fails you can force this inference by making the value argument an object with a 'value' property and a 'dataType'property set
            to one of the breeze.DataType enumeration instances.

Example:

var p1 = new Predicate("CompanyName", "StartsWith", "B");
var query = new EntityQuery("Customers").where(p1);

or

var p2 = new Predicate("Region", FilterQueryOp.Equals, null);
var query = new EntityQuery("Customers").where(p2);

and

(
  • predicates
)

'And's this Predicate with one or more other Predicates and returns a new 'composite' Predicate

Parameters:

  • predicates Multiple Predicates | Array of Predicate multiple

    Any null or undefined values passed in will be automatically filtered out before constructing the composite predicate.

Example:

var dt = new Date(88, 9, 12);
var p1 = Predicate.create("OrderDate", "ne", dt);
var p2 = Predicate.create("ShipCity", "startsWith", "C");
var p3 = Predicate.create("Freight", ">", 100);
var newPred = p1.and(p2, p3);

or

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

The 'and' method is also used to write "fluent" expressions

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

and

(
  • predicates
)
static

Creates a 'composite' Predicate by 'and'ing a set of specified Predicates together.

Parameters:

  • predicates Multiple Predicates | Array of Predicate multiple

    Any null or undefined values passed in will be automatically filtered out before constructing the composite predicate.

Example:

var dt = new Date(88, 9, 12);
var p1 = Predicate.create("OrderDate", "ne", dt);
var p2 = Predicate.create("ShipCity", "startsWith", "C");
var p3 = Predicate.create("Freight", ">", 100);
var newPred = Predicate.and(p1, p2, p3);

or

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

create

(
  • property
  • operator
  • value
)
static

Creates a new 'simple' Predicate. Note that this method can also take its parameters as an array.

Parameters:

  • property String

    A property name, a nested property name or an expression involving a property name.

  • operator FilterQueryOp | String
  • value Object
    • This will be treated as either a property expression or a literal depending on context. In general,
            if the value can be interpreted as a property expression it will be, otherwise it will be treated as a literal. 
            In most cases this works well, but you can also force the interpretation by making the value argument itself an object with a 'value' property and an 'isLiteral' property set to either true or false.
            Breeze also tries to infer the dataType of any literal based on context, if this fails you can force this inference by making the value argument an object with a 'value' property and a 'dataType'property set
            to one of the breeze.DataType enumeration instances.

Example:

var p1 = Predicate.create("Freight", "gt", 100);

or parameters can be passed as an array.

var predArgs = ["Freight", "gt", 100];
var p1 = Predicate.create(predArgs);

both of these are the same as

var p1 = new Predicate("Freight", "gt", 100);

not

(
  • predicate
)
static

Creates a 'composite' Predicate by 'negating' a specified predicate.

Parameters:

Example:

var p1 = Predicate.create("Freight", "gt", 100);
var not_p1 = Predicate.not(p1);

This can also be accomplished using the 'instance' version of the 'not' method

var not_p1 = p1.not();

Both of which would be the same as

var not_p1 = Predicate.create("Freight", "le", 100);

not

()

Returns the 'negated' version of this Predicate

Example:

var p1 = Predicate.create("Freight", "gt", 100);
var not_p1 = p1.not();

This can also be accomplished using the 'static' version of the 'not' method

var p1 = Predicate.create("Freight", "gt", 100);
var not_p1 = Predicate.not(p1);

which would be the same as

var not_p1 = Predicate.create("Freight", "le", 100);

or

(
  • predicates
)
static

Creates a 'composite' Predicate by 'or'ing a set of specified Predicates together.

Parameters:

  • predicates Multiple Predicates | Array of Predicate multiple

    Any null or undefined values passed in will be automatically filtered out before constructing the composite predicate.

Example:

var dt = new Date(88, 9, 12);
var p1 = Predicate.create("OrderDate", "ne", dt);
var p2 = Predicate.create("ShipCity", "startsWith", "C");
var p3 = Predicate.create("Freight", ">", 100);
var newPred = Predicate.or(p1, p2, p3);

or

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

or

(
  • predicates
)

'Or's this Predicate with one or more other Predicates and returns a new 'composite' Predicate

Parameters:

  • predicates Multiple Predicates | Array of Predicate multiple

    Any null or undefined values passed in will be automatically filtered out before constructing the composite predicate.

Example:

var dt = new Date(88, 9, 12);
var p1 = Predicate.create("OrderDate", "ne", dt);
var p2 = Predicate.create("ShipCity", "startsWith", "C");
var p3 = Predicate.create("Freight", ">", 100);
var newPred = p1.or(p2, p3);

or

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

The 'or' method is also used to write "fluent" expressions

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

toFunction

() Function

Returns the function that will be used to execute this Predicate against the local cache.

Returns:

Function:

toString

() String

Returns a human readable string for this Predicate.

Returns:

String:

validate

(
  • entityType
)

Determines whether this Predicate is 'valid' for the specified EntityType; This method will throw an exception if invalid.

Parameters:

  • entityType EntityType

    The entityType to validate against.