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
- <ctor> Predicate
- and
- and static
- create static
- isPredicate static
- not static
- not
- or static
- or
- toFunction
- toString
- validate
Methods
<ctor> Predicate
-
property -
operator -
value -
[valueIsLiteral]
Predicate constructor
Parameters:
-
propertyStringA property name, a nested property name or an expression involving a property name.
-
operatorFilterQueryOp | String -
valueObject- 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 setting the next parameter 'valueIsLiteral' to true.
-
[valueIsLiteral]Boolean optional- Used to force the 'value' parameter to be treated as a literal - otherwise this will be inferred based on the context.
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:
-
predicatesMultiple Predicates | Array of Predicate multiple
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
Creates a 'composite' Predicate by 'and'ing a set of specified Predicates together.
Parameters:
-
predicatesMultiple Predicates | Array of Predicate multiple
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 -
[valueIsLiteral]
Creates a new 'simple' Predicate. Note that this method can also take its parameters as an array.
Parameters:
-
propertyStringA property name, a nested property name or an expression involving a property name.
-
operatorFilterQueryOp | String -
valueObject- 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 setting the next parameter 'valueIsLiteral' to true.
-
[valueIsLiteral]Boolean optional- Used to force the 'value' parameter to be treated as a literal - otherwise this will be inferred based on the context.
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);
isPredicate
-
o
Returns whether an object is a Predicate
Parameters:
-
oObject
Example:
var p1 = new Predicate("CompanyName", "StartsWith", "B");
if (Predicate.isPredicate(p1)) {
// do something
}
not
-
predicate
Creates a 'composite' Predicate by 'negating' a specified predicate.
Parameters:
-
predicatePredicate
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
Creates a 'composite' Predicate by 'or'ing a set of specified Predicates together.
Parameters:
-
predicatesMultiple Predicates | Array of Predicate multiple
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:
-
predicatesMultiple Predicates | Array of Predicate multiple
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 '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:
toString
()
String
Returns a human readable string for this Predicate.
Returns:
validate
-
entityType
Determines whether this Predicate is 'valid' for the specified EntityType; This method will throw an exception if invalid.
Parameters:
-
entityTypeEntityTypeThe entityType to validate against.
