There is an unsaved comment in progress. You will lose your changes if you continue. Are you sure you want to reopen the work item?

4

Closed

UpForGrabs: Query: Support Enum.HasFlag in LINQ to Entities [FixedIn6.1.0-alpha1] [AffectedLastRTM]

description

Enum.HasFlag is a useful and user friendly way to check if a number of bits are set for an enum variable, but if you try to use it in a entity framework Query you get an exception similar to the following:

_"An unhandled exception of type 'System.NotSupportedException' occurred in mscorlib.dll
Additional information: LINQ to Entities does not recognize the method 'Boolean HasFlag(System.Enum)' method, and this method cannot be translated into a store expression."_

I propose that support is added so that one can use the HasFlag function using entity framework. The implementation should be quite straight forward since bitwise operators are already supported. In short the expression "enumVariable.HasFlag(enumValue)"
should be translated to "((enumVariable & enumValue) == enumValue)".