2.2.3.6.1.2 Evaluating System Query Options

Any combination of the system query options defined in this document MAY be present on a valid data service URI. A data service URI with more than one query option present MUST be evaluated as if the query options were applied to the resources identified by the resource path section of the URI, in the following order: $filter, $inlinecount, $orderby, $skiptoken, $skip, $top, $expand, $select, $format.

For example, using data from Appendix A: Sample Entity Data Model and CSDL Document (section 6), the resource identified by the data service URI http://host/service/Customers?$expand=Orders&$filter=substringof(CompanyName, 'bikes')&$orderby=CompanyName asc&$top=2&$skip=3&$skiptoken='Contoso','AKFNU'&$inlinecount=allpages&$select=CustomerID,CustomerName,Orders is determined as follows:

  1. Start with the set of all EntityType instances in the Customers EntitySet in the data service.

  2. Remove all customer instances that do not have "bikes" in their company name (the entities that do not satisfy the condition in the $filter query option).

  3. Determine the count N of all customers identified in step 2.

  4. Sort the set of customers identified in step 2 in ascending order using the values from the CompanyName property defined on the Customer EntityType.

  5. Seek in to the collection up to the index identified by the $skiptoken query option. Select all entities at the index through the end of the collection.

  6. Starting from the 4th entity (from the collection returned by step 4), as directed by $skip=3, select the next two entities (for example, the 5th and 6th entities in the set), as directed by $top=2.

  7. Of the two entities returned from step 6, select only the CustomerName and CustomerID properties of the Customer entities and all properties of the Order entities. The preceding URI identifies the two entities (and their related entities) returned from this step.