Options
All
  • Public
  • Public/Protected
  • All
Menu

Class EntityQuery

An EntityQuery instance is used to query entities either from a remote datasource or from a local EntityManager.

EntityQueries are immutable - this means that all EntityQuery methods that return an EntityQuery actually create a new EntityQuery. This means that EntityQueries can be 'modified' without affecting any current instances.

dynamic

Hierarchy

  • EntityQuery

Index

Constructors

constructor

  • new EntityQuery(resourceName?: string | Object): EntityQuery
  • Constructor

    let query = new EntityQuery("Customers")

    Usually this constructor will be followed by calls to filtering, ordering or selection methods

     let query = new EntityQuery("Customers")
       .where("CompanyName", "startsWith", "C")
       .orderBy("Region");
    

    Parameters

    • Optional resourceName: string | Object

      either a resource name or a serialized EntityQuery ( created by EntityQuery.toJSON)

    Returns EntityQuery

Properties

Optional dataService

dataService: DataService

The DataService for this query. Read Only

Optional entityManager

entityManager: EntityManager

The EntityManager for this query. This may be null and can be set via the 'using' method.

Optional expandClause

expandClause: ExpandClause

The [[ExpandClause]] used by this query. Read Only

Optional fromEntityType

fromEntityType: EntityType

The EntityType that is associated with the 'from' clause ( resourceName) of the query. This is only guaranteed to be be set AFTER the query has been executed because it depends on the MetadataStore associated with the EntityManager that the query was executed against. This value may be null if the entityType cannot be associated with a resourceName. Read Only

inlineCountEnabled

inlineCountEnabled: boolean

Whether an inline count is returned for this query. Read Only

noTrackingEnabled

noTrackingEnabled: boolean

Whether entity tracking has been disabled for this query. Read Only

Optional orderByClause

orderByClause: OrderByClause

The OrderByClause used by this query. Read Only

parameters

parameters: Object

Any additional parameters that were added to the query via the 'withParameters' method. Read Only

Optional queryOptions

queryOptions: QueryOptions

The QueryOptions for this query. Read Only

Optional resourceName

resourceName: string

The resource name used by this query. Read Only

resultEntityType

resultEntityType: EntityType | string

The entityType that will be returned by this query. This property will only be set if the 'toType' method was called. Read Only

Optional selectClause

selectClause: SelectClause

The [[SelectClause]] used by this query. Read Only

Optional skipCount

skipCount: number

The number of entities to 'skip' for this query. Read Only

Optional takeCount

takeCount: number

The number of entities to 'take' for this query. Read Only

Optional usesNameOnServer

usesNameOnServer: boolean

wherePredicate

wherePredicate: Predicate

The 'where' Predicate used by this query. Read Only

Methods

execute

  • Executes this query. This method requires that an EntityManager has been previously specified via the "using" method.

    This method can be called using a 'promises' syntax ( recommended)

     let em = new EntityManager(serviceName);
     let query = new EntityQuery("Orders").using(em);
     query.execute().then( function(data) {
         ... query results processed here
     }).catch( function(err) {
         ... query failure processed here
     });
    

    or with callbacks

     let em = new EntityManager(serviceName);
     let query = new EntityQuery("Orders").using(em);
     query.execute(
       function(data) {
                   let orders = data.results;
                   ... query results processed here
               },
       function(err) {
                   ... query failure processed here
               });
    

    Either way this method is the same as calling the EntityManager 'execute' method.

     let em = new EntityManager(serviceName);
     let query = new EntityQuery("Orders");
     em.executeQuery(query).then( function(data) {
        let orders = data.results;
         ... query results processed here
     }).catch( function(err) {
        ... query failure processed here
     });
    

    Parameters

    • Optional callback: Callback

      Function called on success.

    • Optional errorCallback: ErrorCallback

      Function called on failure.

    Returns Promise<QueryResult>

    Promise

executeLocally

  • executeLocally(): any[]
  • Executes this query against the local cache. This method requires that an EntityManager have been previously specified via the "using" method.

     // assume em is an entityManager already filled with order entities;
     let query = new EntityQuery("Orders").using(em);
     let orders = query.executeLocally();
    

    Note that calling this method is the same as calling EntityManager.executeQueryLocally.

    Returns any[]

expand

  • expand(propertyPaths?: string | string[]): EntityQuery
  • Returns a new query that will return related entities nested within its results. The expand method allows you to identify related entities, via navigation property names such that a graph of entities may be retrieved with a single request. Any filtering occurs before the results are 'expanded'.

    let query = new EntityQuery("Customers")
       .where("CompanyName", "startsWith", "C")
       .expand("Orders");
    

    will return the filtered customers each with its "Orders" properties fully resolved. Multiple paths may be specified by separating the paths by a ','

    let query = new EntityQuery("Orders")
       .expand("Customer, Employee")
    

    and nested property paths my be specified as well

    let query = new EntityQuery("Orders")
       .expand("Customer, OrderDetails, OrderDetails.Product")
    

    Parameters

    • Optional propertyPaths: string | string[]

      A comma-separated list of navigation property names or an array of navigation property names. Each Navigation Property name can be followed by a '.' and another navigation property name to enable identifying a multi-level relationship. If 'propertyPaths' is either null or omitted then any existing 'expand' clause on the query is removed.

    Returns EntityQuery

from

  • Specifies the resource to query for this EntityQuery.

     let query = new EntityQuery()
       .from("Customers");
    

    is the same as

     let query = new EntityQuery("Customers");
    

    Parameters

    • resourceName: string

      The resource to query.

    Returns EntityQuery

inlineCount

  • Returns a query with the 'inlineCount' capability either enabled or disabled. With 'inlineCount' enabled, an additional 'inlineCount' property will be returned with the query results that will contain the number of entities that would have been returned by this query with only the 'where'/'filter' clauses applied, i.e. without any 'skip'/'take' operators applied. For local queries this clause is ignored.

    let query = new EntityQuery("Customers")
       .take(20)
       .orderBy("CompanyName")
       .inlineCount(true);
    

    will return the first 20 customers as well as a count of all of the customers in the remote store.

    Parameters

    • Optional enabled: boolean

      (default = true) Whether or not inlineCount capability should be enabled. If this parameter is omitted, true is assumed.

    Returns EntityQuery

noTracking

  • Returns a query with the 'noTracking' capability either enabled or disabled. With 'noTracking' enabled, the results of this query will not be coerced into entities but will instead look like raw javascript projections. i.e. simple javascript objects.

    let query = new EntityQuery("Customers")
        .take(20)
        .orderBy("CompanyName")
        .noTracking(true);
    

    Parameters

    • Optional enabled: boolean

      (default = true) Whether or not the noTracking capability should be enabled. If this parameter is omitted, true is assumed.

    Returns EntityQuery

orderBy

  • orderBy(propertyPaths?: string, isDescending?: boolean): EntityQuery
  • orderBy(propertyPaths: string[], isDescending?: boolean): EntityQuery
  • Returns a new query that orders the results of the query by property name. By default sorting occurs is ascending order, but sorting in descending order is supported as well. OrderBy clauses may be chained.

    let query = new EntityQuery("Customers")
       .orderBy("CompanyName");
    

    or to sort across multiple properties

    let query = new EntityQuery("Customers")
       .orderBy("Region, CompanyName");
    

    Nested property paths are also supported

    let query = new EntityQuery("Products")
       .orderBy("Category.CategoryName");
    

    Sorting in descending order is supported via the addition of ' desc' to the end of any property path.

    let query = new EntityQuery("Customers")
       .orderBy("CompanyName desc");
    

    or

    let query = new EntityQuery("Customers")
       .orderBy("Region desc, CompanyName desc");
    

    Parameters

    • Optional propertyPaths: string

      A comma-separated (',') string of property paths or an array of property paths. Each property path can optionally end with " desc" to force a descending sort order. If 'propertyPaths' is either null or omitted then all ordering is removed.

    • Optional isDescending: boolean

      If specified, overrides all of the embedded 'desc' tags in the previously specified property paths.

    Returns EntityQuery

  • Returns a new query that orders the results of the query by property name. By default sorting occurs is ascending order, but sorting in descending order is supported as well. OrderBy clauses may be chained.

    let query = new EntityQuery("Customers")
       .orderBy("CompanyName");
    

    or to sort across multiple properties

    let query = new EntityQuery("Customers")
       .orderBy("Region, CompanyName");
    

    Nested property paths are also supported

    let query = new EntityQuery("Products")
       .orderBy("Category.CategoryName");
    

    Sorting in descending order is supported via the addition of ' desc' to the end of any property path.

    let query = new EntityQuery("Customers")
       .orderBy("CompanyName desc");
    

    or

    let query = new EntityQuery("Customers")
       .orderBy("Region desc, CompanyName desc");
    

    Parameters

    • propertyPaths: string[]
    • Optional isDescending: boolean

    Returns EntityQuery

orderByDesc

  • Returns a new query that orders the results of the query by property name in descending order.

    let query = new EntityQuery("Customers")
       .orderByDesc("CompanyName");
    

    or to sort across multiple properties

    let query = new EntityQuery("Customers")
       .orderByDesc("Region, CompanyName");
    

    Nested property paths are also supported

    let query = new EntityQuery("Products")
       .orderByDesc("Category.CategoryName");
    

    Parameters

    • propertyPaths: string

      A comma-separated (',') string of property paths or an array of property paths. If 'propertyPaths' is either null or omitted then all ordering is removed.

    Returns EntityQuery

  • Returns a new query that orders the results of the query by property name in descending order.

    let query = new EntityQuery("Customers")
       .orderByDesc("CompanyName");
    

    or to sort across multiple properties

    let query = new EntityQuery("Customers")
       .orderByDesc("Region, CompanyName");
    

    Nested property paths are also supported

    let query = new EntityQuery("Products")
       .orderByDesc("Category.CategoryName");
    

    Parameters

    • propertyPaths: string[]

    Returns EntityQuery

select

  • select(propertyPaths?: string | string[]): EntityQuery
  • Returns a new query that selects a list of properties from the results of the original query and returns the values of just these properties. This will be referred to as a projection. If the result of this selection "projection" contains entities, these entities will automatically be added to EntityManager's cache and will be made 'observable'. Any simple properties, i.e. strings, numbers or dates within a projection will not be cached are will NOT be made 'observable'.

    Simple data properties can be projected

    let query = new EntityQuery("Customers")
        .where("CompanyName", "startsWith", "C")
        .select("CompanyName");
    

    This will return an array of objects each with a single "CompanyName" property of type string. A similar query could return a navigation property instead

    let query = new EntityQuery("Customers")
       .where("CompanyName", "startsWith", "C")
       .select("Orders");
    

    where the result would be an array of objects each with a single "Orders" property that would itself be an array of "Order" entities. Composite projections are also possible:

    let query = new EntityQuery("Customers")
       .where("CompanyName", "startsWith", "C")
       .select("CompanyName, Orders");
    

    As well as projections involving nested property paths

    let query = EntityQuery("Orders")
       .where("Customer.CompanyName", "startsWith", "C")
       .select("Customer.CompanyName, Customer, OrderDate");
    

    Parameters

    • Optional propertyPaths: string | string[]

      A comma-separated (',') string of property paths or an array of property paths. If 'propertyPaths' is either null or omitted then any existing projection on the query is removed.

    Returns EntityQuery

skip

  • Returns a new query that skips the specified number of entities when returning results. Any existing 'skip' can be cleared by calling 'skip' with no arguments.

    let query = new EntityQuery("Customers")
      .where("CompanyName", "startsWith", "C")
      .skip(5);
    

    Parameters

    • Optional count: number

      The number of entities to skip over. If omitted or null any existing skip count on the query is removed.

    Returns EntityQuery

take

  • Returns a new query that returns only the specified number of entities when returning results - Same as 'top'. Any existing take can be cleared by calling take with no arguments.

    let query = new EntityQuery("Customers")
       .take(5);
    

    Parameters

    • Optional count: number

      The number of entities to return. If 'count' is either null or omitted then any existing 'take' count on the query is removed.

    Returns EntityQuery

toJSON

  • toJSON(): Object

toType

  • Specifies the top level EntityType that this query will return. Only needed when a query returns a json result that does not include type information.

     let query = new EntityQuery()
       .from("MyCustomMethod")
       .toType("Customer")
    

    Parameters

    • entityType: string | EntityType

      The top level EntityType that this query will return. This method is only needed when a query returns a json result that does not include type information. If the json result consists of more than a simple entity or array of entities, consider using a JsonResultsAdapter instead.

    Returns EntityQuery

top

  • Returns a new query that returns only the specified number of entities when returning results. - Same as 'take'. Any existing 'top' can be cleared by calling 'top' with no arguments.

    let query = new EntityQuery("Customers")
       .top(5);
    

    Parameters

    • Optional count: number

      The number of entities to return. If 'count' is either null or omitted then any existing 'top' count on the query is removed.

    Returns EntityQuery

useNameOnServer

  • useNameOnServer(usesNameOnServer?: boolean): EntityQuery

using

  • Returns a copy of this EntityQuery with the specified EntityManager, DataService, JsonResultsAdapter, MergeStrategy or FetchStrategy applied.

     // 'using' can be used to return a new query with a specified EntityManager.
     let em = new EntityManager(serviceName);
     let query = new EntityQuery("Orders")
       .using(em);
    

    or with a specified MergeStrategy

     let em = new EntityManager(serviceName);
     let query = new EntityQuery("Orders")
       .using(MergeStrategy.PreserveChanges);
    

    or with a specified FetchStrategy

     let em = new EntityManager(serviceName);
     let query = new EntityQuery("Orders")
       .using(FetchStrategy.FromLocalCache);
    

    Parameters

    • obj: EntityManager

      The object to update in creating a new EntityQuery from an existing one.

    Returns EntityQuery

  • Returns a copy of this EntityQuery with the specified EntityManager, DataService, JsonResultsAdapter, MergeStrategy or FetchStrategy applied.

     // 'using' can be used to return a new query with a specified EntityManager.
     let em = new EntityManager(serviceName);
     let query = new EntityQuery("Orders")
       .using(em);
    

    or with a specified MergeStrategy

     let em = new EntityManager(serviceName);
     let query = new EntityQuery("Orders")
       .using(MergeStrategy.PreserveChanges);
    

    or with a specified FetchStrategy

     let em = new EntityManager(serviceName);
     let query = new EntityQuery("Orders")
       .using(FetchStrategy.FromLocalCache);
    

    Parameters

    Returns EntityQuery

  • Returns a copy of this EntityQuery with the specified EntityManager, DataService, JsonResultsAdapter, MergeStrategy or FetchStrategy applied.

     // 'using' can be used to return a new query with a specified EntityManager.
     let em = new EntityManager(serviceName);
     let query = new EntityQuery("Orders")
       .using(em);
    

    or with a specified MergeStrategy

     let em = new EntityManager(serviceName);
     let query = new EntityQuery("Orders")
       .using(MergeStrategy.PreserveChanges);
    

    or with a specified FetchStrategy

     let em = new EntityManager(serviceName);
     let query = new EntityQuery("Orders")
       .using(FetchStrategy.FromLocalCache);
    

    Parameters

    Returns EntityQuery

  • Returns a copy of this EntityQuery with the specified EntityManager, DataService, JsonResultsAdapter, MergeStrategy or FetchStrategy applied.

     // 'using' can be used to return a new query with a specified EntityManager.
     let em = new EntityManager(serviceName);
     let query = new EntityQuery("Orders")
       .using(em);
    

    or with a specified MergeStrategy

     let em = new EntityManager(serviceName);
     let query = new EntityQuery("Orders")
       .using(MergeStrategy.PreserveChanges);
    

    or with a specified FetchStrategy

     let em = new EntityManager(serviceName);
     let query = new EntityQuery("Orders")
       .using(FetchStrategy.FromLocalCache);
    

    Parameters

    Returns EntityQuery

  • Returns a copy of this EntityQuery with the specified EntityManager, DataService, JsonResultsAdapter, MergeStrategy or FetchStrategy applied.

     // 'using' can be used to return a new query with a specified EntityManager.
     let em = new EntityManager(serviceName);
     let query = new EntityQuery("Orders")
       .using(em);
    

    or with a specified MergeStrategy

     let em = new EntityManager(serviceName);
     let query = new EntityQuery("Orders")
       .using(MergeStrategy.PreserveChanges);
    

    or with a specified FetchStrategy

     let em = new EntityManager(serviceName);
     let query = new EntityQuery("Orders")
       .using(FetchStrategy.FromLocalCache);
    

    Parameters

    Returns EntityQuery

  • Returns a copy of this EntityQuery with the specified EntityManager, DataService, JsonResultsAdapter, MergeStrategy or FetchStrategy applied.

     // 'using' can be used to return a new query with a specified EntityManager.
     let em = new EntityManager(serviceName);
     let query = new EntityQuery("Orders")
       .using(em);
    

    or with a specified MergeStrategy

     let em = new EntityManager(serviceName);
     let query = new EntityQuery("Orders")
       .using(MergeStrategy.PreserveChanges);
    

    or with a specified FetchStrategy

     let em = new EntityManager(serviceName);
     let query = new EntityQuery("Orders")
       .using(FetchStrategy.FromLocalCache);
    

    Parameters

    Returns EntityQuery

where

  • Returns a new query with an added filter criteria; Can be called multiple times which means to 'and' with any existing Predicate or can be called with null to clear all predicates.

     let query = new EntityQuery("Customers")
         .where("CompanyName", "startsWith", "C");
    

    This can also be expressed using an explicit FilterQueryOp as

     let query = new EntityQuery("Customers")
         .where("CompanyName", FilterQueryOp.StartsWith, "C");
    

    or a preconstructed Predicate may be used

     let pred = new Predicate("CompanyName", FilterQueryOp.StartsWith, "C");
     let query = new EntityQuery("Customers").where(pred);
    

    Predicates are often useful when you want to combine multiple conditions in a single filter, such as

     let pred = Predicate.create("CompanyName", "startswith", "C").and("Region", FilterQueryOp.Equals, null);
     let query = new EntityQuery("Customers")
         .where(pred);
    

    More complicated queries can make use of nested property paths

     let query = new EntityQuery("Products")
         .where("Category.CategoryName", "startswith", "S");
    

    or OData functions - A list of valid OData functions can be found within the Predicate documentation.

     let query = new EntityQuery("Customers")
         .where("toLower(CompanyName)", "startsWith", "c");
    

    or to be even more baroque

     let query = new EntityQuery("Customers")
         .where("toUpper(substring(CompanyName, 1, 2))", FilterQueryOp.Equals, "OM");
    

    Parameters

    • Optional predicate: Predicate

      Can be either

      • a single Predicate

      • the parameters to create a 'simple' Predicate

        • a property name, a property path with '.' as path seperators or a property expression {String}
        • an operator - FilterQueryOp or it's string representation. Case is ignored when if a string is provided and any string that matches one of the FilterQueryOp aliases will be accepted.
        • a 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 DataType enumeration instances.
      • a null or undefined ( this causes any existing where clause to be removed)

    Returns EntityQuery

  • Returns a new query with an added filter criteria; Can be called multiple times which means to 'and' with any existing Predicate or can be called with null to clear all predicates.

     let query = new EntityQuery("Customers")
         .where("CompanyName", "startsWith", "C");
    

    This can also be expressed using an explicit FilterQueryOp as

     let query = new EntityQuery("Customers")
         .where("CompanyName", FilterQueryOp.StartsWith, "C");
    

    or a preconstructed Predicate may be used

     let pred = new Predicate("CompanyName", FilterQueryOp.StartsWith, "C");
     let query = new EntityQuery("Customers").where(pred);
    

    Predicates are often useful when you want to combine multiple conditions in a single filter, such as

     let pred = Predicate.create("CompanyName", "startswith", "C").and("Region", FilterQueryOp.Equals, null);
     let query = new EntityQuery("Customers")
         .where(pred);
    

    More complicated queries can make use of nested property paths

     let query = new EntityQuery("Products")
         .where("Category.CategoryName", "startswith", "S");
    

    or OData functions - A list of valid OData functions can be found within the Predicate documentation.

     let query = new EntityQuery("Customers")
         .where("toLower(CompanyName)", "startsWith", "c");
    

    or to be even more baroque

     let query = new EntityQuery("Customers")
         .where("toUpper(substring(CompanyName, 1, 2))", FilterQueryOp.Equals, "OM");
    

    Parameters

    • predicate: Object

    Returns EntityQuery

  • Returns a new query with an added filter criteria; Can be called multiple times which means to 'and' with any existing Predicate or can be called with null to clear all predicates.

     let query = new EntityQuery("Customers")
         .where("CompanyName", "startsWith", "C");
    

    This can also be expressed using an explicit FilterQueryOp as

     let query = new EntityQuery("Customers")
         .where("CompanyName", FilterQueryOp.StartsWith, "C");
    

    or a preconstructed Predicate may be used

     let pred = new Predicate("CompanyName", FilterQueryOp.StartsWith, "C");
     let query = new EntityQuery("Customers").where(pred);
    

    Predicates are often useful when you want to combine multiple conditions in a single filter, such as

     let pred = Predicate.create("CompanyName", "startswith", "C").and("Region", FilterQueryOp.Equals, null);
     let query = new EntityQuery("Customers")
         .where(pred);
    

    More complicated queries can make use of nested property paths

     let query = new EntityQuery("Products")
         .where("Category.CategoryName", "startswith", "S");
    

    or OData functions - A list of valid OData functions can be found within the Predicate documentation.

     let query = new EntityQuery("Customers")
         .where("toLower(CompanyName)", "startsWith", "c");
    

    or to be even more baroque

     let query = new EntityQuery("Customers")
         .where("toUpper(substring(CompanyName, 1, 2))", FilterQueryOp.Equals, "OM");
    

    Parameters

    • property: string
    • operator: string
    • value: any

    Returns EntityQuery

  • Returns a new query with an added filter criteria; Can be called multiple times which means to 'and' with any existing Predicate or can be called with null to clear all predicates.

     let query = new EntityQuery("Customers")
         .where("CompanyName", "startsWith", "C");
    

    This can also be expressed using an explicit FilterQueryOp as

     let query = new EntityQuery("Customers")
         .where("CompanyName", FilterQueryOp.StartsWith, "C");
    

    or a preconstructed Predicate may be used

     let pred = new Predicate("CompanyName", FilterQueryOp.StartsWith, "C");
     let query = new EntityQuery("Customers").where(pred);
    

    Predicates are often useful when you want to combine multiple conditions in a single filter, such as

     let pred = Predicate.create("CompanyName", "startswith", "C").and("Region", FilterQueryOp.Equals, null);
     let query = new EntityQuery("Customers")
         .where(pred);
    

    More complicated queries can make use of nested property paths

     let query = new EntityQuery("Products")
         .where("Category.CategoryName", "startswith", "S");
    

    or OData functions - A list of valid OData functions can be found within the Predicate documentation.

     let query = new EntityQuery("Customers")
         .where("toLower(CompanyName)", "startsWith", "c");
    

    or to be even more baroque

     let query = new EntityQuery("Customers")
         .where("toUpper(substring(CompanyName, 1, 2))", FilterQueryOp.Equals, "OM");
    

    Parameters

    Returns EntityQuery

  • Returns a new query with an added filter criteria; Can be called multiple times which means to 'and' with any existing Predicate or can be called with null to clear all predicates.

     let query = new EntityQuery("Customers")
         .where("CompanyName", "startsWith", "C");
    

    This can also be expressed using an explicit FilterQueryOp as

     let query = new EntityQuery("Customers")
         .where("CompanyName", FilterQueryOp.StartsWith, "C");
    

    or a preconstructed Predicate may be used

     let pred = new Predicate("CompanyName", FilterQueryOp.StartsWith, "C");
     let query = new EntityQuery("Customers").where(pred);
    

    Predicates are often useful when you want to combine multiple conditions in a single filter, such as

     let pred = Predicate.create("CompanyName", "startswith", "C").and("Region", FilterQueryOp.Equals, null);
     let query = new EntityQuery("Customers")
         .where(pred);
    

    More complicated queries can make use of nested property paths

     let query = new EntityQuery("Products")
         .where("Category.CategoryName", "startswith", "S");
    

    or OData functions - A list of valid OData functions can be found within the Predicate documentation.

     let query = new EntityQuery("Customers")
         .where("toLower(CompanyName)", "startsWith", "c");
    

    or to be even more baroque

     let query = new EntityQuery("Customers")
         .where("toUpper(substring(CompanyName, 1, 2))", FilterQueryOp.Equals, "OM");
    

    Parameters

    Returns EntityQuery

  • Returns a new query with an added filter criteria; Can be called multiple times which means to 'and' with any existing Predicate or can be called with null to clear all predicates.

     let query = new EntityQuery("Customers")
         .where("CompanyName", "startsWith", "C");
    

    This can also be expressed using an explicit FilterQueryOp as

     let query = new EntityQuery("Customers")
         .where("CompanyName", FilterQueryOp.StartsWith, "C");
    

    or a preconstructed Predicate may be used

     let pred = new Predicate("CompanyName", FilterQueryOp.StartsWith, "C");
     let query = new EntityQuery("Customers").where(pred);
    

    Predicates are often useful when you want to combine multiple conditions in a single filter, such as

     let pred = Predicate.create("CompanyName", "startswith", "C").and("Region", FilterQueryOp.Equals, null);
     let query = new EntityQuery("Customers")
         .where(pred);
    

    More complicated queries can make use of nested property paths

     let query = new EntityQuery("Products")
         .where("Category.CategoryName", "startswith", "S");
    

    or OData functions - A list of valid OData functions can be found within the Predicate documentation.

     let query = new EntityQuery("Customers")
         .where("toLower(CompanyName)", "startsWith", "c");
    

    or to be even more baroque

     let query = new EntityQuery("Customers")
         .where("toUpper(substring(CompanyName, 1, 2))", FilterQueryOp.Equals, "OM");
    

    Parameters

    • property: string
    • filterop: string
    • property2: string
    • filterop2: string
    • value: any

    Returns EntityQuery

  • Returns a new query with an added filter criteria; Can be called multiple times which means to 'and' with any existing Predicate or can be called with null to clear all predicates.

     let query = new EntityQuery("Customers")
         .where("CompanyName", "startsWith", "C");
    

    This can also be expressed using an explicit FilterQueryOp as

     let query = new EntityQuery("Customers")
         .where("CompanyName", FilterQueryOp.StartsWith, "C");
    

    or a preconstructed Predicate may be used

     let pred = new Predicate("CompanyName", FilterQueryOp.StartsWith, "C");
     let query = new EntityQuery("Customers").where(pred);
    

    Predicates are often useful when you want to combine multiple conditions in a single filter, such as

     let pred = Predicate.create("CompanyName", "startswith", "C").and("Region", FilterQueryOp.Equals, null);
     let query = new EntityQuery("Customers")
         .where(pred);
    

    More complicated queries can make use of nested property paths

     let query = new EntityQuery("Products")
         .where("Category.CategoryName", "startswith", "S");
    

    or OData functions - A list of valid OData functions can be found within the Predicate documentation.

     let query = new EntityQuery("Customers")
         .where("toLower(CompanyName)", "startsWith", "c");
    

    or to be even more baroque

     let query = new EntityQuery("Customers")
         .where("toUpper(substring(CompanyName, 1, 2))", FilterQueryOp.Equals, "OM");
    

    Parameters

    • property: string
    • filterop: string
    • property2: string
    • filterop2: string
    • property3: string
    • filterop3: string
    • value: any

    Returns EntityQuery

  • Returns a new query with an added filter criteria; Can be called multiple times which means to 'and' with any existing Predicate or can be called with null to clear all predicates.

     let query = new EntityQuery("Customers")
         .where("CompanyName", "startsWith", "C");
    

    This can also be expressed using an explicit FilterQueryOp as

     let query = new EntityQuery("Customers")
         .where("CompanyName", FilterQueryOp.StartsWith, "C");
    

    or a preconstructed Predicate may be used

     let pred = new Predicate("CompanyName", FilterQueryOp.StartsWith, "C");
     let query = new EntityQuery("Customers").where(pred);
    

    Predicates are often useful when you want to combine multiple conditions in a single filter, such as

     let pred = Predicate.create("CompanyName", "startswith", "C").and("Region", FilterQueryOp.Equals, null);
     let query = new EntityQuery("Customers")
         .where(pred);
    

    More complicated queries can make use of nested property paths

     let query = new EntityQuery("Products")
         .where("Category.CategoryName", "startswith", "S");
    

    or OData functions - A list of valid OData functions can be found within the Predicate documentation.

     let query = new EntityQuery("Customers")
         .where("toLower(CompanyName)", "startsWith", "c");
    

    or to be even more baroque

     let query = new EntityQuery("Customers")
         .where("toUpper(substring(CompanyName, 1, 2))", FilterQueryOp.Equals, "OM");
    

    Parameters

    Returns EntityQuery

withParameters

  • Returns a new query that includes a collection of parameters to pass to the server.

    let query = EntityQuery.from("EmployeesFilteredByCountryAndBirthdate")
       .withParameters({ BirthDate: "1/1/1960", Country: "USA" });
    

    will call the 'EmployeesFilteredByCountryAndBirthdate' method on the server and pass in 2 parameters. This query will be uri encoded as

     {serviceApi}/EmployeesFilteredByCountryAndBirthdate?birthDate=1%2F1%2F1960&country=USA
    

    Parameters may also be mixed in with other query criteria.

    let query = EntityQuery.from("EmployeesFilteredByCountryAndBirthdate")
       .withParameters({ BirthDate: "1/1/1960", Country: "USA" })
       .where("LastName", "startsWith", "S")
       .orderBy("BirthDate");
    

    Parameters

    • parameters: Object

      A parameters object where the keys are the parameter names and the values are the parameter values.

    Returns EntityQuery

Static from

  • This is a static version of the "from" method and it creates a 'base' entityQuery for the specified resource name.

     let query = EntityQuery.from("Customers");
    

    is the same as

     let query = new EntityQuery("Customers");
    

    Parameters

    • resourceName: string

      The resource to query.

    Returns EntityQuery

Static fromEntities

  • Static method that creates an EntityQuery that will allow 'requerying' an entity or a collection of entities by primary key. This can be useful to force a requery of selected entities, or to restrict an existing collection of entities according to some filter.

    Works for a single entity or an array of entities of the SAME type. Does not work for an array of entities of different types.

     // assuming 'customers' is an array of 'Customer' entities retrieved earlier.
     let customersQuery = EntityQuery.fromEntities(customers);
    

    The resulting query can, of course, be extended

     // assuming 'customers' is an array of 'Customer' entities retrieved earlier.
     let customersQuery = EntityQuery.fromEntities(customers)
       .where("Region", FilterQueryOp.NotEquals, null);
    

    Single entities can requeried as well.

     // assuming 'customer' is a 'Customer' entity retrieved earlier.
     let customerQuery = EntityQuery.fromEntities(customer);
    

    will create a query that will return an array containing a single customer entity.

    Parameters

    Returns EntityQuery

  • Static method that creates an EntityQuery that will allow 'requerying' an entity or a collection of entities by primary key. This can be useful to force a requery of selected entities, or to restrict an existing collection of entities according to some filter.

    Works for a single entity or an array of entities of the SAME type. Does not work for an array of entities of different types.

     // assuming 'customers' is an array of 'Customer' entities retrieved earlier.
     let customersQuery = EntityQuery.fromEntities(customers);
    

    The resulting query can, of course, be extended

     // assuming 'customers' is an array of 'Customer' entities retrieved earlier.
     let customersQuery = EntityQuery.fromEntities(customers)
       .where("Region", FilterQueryOp.NotEquals, null);
    

    Single entities can requeried as well.

     // assuming 'customer' is a 'Customer' entity retrieved earlier.
     let customerQuery = EntityQuery.fromEntities(customer);
    

    will create a query that will return an array containing a single customer entity.

    Parameters

    Returns EntityQuery

Static fromEntityKey

  • Creates an EntityQuery for the specified EntityKey.

     let empType = metadataStore.getEntityType("Employee");
     let entityKey = new EntityKey(empType, 1);
     let query = EntityQuery.fromEntityKey(entityKey);
    

    or

     // 'employee' is a previously queried employee
     let entityKey = employee.entityAspect.getKey();
     let query = EntityQuery.fromEntityKey(entityKey);
    

    Parameters

    Returns EntityQuery

Static fromEntityNavigation

  • Creates an EntityQuery for the specified entity and NavigationProperty.

     // 'employee' is a previously queried employee
     let ordersNavProp = employee.entityType.getProperty("Orders");
     let query = EntityQuery.fromEntityNavigation(employee, ordersNavProp);
    

    will return a query for the "Orders" of the specified 'employee'.

    Parameters

    Returns EntityQuery

Generated using TypeDoc