Open
Description
Given the following filter:
$filter=contains(tolower(cast(MyEnumProperty, Edm.String)), 'EnumLabel1')
Executing the filter seems to convert the value of MyEnumProperty to the int-representation in form of a string.
This query then works (assuming "EnumLabel1" is represented by int-value 2:
$filter=contains(tolower(cast(MyEnumProperty, Edm.String)), '2')
Additional detail
Have a look at the else branch in FilterBinder.cs - BindCastToStringType(Expression source)
:
if (TypeHelper.IsGenericType(source.Type) && source.Type.GetGenericTypeDefinition() == typeof(Nullable<>))
{
...
}
else
{
sourceValue = TypeHelper.IsEnum(source.Type) ?
Expression.Convert(source, Enum.GetUnderlyingType(source.Type)) :
source;
return Expression.Call(sourceValue, "ToString", typeArguments: null, arguments: null);
}
The Enum.GetUnderlyingType(source.Type)
is Int32, which is passed to the convert function.
I'm not too familiar with the OData spec, but is it really the expected behavior, since on a lot of other places, enum label names are used instead of enum values.