diff --git a/docs/odata-protocol/odata-protocol.html b/docs/odata-protocol/odata-protocol.html index 94e7def1..8bd261f0 100644 --- a/docs/odata-protocol/odata-protocol.html +++ b/docs/odata-protocol/odata-protocol.html @@ -369,7 +369,10 @@

Table of Contents

  • 11.2.5 Specifying Properties to Return
  • 5.1.2 System Query Option $filter
  • -
  • 5.1.3 System Query Option $expand
  • -
  • 5.1.4 System Query Option $select
  • +
  • 5.1.3 System Query Option $expand +
  • +
  • 5.1.4 System Query Option $select +
  • 5.1.5 System Query Option $orderby
  • 5.1.6 System Query Options $top and $skip
  • 5.1.7 System Query Option $count
  • @@ -2251,7 +2257,7 @@

    type-cast segment to expand only related entities of that derived type or one of its sub-types, optionally followed by /$ref to expand only entity references. +
  • a navigation property to expand the related entity or entities, optionally followed by a type-cast segment to expand only related entities of that derived type or one of its sub-types, optionally followed by /$ref to expand only entity references, or /$count, optionally with expand options, to return only the count of matching entities.
  • an entity-valued instance annotation to expand the related entity or entities, optionally followed by a type-cast segment to expand only related entities of that derived type or one of its sub-types.
  • If a structured type traversed by the path supports neither dynamic properties nor instance annotations, then a corresponding property segment MUST specify a declared property of that structured type. Otherwise, if a traversed type does support dynamic navigation properties or instance annotations and the corresponding property segment does not specify a declared property, then the expanded property appears only for those instances on which it has a value.

    @@ -2264,59 +2270,63 @@

    $compute, $select, $expand, and $levels for all navigation properties, plus $filter, $orderby, $skip, $top, $count, and $search for collection-valued navigation properties.

    -
    -

    Example 124: all categories and for each category all related products with a discontinued date equal to null

    -
    http://host/service/Categories?$expand=Products($filter=DiscontinuedDate eq null)
    -
    -

    The $count segment can be appended to a navigation property name or type-cast segment following a navigation property name to return just the count of the related entities. The $filter and $search system query options can be used to limit the number of related entities included in the count.

    +

    The $count segment can be appended to a navigation property name or type-cast segment following a collection-valued navigation property name to return just the count of the related entities. The $filter and $search Expand Options can be used to limit the number of related entities included in the count.

    -

    Example 125: all categories and for each category the number of all related products

    +

    Example 124: all categories and for each category the number of all related products

    http://host/service/Categories?$expand=Products/$count
    -

    Example 126: all categories and for each category the number of all related blue products

    +

    Example 125: all categories and for each category the number of all related blue products

    http://host/service/Categories?$expand=Products/$count($search=blue)
    -

    To retrieve entity references instead of the related entities, append /$ref to the navigation property name or type-cast segment following a navigation property name. The system query options $filter, $search, $skip, $top, and $count can be used to limit the number of expanded entity references.

    +

    To retrieve entity references instead of the related entities, append /$ref to the navigation property name or type-cast segment following a navigation property name. The Expand Options $filter, $search, $skip, $top, and $count can be used to include the count of expanded entity references.

    -

    Example 127: all categories and for each category the references of all related products

    +

    Example 126: all categories and for each category the references of all related products

    http://host/service/Categories?$expand=Products/$ref
    -

    Example 128: all categories and for each category the references of all related products of the derived type Sales.PremierProduct

    +

    Example 127: all categories and for each category the references of all related products of the derived type Sales.PremierProduct

    http://host/service/Categories?$expand=Products/Sales.PremierProduct/$ref
    -

    Example 129: all categories and for each category the references of all related premier products with a current promotion equal to null

    +

    Example 128: all categories and for each category the references of all related premier products with a current promotion equal to null

    http://host/service/Categories
       ?$expand=Products/Sales.PremierProduct/$ref($filter=CurrentPromotion eq null)
    -

    Cyclic navigation properties (whose target type is identical or can be cast to its source type) can be recursively expanded using the special $levels option. The value of the $levels option is either a positive integer to specify the number of levels to expand, or the literal string max to specify the maximum expansion level supported by that service. A $levels option with a value of 1 specifies a single expand with no recursion.

    -
    -

    Example 130: all employees with their manager, manager’s manager, and manager’s manager’s manager

    -
    http://host/service/Employees?$expand=ReportsTo($levels=3)
    -
    -

    It is also possible to expand all declared and dynamic navigation properties using a star (*). To retrieve references to all related entities use */$ref, and to expand all related entities with a certain distance use the star operator with the $levels option. The star operator can be combined with explicitly named navigation properties, which take precedence over the star operator.

    +

    It is also possible to expand all declared and dynamic navigation properties using a star (*). To retrieve references to all related entities use */$ref, and to expand all related entities with a certain distance use the star operator with the $levels Expand Option. The star operator can be combined with explicitly named navigation properties, which take precedence over the star operator.

    The star operator does not implicitly include stream properties.

    -

    Example 131: expand Supplier and include references for all other related entities

    +

    Example 129: expand Supplier and include references for all other related entities

    http://host/service/Categories?$expand=*/$ref,Supplier
    -
    -

    Example 132: expand all related entities and their related entities

    -
    http://host/service/Categories?$expand=*($levels=2)
    -

    Specifying a stream property includes the media stream inline according to the specified format.

    -

    Example 133: include Employee’s Photo stream property along with other properties of the customer

    +

    Example 130: include Employee’s Photo stream property along with other properties of the customer

    http://host/service/Employees?$expand=Photo

    Specifying $value for a media entity includes the media entity’s stream value inline according to the specified format.

    -

    Example 134: Include the Product’s media stream along with other properties of the product

    +

    Example 131: Include the Product’s media stream along with other properties of the product

    http://host/service/Products?$expand=$value
    +
    +

    5.1.3.1 Expand Options

    +
    +

    Query options can be applied to an expanded navigation property by appending a semicolon-separated list of query options, enclosed in parentheses, to the navigation property name. The system query option, irrespective of casing or whether or not it is prefixed with a $, MUST NOT be specified more than once in the list. Allowed system query options are $compute, $select, $expand, and $levels for all navigation properties, plus $filter, $orderby, $skip, $top, $count, and $search for collection-valued navigation properties.

    +
    +

    Example 132: all categories and for each category all related products with a discontinued date equal to null

    +
    http://host/service/Categories?$expand=Products($filter=DiscontinuedDate eq null)
    +
    +

    Cyclic navigation properties (whose target type is identical or can be cast to its source type) can be recursively expanded using the special $levels expand option. The value of the $levels expand option is either a positive integer to specify the number of levels to expand, or the literal string max to specify the maximum expansion level supported by that service. A $levels option with a value of 1 specifies a single expand with no recursion.

    +
    +

    Example 133: all employees with their manager, manager’s manager, and manager’s manager’s manager

    +
    http://host/service/Employees?$expand=ReportsTo($levels=3)
    +
    +
    +

    Example 134: expand all related entities and their related entities

    +
    http://host/service/Categories?$expand=*($levels=2)
    +
    +

    5.1.4 System Query Option $select

    @@ -2326,14 +2336,14 @@

    OData-ABNF select syntax rule defines the formal grammar of the $select query option.

    The value of $select is a comma-separated list of select items. Each select item is one of the following:

      -
    • a path, to include a property,
    • +
    • a path, optionally followed by a count segment or select options
    • a star (*), to include all declared or dynamic properties of the type, or
    • a qualified schema name followed by a dot (.) followed by a star (*) to request all applicable actions or functions from that schema

    A path consists of segments separated by a forward slash (/). Segments are either names of single- or collection-valued complex properties, instance annotations, or type-cast segments consisting of the qualified name of a structured type that is derived from the type identified by the preceding path segment to reach properties defined on the derived type.

    A path can end with

    5.1.5 System Query Option $orderby

    @@ -2411,7 +2439,7 @@

    The OData-ABNF compute syntax rule defines the formal grammar of the $compute query option.

    Computed properties SHOULD be included as dynamic properties in the result and MUST be included if $select is specified with the computed property name, or star (*).

    -

    Example 142: compute total price for order items

    +

    Example 145: compute total price for order items

    http://host/service/Orders(10)/Items
       ?$select=Product/Description,Total
       &$filter=Total gt 100
    @@ -2474,7 +2502,7 @@ 

    OData-ABNF.

    Custom query options MUST NOT begin with a $ or @ character.

    -

    Example 143: service-specific custom query option debug-mode

    +

    Example 146: service-specific custom query option debug-mode

    http://host/service/Products?debug-mode=true

    @@ -2485,15 +2513,15 @@

    Parameter aliases MUST start with an @ character, see rule parameterAlias in OData-ABNF.

    The semantics of parameter aliases are covered in OData-Protocol, section 11.2.6.1.3. The OData-ABNF rule aliasAndValue defines the formal grammar for passing parameter alias values as query options.

    -

    Example 144:

    +

    Example 147:

    http://host/service/Movies?$filter=contains(@word,Title)&@word='Black'
    -

    Example 145:

    +

    Example 148:

    http://host/service/Movies?$filter=Title eq @title&@title='Wizard of Oz'
    -

    Example 146: JSON array of strings as parameter alias value — note that [, ], and " need to be percent-encoded in real URLs, the clear-text representation used here is just for readability

    +

    Example 149: JSON array of strings as parameter alias value — note that [, ], and " need to be percent-encoded in real URLs, the clear-text representation used here is just for readability

    http://host/service/Products/Model.WithIngredients(Ingredients=@i)
       ?@i=["Carrots","Ginger","Oranges"]
    diff --git a/docs/odata-url-conventions/odata-url-conventions.md b/docs/odata-url-conventions/odata-url-conventions.md index 3ed0a793..26da05b1 100644 --- a/docs/odata-url-conventions/odata-url-conventions.md +++ b/docs/odata-url-conventions/odata-url-conventions.md @@ -220,7 +220,9 @@ For complete copyright information please see the full Notices section in an App - [5.1.1.18 Numeric Promotion](#NumericPromotion) - [5.1.2 System Query Option `$filter`](#SystemQueryOptionfilter) - [5.1.3 System Query Option `$expand`](#SystemQueryOptionexpand) + - [5.1.3.1 Expand Options](#ExpandOptions) - [5.1.4 System Query Option `$select`](#SystemQueryOptionselect) + - [5.1.4.1 SelectOptions](#SelectOptions) - [5.1.5 System Query Option `$orderby`](#SystemQueryOptionorderby) - [5.1.6 System Query Options `$top` and `$skip`](#SystemQueryOptionstopandskip) - [5.1.7 System Query Option `$count`](#SystemQueryOptioncount) @@ -3589,7 +3591,7 @@ properties of the identified instances of a structured type, optionally followed related entity or entities, optionally followed by a [type-cast segment](#AddressingDerivedTypes) to expand only related entities of that derived type or one of its sub-types, optionally followed by `/$ref` to expand only entity -references. +references, or `/$count`, optionally with expand options, to return only the count of matching entities. - an entity-valued instance annotation to expand the related entity or entities, optionally followed by a [type-cast segment](#AddressingDerivedTypes) to expand only related entities of that derived type @@ -3619,39 +3621,14 @@ http://host/service/Customers?$expand=Addresses/Country A path MUST NOT appear in more than one expand item. -Query options can be applied to an expanded navigation property by -appending a semicolon-separated list of query options, enclosed in -parentheses, to the navigation property name. -The system query option, irrespective of casing or whether or not it is prefixed with a `$`, -MUST NOT be specified more than once in the list. -Allowed system query options are -[`$compute`](#SystemQueryOptioncompute), -[`$select`](#SystemQueryOptionselect), -`$expand`, and -[`$levels`](#ExpandOptionlevels) for all navigation properties, plus -[`$filter`](#SystemQueryOptionfilter), -[`$orderby`](#SystemQueryOptionorderby), -[`$skip`](#SystemQueryOptionstopandskip), [`$top`](#SystemQueryOptionstopandskip), -[`$count`](#SystemQueryOptioncount), and -[`$search`](#SystemQueryOptionsearch) -for collection-valued navigation properties. - -::: example -Example 124: all categories and for each category all related products -with a discontinued date equal to `null` -``` -http://host/service/Categories?$expand=Products($filter=DiscontinuedDate eq null) -``` -::: - The `$count` segment can be appended to a navigation property name or -[type-cast segment](#AddressingDerivedTypes) following a navigation +[type-cast segment](#AddressingDerivedTypes) following a collection-valued navigation property name to return just the count of the related entities. The -`$filter` and `$search` system query options can be used to limit the -number of related entities included in the count. +[`$filter`](#SystemQueryOptionfilter) and [`$search`](#SystemQueryOptionsearch) [Expand Options](#ExpandOptions) +can be used to limit the number of related entities included in the count. ::: example -Example 125: all categories and for each category the number of all +Example 124: all categories and for each category the number of all related products ``` http://host/service/Categories?$expand=Products/$count @@ -3659,7 +3636,7 @@ http://host/service/Categories?$expand=Products/$count ::: ::: example -Example 126: all categories and for each category the number of all +Example 125: all categories and for each category the number of all related blue products ``` http://host/service/Categories?$expand=Products/$count($search=blue) @@ -3668,15 +3645,15 @@ http://host/service/Categories?$expand=Products/$count($search=blue) To retrieve entity references instead of the related entities, append `/$ref` to the navigation property name or [type-cast segment](#AddressingDerivedTypes) following a navigation property name. -The system query options [`$filter`](#SystemQueryOptionfilter), +The [Expand Options](#ExpandOptions) [`$filter`](#SystemQueryOptionfilter), [`$search`](#SystemQueryOptionsearch), [`$skip`](#SystemQueryOptionstopandskip), [`$top`](#SystemQueryOptionstopandskip), and -[`$count`](#SystemQueryOptioncount) can be used to limit the number of +[`$count`](#SystemQueryOptioncount) can be used to include the count of expanded entity references. ::: example -Example 127: all categories and for each category the references of all +Example 126: all categories and for each category the references of all related products ``` http://host/service/Categories?$expand=Products/$ref @@ -3684,7 +3661,7 @@ http://host/service/Categories?$expand=Products/$ref ::: ::: example -Example 128: all categories and for each category the references of all +Example 127: all categories and for each category the references of all related products of the derived type `Sales.PremierProduct` ``` http://host/service/Categories?$expand=Products/Sales.PremierProduct/$ref @@ -3692,7 +3669,7 @@ http://host/service/Categories?$expand=Products/Sales.PremierProduct/$ref ::: ::: example -Example 129: all categories and for each category the references of all +Example 128: all categories and for each category the references of all related premier products with a current promotion equal to `null` ``` http://host/service/Categories @@ -3700,51 +3677,27 @@ http://host/service/Categories ``` ::: -[Cyclic navigation properties]{id=ExpandOptionlevels} (whose target type is identical or can be -cast to its source type) can be recursively expanded using the special -`$levels` option. The value of the `$levels` option is either a positive -integer to specify the number of levels to expand, or the literal string -`max` to specify the maximum expansion level supported by that service. -A `$levels` option with a value of 1 specifies a single expand with no -recursion. - -::: example -Example 130: all employees with their manager, manager's manager, and -manager's manager's manager -``` -http://host/service/Employees?$expand=ReportsTo($levels=3) -``` -::: - It is also possible to expand all declared and dynamic navigation properties using a star (`*`). To retrieve references to all related entities use `*/$ref`, and to expand all related entities with a certain -distance use the star operator with the `$levels` option. The star -operator can be combined with explicitly named navigation properties, +distance use the star operator with the `$levels` [Expand Option](#ExpandOptionlevels). The star operator can be combined with explicitly named navigation properties, which take precedence over the star operator. The star operator does not implicitly include stream properties. ::: example -Example 131: expand `Supplier` and include references for all other +Example 129: expand `Supplier` and include references for all other related entities ``` http://host/service/Categories?$expand=*/$ref,Supplier ``` ::: -::: example -Example 132: expand all related entities and their related entities -``` -http://host/service/Categories?$expand=*($levels=2) -``` -::: - Specifying a stream property includes the media stream inline according to the specified format. ::: example -Example 133: include Employee's `Photo` stream property along with other +Example 130: include Employee's `Photo` stream property along with other properties of the customer ``` http://host/service/Employees?$expand=Photo @@ -3755,13 +3708,63 @@ Specifying `$value` for a media entity includes the media entity's stream value inline according to the specified format. ::: example -Example 134: Include the Product's media stream along with other +Example 131: Include the Product's media stream along with other properties of the product ``` http://host/service/Products?$expand=$value ``` ::: +#### 5.1.3.1 Expand Options + +Query options can be applied to an expanded navigation property by +appending a semicolon-separated list of query options, enclosed in +parentheses, to the navigation property name. +The system query option, irrespective of casing or whether or not it is prefixed with a `$`, +MUST NOT be specified more than once in the list. +Allowed system query options are +[`$compute`](#SystemQueryOptioncompute), +[`$select`](#SystemQueryOptionselect), +`$expand`, and +[`$levels`](#ExpandOptionlevels) for all navigation properties, plus +[`$filter`](#SystemQueryOptionfilter), +[`$orderby`](#SystemQueryOptionorderby), +[`$skip`](#SystemQueryOptionstopandskip), [`$top`](#SystemQueryOptionstopandskip), +[`$count`](#SystemQueryOptioncount), and +[`$search`](#SystemQueryOptionsearch) +for collection-valued navigation properties. + +::: example +Example 132: all categories and for each category all related products +with a discontinued date equal to `null` +``` +http://host/service/Categories?$expand=Products($filter=DiscontinuedDate eq null) +``` +::: + +[Cyclic navigation properties]{id=ExpandOptionlevels} (whose target type is identical or can be +cast to its source type) can be recursively expanded using the special +`$levels` expand option. The value of the `$levels` expand option is either a positive +integer to specify the number of levels to expand, or the literal string +`max` to specify the maximum expansion level supported by that service. +A `$levels` option with a value of 1 specifies a single expand with no +recursion. + +::: example +Example 133: all employees with their manager, manager's manager, and +manager's manager's manager +``` +http://host/service/Employees?$expand=ReportsTo($levels=3) +``` +::: + +::: example +Example 134: expand all related entities and their related entities +``` +http://host/service/Categories?$expand=*($levels=2) +``` +::: + ### 5.1.4 System Query Option `$select` The `$select` system query option allows clients to request a specific @@ -3779,7 +3782,7 @@ grammar of the `$select` query option. The value of `$select` is a comma-separated list of select items. Each select item is one of the following: -- a path, to include a property, +- a path, optionally followed by a count segment or select options - a star (`*`), to include all declared or dynamic properties of the type, or - a qualified schema name followed by a @@ -3796,7 +3799,7 @@ properties defined on the derived type. A path can end with - the name of a property or non-entity-valued instance annotation of the identified -instance of a structured type, +instance of a structured type - the qualified name of a bound action, - the qualified name of a bound function to include all matching overloads, or @@ -3866,8 +3869,8 @@ in order to select a property defined on a type derived from the type of the resource segment. A select item that is a complex type or collection of complex type can -be followed by a forward slash, an optional [type-cast segment](#AddressingDerivedTypes), and the name of a property of the -complex type (and so on for nested complex types). +be followed by a forward slash, an optional [type-cast segment](#AddressingDerivedTypes), +and the name of a property of the complex type (and so on for nested complex types). ::: example Example 138: the `AccountRepresentative` property of any supplier that @@ -3881,24 +3884,20 @@ http://host/service/Suppliers ``` ::: -Query options can be applied to a select item that is a path to a single -complex value or a collection of primitive or complex values by -appending a semicolon-separated list of query options, enclosed in -parentheses, to the select item. The allowed system query options depend -on the type of the resource identified by the select item, see section -[System Query Options](#SystemQueryOptions), with the exception of -[`$expand`](#SystemQueryOptionexpand). The same property MUST NOT have -select options specified in more than one place in a request and MUST -NOT be specified in more than one expand. +If the path ends in a collection of primitive or complex values, then the count segment (`/$count`), optionally followed by the [Select Options](#SelectOptions) [`$filter`](#SystemQueryOptionfilter) +and/or [`$search`](#SystemQueryOptionsearch), can be appended to the path in order to return only the count of the matching items. ::: example -Example 139: select up to five addresses whose `City` starts with an -`H`, sorted, and with the `Country` expanded +Example 139: for each `Customer`, return the `ID` and the count of `Addresses` ``` -http://host/service/Customers - ?$select=Addresses($filter=startswith(City,'H');$top=5; - $orderby=Country/Name,City,Street) - &$expand=Addresses/Country +http://host/service/Customers?$select=ID,Addresses/$count +``` +::: + +::: example +Example 140: for each `Customer`, return the `ID` and the count of `Addresses` whose `City` starts with 'H' +``` +http://host/service/Customers?$select=ID,Addresses/$count($filter=startswith(City,'H')) ``` ::: @@ -3929,7 +3928,7 @@ qualified name and that operation cannot be bound to the entities requested, the service MUST ignore the select item. ::: example -Example 140: the `ID` property, the `ActionName` action defined in +Example 141: the `ID` property, the `ActionName` action defined in `Model` and all actions and functions defined in the `Model2` for each product if those actions and functions can be bound to that product ``` @@ -3942,6 +3941,39 @@ of properties, open properties, navigation properties, actions and functions to be returned is equal to the union of the set of those identified by each select item. +#### 5.1.4.1 SelectOptions + +Query options can be applied to a select item that is a path to a single +complex value or a collection of primitive or complex values by +appending a semicolon-separated list of query options, enclosed in +parentheses, to the select item. The allowed system query options depend +on the type of the resource identified by the select item, see section +[System Query Options](#SystemQueryOptions), with the exception of +[`$expand`](#SystemQueryOptionexpand). The same property MUST NOT have +select options specified in more than one place in a request and MUST +NOT be specified in more than one expand. + +If the select item is a complex type, or collection of complex types, then +it can include a nested select. + +::: example +Example 142: return the City from the Address complex type +``` +http://host/service/Customers?$select=Address($select=City) +``` +::: + +::: example +Example 143: select up to five addresses whose `City` starts with an +`H`, sorted, and with the `Country` expanded +``` +http://host/service/Customers + ?$select=Addresses($filter=startswith(City,'H');$top=5; + $orderby=Country/Name,City,Street) + &$expand=Addresses/Country +``` +::: + ### 5.1.5 System Query Option `$orderby` The `$orderby` system query option allows clients to request resources @@ -3994,7 +4026,7 @@ The [OData-ABNF](#ODataABNF) `search` syntax rule defines the formal grammar of the `$search` query option. ::: example -Example 141: all products that are blue or green. It is up to the +Example 144: all products that are blue or green. It is up to the service to decide what makes a product blue or green. ``` http://host/service/Products?$search=blue OR green @@ -4088,7 +4120,7 @@ result and MUST be included if `$select` is specified with the computed property name, or star (`*`). ::: example -Example 142: compute total price for order items +Example 145: compute total price for order items ``` http://host/service/Orders(10)/Items ?$select=Product/Description,Total @@ -4132,7 +4164,7 @@ custom query option is any query option of the form shown by the rule Custom query options MUST NOT begin with a `$` or `@` character. ::: example -Example 143: service-specific custom query option `debug-mode` +Example 146: service-specific custom query option `debug-mode` ``` http://host/service/Products?debug-mode=true ``` @@ -4154,21 +4186,21 @@ The semantics of parameter aliases are covered in values as query options. ::: example -Example 144: +Example 147: ``` http://host/service/Movies?$filter=contains(@word,Title)&@word='Black' ``` ::: ::: example -Example 145: +Example 148: ``` http://host/service/Movies?$filter=Title eq @title&@title='Wizard of Oz' ``` ::: ::: example -Example 146: JSON array of strings as parameter alias value --- note that +Example 149: JSON array of strings as parameter alias value --- note that `[`, `]`, and `"` need to be percent-encoded in real URLs, the clear-text representation used here is just for readability ``` diff --git a/odata-protocol/11 Data Service Requests.md b/odata-protocol/11 Data Service Requests.md index 229b5547..d664373b 100644 --- a/odata-protocol/11 Data Service Requests.md +++ b/odata-protocol/11 Data Service Requests.md @@ -336,7 +336,7 @@ GET http://host/service/Products?$select=* ::: Properties of related entities can be specified by including the -`$select` query option within the `$expand`. +`$select` [option](#ExpandOptions) within the `$expand`. ::: example Example ##ex: @@ -370,19 +370,19 @@ GET http://host/service/Products?$select=DemoService.* ``` ::: -Query options can be applied to a selected property by appending a -semicolon-separated list of query options, enclosed in parentheses, to -the property. Allowed system query options are -[`$select`](#SystemQueryOptionselect) and -[`$compute`](#SystemQueryOptioncompute) for complex properties, plus -[`$filter`](#SystemQueryOptionfilter), -[`$search`](#SystemQueryOptionsearch), -[`$count`](#SystemQueryOptioncount), -[`$orderby`](#SystemQueryOptionorderby), -[`$skip`](#SystemQueryOptionskip), and [`$top`](#SystemQueryOptiontop) -for collection-valued properties. A property MUST NOT have select -options specified in more than one place in a request and MUST NOT have -both select options and expand options specified. +If the selected property represents a collection of primitive or complex values, +then the [count segment](#RequestingtheNumberofItemsinaCollection) (`/$count`), +optionally followed by the [Select Options](#SelectOptions) [`$filter`](#SystemQueryOptionfilter) +and/or [`$search`](#SystemQueryOptionsearch), can be appended to the path in order +to return only the count of the matching items. + +::: example +Example ##ex: for each customer, return the ID and the count of addresses +starting with the letter 'H'. +``` +GET http://host/service/Customers?$select=ID,Addresses/$count(startswith(City,'H')) +``` +::: If the `$select` query option is not specified, the service returns the full set of properties or a default set of properties. The default @@ -400,6 +400,22 @@ the [context URL](#ContextURL) MUST reflect the set of selected properties and projected [expanded](#SystemQueryOptionexpand) navigation properties. +##### ##subsubsubsubsec Select Options + +Query options can be applied to a selected property by appending a +semicolon-separated list of query options, enclosed in parentheses, to +the property. Allowed system query options are +[`$select`](#SystemQueryOptionselect) and +[`$compute`](#SystemQueryOptioncompute) for complex properties, plus +[`$filter`](#SystemQueryOptionfilter), +[`$search`](#SystemQueryOptionsearch), +[`$count`](#SystemQueryOptioncount), +[`$orderby`](#SystemQueryOptionorderby), +[`$skip`](#SystemQueryOptionskip), and [`$top`](#SystemQueryOptiontop) +for collection-valued properties. A property MUST NOT have select +options specified in more than one place in a request and MUST NOT have +both select options and expand options specified. + #### ##subsubsubsec System Query Option `$expand` The `$expand` system query option indicates the related entities and @@ -437,6 +453,20 @@ GET http://host/service.svc/Customers?$expand=Photo ``` ::: +If the expand item represents a collection of entities, then the +[count segment](#RequestingtheNumberofItemsinaCollection) (`/$count`), optionally followed by +the [Expand Options](#ExpandOptions) [`$filter`](#SystemQueryOptionfilter) and/or +[`$search`](#SystemQueryOptionsearch), can be appended to the expand item in order to +return only the count of matching items. + +::: example +Example ##ex: for each Category, return the `Name` and the count of `Products` +starting with the letter 'H'. +``` +GET http://host/service/Categories?$select=Name&$expand=Products/$count(startswith(Name,'H')) +``` +::: + ##### ##subsubsubsubsec Expand Options The set of expanded entities can be further refined through the @@ -452,7 +482,8 @@ Allowed system query options are for all navigation properties, plus [`$filter`](#SystemQueryOptionfilter), [`$orderby`](#SystemQueryOptionorderby), -[`$skip`](#SystemQueryOptionskip), [`$top`](#SystemQueryOptiontop), +[`$skip`](#SystemQueryOptionskip), +[`$top`](#SystemQueryOptiontop), [`$count`](#SystemQueryOptioncount), and [`$search`](#SystemQueryOptionsearch) for collection-valued navigation properties. diff --git a/odata-url-conventions/5 Query Options.md b/odata-url-conventions/5 Query Options.md index d82a7de5..60cb84db 100644 --- a/odata-url-conventions/5 Query Options.md +++ b/odata-url-conventions/5 Query Options.md @@ -2017,7 +2017,8 @@ properties of the identified instances of a structured type, optionally followed related entity or entities, optionally followed by a [type-cast segment](#AddressingDerivedTypes) to expand only related entities of that derived type or one of its sub-types, optionally followed by `/$ref` to expand only entity -references. +references, or `/$count`, optionally with expand options, to return only the count of +matching entities. - an entity-valued instance annotation to expand the related entity or entities, optionally followed by a [type-cast segment](#AddressingDerivedTypes) to expand only related entities of that derived type @@ -2047,36 +2048,12 @@ http://host/service/Customers?$expand=Addresses/Country A path MUST NOT appear in more than one expand item. -Query options can be applied to an expanded navigation property by -appending a semicolon-separated list of query options, enclosed in -parentheses, to the navigation property name. -The system query option, irrespective of casing or whether or not it is prefixed with a `$`, -MUST NOT be specified more than once in the list. -Allowed system query options are -[`$compute`](#SystemQueryOptioncompute), -[`$select`](#SystemQueryOptionselect), -`$expand`, and -[`$levels`](#ExpandOptionlevels) for all navigation properties, plus -[`$filter`](#SystemQueryOptionfilter), -[`$orderby`](#SystemQueryOptionorderby), -[`$skip`](#SystemQueryOptionstopandskip), [`$top`](#SystemQueryOptionstopandskip), -[`$count`](#SystemQueryOptioncount), and -[`$search`](#SystemQueryOptionsearch) -for collection-valued navigation properties. - -::: example -Example ##ex: all categories and for each category all related products -with a discontinued date equal to `null` -``` -http://host/service/Categories?$expand=Products($filter=DiscontinuedDate eq null) -``` -::: - The `$count` segment can be appended to a navigation property name or -[type-cast segment](#AddressingDerivedTypes) following a navigation +[type-cast segment](#AddressingDerivedTypes) following a collection-valued navigation property name to return just the count of the related entities. The -`$filter` and `$search` system query options can be used to limit the -number of related entities included in the count. +[`$filter`](#SystemQueryOptionfilter) and [`$search`](#SystemQueryOptionsearch) +[Expand Options](#ExpandOptions) +can be used to limit the number of related entities included in the count. ::: example Example ##ex: all categories and for each category the number of all @@ -2096,11 +2073,11 @@ http://host/service/Categories?$expand=Products/$count($search=blue) To retrieve entity references instead of the related entities, append `/$ref` to the navigation property name or [type-cast segment](#AddressingDerivedTypes) following a navigation property name. -The system query options [`$filter`](#SystemQueryOptionfilter), +The [Expand Options](#ExpandOptions) [`$filter`](#SystemQueryOptionfilter), [`$search`](#SystemQueryOptionsearch), [`$skip`](#SystemQueryOptionstopandskip), [`$top`](#SystemQueryOptionstopandskip), and -[`$count`](#SystemQueryOptioncount) can be used to limit the number of +[`$count`](#SystemQueryOptioncount) can be used to include the count of expanded entity references. ::: example @@ -2128,27 +2105,11 @@ http://host/service/Categories ``` ::: -[Cyclic navigation properties]{id=ExpandOptionlevels} (whose target type is identical or can be -cast to its source type) can be recursively expanded using the special -`$levels` option. The value of the `$levels` option is either a positive -integer to specify the number of levels to expand, or the literal string -`max` to specify the maximum expansion level supported by that service. -A `$levels` option with a value of 1 specifies a single expand with no -recursion. - -::: example -Example ##ex: all employees with their manager, manager's manager, and -manager's manager's manager -``` -http://host/service/Employees?$expand=ReportsTo($levels=3) -``` -::: - It is also possible to expand all declared and dynamic navigation properties using a star (`*`). To retrieve references to all related entities use `*/$ref`, and to expand all related entities with a certain -distance use the star operator with the `$levels` option. The star -operator can be combined with explicitly named navigation properties, +distance use the star operator with the `$levels` [Expand Option](#ExpandOptionlevels). +The star operator can be combined with explicitly named navigation properties, which take precedence over the star operator. The star operator does not implicitly include stream properties. @@ -2161,13 +2122,6 @@ http://host/service/Categories?$expand=*/$ref,Supplier ``` ::: -::: example -Example ##ex: expand all related entities and their related entities -``` -http://host/service/Categories?$expand=*($levels=2) -``` -::: - Specifying a stream property includes the media stream inline according to the specified format. @@ -2190,6 +2144,56 @@ http://host/service/Products?$expand=$value ``` ::: +#### ##subsubsubsec Expand Options + +Query options can be applied to an expanded navigation property by +appending a semicolon-separated list of query options, enclosed in +parentheses, to the navigation property name. +The system query option, irrespective of casing or whether or not it is prefixed with a `$`, +MUST NOT be specified more than once in the list. +Allowed system query options are +[`$compute`](#SystemQueryOptioncompute), +[`$select`](#SystemQueryOptionselect), +`$expand`, and +[`$levels`](#ExpandOptionlevels) for all navigation properties, plus +[`$filter`](#SystemQueryOptionfilter), +[`$orderby`](#SystemQueryOptionorderby), +[`$skip`](#SystemQueryOptionstopandskip), [`$top`](#SystemQueryOptionstopandskip), +[`$count`](#SystemQueryOptioncount), and +[`$search`](#SystemQueryOptionsearch) +for collection-valued navigation properties. + +::: example +Example ##ex: all categories and for each category all related products +with a discontinued date equal to `null` +``` +http://host/service/Categories?$expand=Products($filter=DiscontinuedDate eq null) +``` +::: + +[Cyclic navigation properties]{id=ExpandOptionlevels} (whose target type is identical or can be +cast to its source type) can be recursively expanded using the special +`$levels` expand option. The value of the `$levels` expand option is either a positive +integer to specify the number of levels to expand, or the literal string +`max` to specify the maximum expansion level supported by that service. +A `$levels` option with a value of 1 specifies a single expand with no +recursion. + +::: example +Example ##ex: all employees with their manager, manager's manager, and +manager's manager's manager +``` +http://host/service/Employees?$expand=ReportsTo($levels=3) +``` +::: + +::: example +Example ##ex: expand all related entities and their related entities +``` +http://host/service/Categories?$expand=*($levels=2) +``` +::: + ### ##subsubsec System Query Option `$select` The `$select` system query option allows clients to request a specific @@ -2207,7 +2211,7 @@ grammar of the `$select` query option. The value of `$select` is a comma-separated list of select items. Each select item is one of the following: -- a path, to include a property, +- a path, optionally followed by a count segment or select options - a star (`*`), to include all declared or dynamic properties of the type, or - a qualified schema name followed by a @@ -2224,7 +2228,7 @@ properties defined on the derived type. A path can end with - the name of a property or non-entity-valued instance annotation of the identified -instance of a structured type, +instance of a structured type - the qualified name of a bound action, - the qualified name of a bound function to include all matching overloads, or @@ -2294,8 +2298,8 @@ in order to select a property defined on a type derived from the type of the resource segment. A select item that is a complex type or collection of complex type can -be followed by a forward slash, an optional [type-cast segment](#AddressingDerivedTypes), and the name of a property of the -complex type (and so on for nested complex types). +be followed by a forward slash, an optional [type-cast segment](#AddressingDerivedTypes), +and the name of a property of the complex type (and so on for nested complex types). ::: example Example ##ex: the `AccountRepresentative` property of any supplier that @@ -2309,24 +2313,23 @@ http://host/service/Suppliers ``` ::: -Query options can be applied to a select item that is a path to a single -complex value or a collection of primitive or complex values by -appending a semicolon-separated list of query options, enclosed in -parentheses, to the select item. The allowed system query options depend -on the type of the resource identified by the select item, see section -[System Query Options](#SystemQueryOptions), with the exception of -[`$expand`](#SystemQueryOptionexpand). The same property MUST NOT have -select options specified in more than one place in a request and MUST -NOT be specified in more than one expand. +If the path ends in a collection of primitive or complex values, +then the count segment (`/$count`), optionally followed by the +[Select Options](#SelectOptions) [`$filter`](#SystemQueryOptionfilter) +and/or [`$search`](#SystemQueryOptionsearch), can be +appended to the path in order to return only the count of the matching items. ::: example -Example ##ex: select up to five addresses whose `City` starts with an -`H`, sorted, and with the `Country` expanded +Example ##ex: for each `Customer`, return the `ID` and the count of `Addresses` ``` -http://host/service/Customers - ?$select=Addresses($filter=startswith(City,'H');$top=5; - $orderby=Country/Name,City,Street) - &$expand=Addresses/Country +http://host/service/Customers?$select=ID,Addresses/$count +``` +::: + +::: example +Example ##ex: for each `Customer`, return the `ID` and the count of `Addresses` whose `City` starts with 'H' +``` +http://host/service/Customers?$select=ID,Addresses/$count($filter=startswith(City,'H')) ``` ::: @@ -2370,6 +2373,39 @@ of properties, open properties, navigation properties, actions and functions to be returned is equal to the union of the set of those identified by each select item. +#### ##subsubsubsec SelectOptions + +Query options can be applied to a select item that is a path to a single +complex value or a collection of primitive or complex values by +appending a semicolon-separated list of query options, enclosed in +parentheses, to the select item. The allowed system query options depend +on the type of the resource identified by the select item, see section +[System Query Options](#SystemQueryOptions), with the exception of +[`$expand`](#SystemQueryOptionexpand). The same property MUST NOT have +select options specified in more than one place in a request and MUST +NOT be specified in more than one expand. + +If the select item is a complex type, or collection of complex types, then +it can include a nested select. + +::: example +Example ##ex: return the City from the Address complex type +``` +http://host/service/Customers?$select=Address($select=City) +``` +::: + +::: example +Example ##ex: select up to five addresses whose `City` starts with an +`H`, sorted, and with the `Country` expanded +``` +http://host/service/Customers + ?$select=Addresses($filter=startswith(City,'H');$top=5; + $orderby=Country/Name,City,Street) + &$expand=Addresses/Country +``` +::: + ### ##subsubsec System Query Option `$orderby` The `$orderby` system query option allows clients to request resources