You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The in operator does not allow you to use a string literal as an operand when comparing against a collection of enums.
For example, let's assume WorkingDays property is a collection of enums, the following would fail with an error:
$filter='Monday' in WorkingDays
For it to work, you have to use the fully qualified enum literal:
$filter=ODataRoutingSample.Models.WorkingDay'Monday' in WorkingDays
However, binary operators like eq do allow comparisons between string literals and enums, so the following does work:
$filter=WorkingDays/any(t:t eq 'Monday')
I think both approaches should work. According to the spec:
Enumeration literals in OData 4.0 required prefixing with the qualified type name of the enumeration.
In OData 4.01, services MUST support duration and enumeration literals with or without the type prefix.
OData clients that want to operate across OData 4.0 and OData 4.01 services should always include the prefix for duration and enumeration types.
Assemblies affected
Microsoft.OData.Core 7.10.0
Reproduce steps
Create a service that exposes an entity set with a property that contains a collection of enums, e.g.: WorkingDays that contains enum values: WorkingDay.Monday, WorkingDay.Tueday, etc.
Make a query against the service with the filter expression: $filter='Monday' in WorkingDays.
The request should return the expected filtered data, same to what you would get with: $filter=WorkingDays/any(t:t eq 'Monday')
Actual result
The following error is thrown:
System.ArgumentException: An instance of InNode can only be created where the item types of the right operand 'ODataRoutingSample.Models.WorkingDay' and the left operand 'Edm.String' can be compared.
Related to OData/AspNetCoreOData#536
The
in
operator does not allow you to use a string literal as an operand when comparing against a collection of enums.For example, let's assume
WorkingDays
property is a collection of enums, the following would fail with an error:For it to work, you have to use the fully qualified enum literal:
However, binary operators like
eq
do allow comparisons between string literals and enums, so the following does work:I think both approaches should work. According to the spec:
Assemblies affected
Microsoft.OData.Core 7.10.0
Reproduce steps
Create a service that exposes an entity set with a property that contains a collection of enums, e.g.:
WorkingDays
that contains enum values:WorkingDay.Monday
,WorkingDay.Tueday
, etc.Make a query against the service with the filter expression:
$filter='Monday' in WorkingDays
.See this related issue for a more detailed repro example.
Expected result
The request should return the expected filtered data, same to what you would get with:
$filter=WorkingDays/any(t:t eq 'Monday')
Actual result
The following error is thrown:
Additional detail
For binary operators, the
BinaryOperatorBinder
promotes the operands to compatible types, specifically, strings are promoted to enums where applicable:The
InBinder
does not promote types. TheInNode
throws an exception if the type of one operand is not assignable to the other.The text was updated successfully, but these errors were encountered: