This part:
|
// Convert to integers unless Enum type is required |
|
if ((TypeHelper.IsEnum(leftUnderlyingType) || TypeHelper.IsEnum(rightUnderlyingType)) && binaryOperator != BinaryOperatorKind.Has) |
|
{ |
|
Type enumType = TypeHelper.IsEnum(leftUnderlyingType) ? leftUnderlyingType : rightUnderlyingType; |
|
Type enumUnderlyingType = Enum.GetUnderlyingType(enumType); |
|
left = ConvertToEnumUnderlyingType(left, enumType, enumUnderlyingType); |
|
right = ConvertToEnumUnderlyingType(right, enumType, enumUnderlyingType); |
|
} |
Arbitrarily converts enums to integers, which may or might not be the desired effect.
I have a custom ValueConverter applied to an enum in EF Core, which causes them to be saved as a hash of the enum name instead of their enum value. So Type eq 'MyType' currently becomes (int)$it.Type == 1 which does not make sense for my case because it should be $it.Type == TypeEnum.MyType (which later will be translated by EF Core into something like (int)$it.Type == 123456789).
This makes even less sense considering that enums themselves support also comparison operators like >, >=, <, <=, ... so why this decision was even made in the first place?
I think enum handling or conversions should be left to the underlying IQueryable QueryProvider, EF Core in this case, OData expressions should be translated as they are.
This part:
AspNetCoreOData/src/Microsoft.AspNetCore.OData/Query/Expressions/ExpressionBinderHelper.cs
Lines 65 to 72 in 85944be
Arbitrarily converts enums to integers, which may or might not be the desired effect.
I have a custom ValueConverter applied to an enum in EF Core, which causes them to be saved as a hash of the enum name instead of their enum value. So
Type eq 'MyType'currently becomes(int)$it.Type == 1which does not make sense for my case because it should be$it.Type == TypeEnum.MyType(which later will be translated by EF Core into something like(int)$it.Type == 123456789).This makes even less sense considering that enums themselves support also comparison operators like >, >=, <, <=, ... so why this decision was even made in the first place?
I think enum handling or conversions should be left to the underlying
IQueryableQueryProvider, EF Core in this case, OData expressions should be translated as they are.