IN operator
Applies To: # OData core lib v7 supported OData Core Lib V7
The IN operator is a new feature in OData 4.01 that enables a shorthand way of writing multiple EQ expressions joined by OR. For example,
GET /service/Products?$filter=Name eq 'Milk' or Name eq 'Cheese' or Name eq 'Donut'
can become
GET /service/Products?$filter=Name in ('Milk', 'Cheese', 'Donut')
Of the binary expression invoking IN, the left operand must be a single value and the right operand must be a comma-separated list of primitive values or a single expression that resolves to a collection; the expression returns true if the left operand is a member of the right operand.
The IN
operator is used in expressions that resolve to a Boolean. Common use would be with $filter
and it can also be used for $orderby
. See test cases for examples of supported scenarios.
Having successfully parsed the $filter
expression, the FilterClause
will have an Expression
member which can be casted to an InNode
object. The members of InNode Left
and Right
represent SingleValueNode
and CollectionNode
respectively. From there, it is up to the user to do whatever they would like with the parsed information from the InNode
. As shown in the code samples, it may be in the user's best interest to downcast the SingleValueNode
and CollectionNode
to subclasses to access additional properties.