odata.net icon indicating copy to clipboard operation
odata.net copied to clipboard

Comparing a flags enum field with string constant using the has operator fails

Open khodaie opened this issue 5 years ago • 2 comments

Comparing a flags enum field with string constant using the has operator fails.

/odata/files?$filter=Attributes has 'Hidden'

Assemblies affected

Microsoft.OData.Core

Reproduce steps

Use the has operator to compare a flag enum filed and a string constant

Expected result

The string constant should be treated as enum constant value.

Actual result

The exception of type Microsoft.OData.ODataException is thrown with message: "A binary operator with incompatible types was detected. Found operand types 'My.FlagsEnumType' and 'Edm.String' for operator kind 'Has'."

Additional detail

The code in the Microsoft.OData.UriParser.TypePromotionUtils.PromoteOperandTypes method should be fixed to support comparing enum with string using the has operator.

khodaie avatar Aug 19 '20 10:08 khodaie

@khodaie Have you tried using the fully qualified namespace for the enum? It seems like ODL is treating Hidden as a string and not as enum . You can try using has - NameSpace'Hidden'.

KanishManuja-MS avatar Aug 24 '20 06:08 KanishManuja-MS

@KanishManuja-MS When using UnqualifiedCallAndEnumPrefixFreeResolver or StringAsEnumResolver, I expect to use the prefix free enum in the has operrator as well as eq and ne. In previous versions of the ODATA(v6.19-) it works as expected and I cannot tell my API users to change their queries because of my internal framework update.

khodaie avatar Aug 24 '20 10:08 khodaie