2.2.3.6.1.4 Filter System Query Option ($filter)

A data service URI with a $filter system query option identifies a subset of the entities in the EntitySet, identified by the resource path section of the URI, by only selecting the entities that satisfy the predicate expression specified by the query option.

The syntax of the filter system query option is defined as:

 filterQueryOption = "$filter" [WSP] "=" [WSP] boolCommonExpression

Examples:

 http://host/service.svc/Orders?$filter=ShipCountry eq 'France'

The set of Order entity instances where the ShipCountry is equal to the value "France".

 http://host/service.svc/Orders?$filter = Customer/ContactName ne 'Fred'

The set of Order entity instances where the associated Customer entity instance has a ContactName not equal to the value "Fred".

The syntax, construction, and evaluation rules for boolCommonExpression are defined in Common Expression Syntax (section 2.2.3.6.1.1).

The OData 3.0 protocol supports specifying the namespace-qualified EntityType of the property that is used in the filter.

 http://host/service.svc/Customers?$filter = SampleModel.VipCustomer/CreditPurchases/CreditLimit gt '5000'

The previous example shows the set of Customer entity instances that are of subtype VipCustomer, or any of its subtypes, with a CreditLimit greater than $5000. If an entity instance in the Customers EntitySet is not of type VipCustomer, or any of its subtypes, this falsifies the terms within the predicate and MUST result in the exclusion of the entity instance from the results.

The OData 3.0 protocol supports anyMethodCallExpression and allMethodCallExpression used in the filter.

Examples:

 http://host/service.svc/Orders?$filter=OrderLines/any(ol: ol/Quantity gt 10)

In the previous example, the Orders that have any Orderlines with a Quantity greater than 10.

 http://host/service.svc/Orders?$filter=OrderLines/all(ol: ol/Quantity gt 10)

In the previous example, the Orders for which all Orderlines have a Quantity greater than 10.

Show: