Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Binary AND not supported for bitmasks #191

Closed
Toxantron opened this issue Nov 12, 2019 · 4 comments
Closed

Binary AND not supported for bitmasks #191

Toxantron opened this issue Nov 12, 2019 · 4 comments
Assignees

Comments

@Toxantron
Copy link

Description

I have an entity with a property of type integer which contains a converted bit-flag enum. I want to query entities by comparing that value to a given bit-mask which is an integer as well.

If I replace the given bit-mask with a static integer like 1, everything works fine. The exception thrown by Entity Framework indicates, that effort wrongly converts the given bit-mask parameter to a Nullable<int>.

Exception

Exception message: The binary operator AND is not defined for "System.Nullable`1[System.Int32]" and "System.Int32"

Stack trace:
at System.Linq.Expressions.Expression.GetUserDefinedBinaryOperatorOrThrow(ExpressionType binaryType, String name, Expression left, Expression right, Boolean liftToNull)
   at System.Linq.Expressions.Expression.And(Expression left, Expression right, MethodInfo method)
   at Effort.Internal.DbCommandTreeTransformation.CanonicalFunctionMapper.<>c.<AddBitwiseMappings>b__4_1(EdmFunction f, Expression[] args)
   at Effort.Internal.DbCommandTreeTransformation.CanonicalFunctionMapper.CreateMethodCall(EdmFunction function, Expression[] arguments)
   at Effort.Internal.DbCommandTreeTransformation.TransformVisitor.Visit(DbComparisonExpression expression)
   at Effort.Internal.DbCommandTreeTransformation.TransformVisitor.Visit(DbAndExpression expression)
   at Effort.Internal.DbCommandTreeTransformation.TransformVisitor.Visit(DbFilterExpression expression)
   at Effort.Internal.DbCommandTreeTransformation.TransformVisitor.Visit(DbProjectExpression expression)
   at Effort.Internal.CommandActions.QueryCommandAction.ExecuteDataReader(ActionContext context)
   at System.Data.Entity.Infrastructure.Interception.InternalDispatcher`1.Dispatch[TTarget,TInterceptionContext,TResult](TTarget target, Func`3 operation, TInterceptionContext interceptionContext, Action`3 executing, Action`3 executed)
   at System.Data.Entity.Infrastructure.Interception.DbCommandDispatcher.Reader(DbCommand command, DbCommandInterceptionContext interceptionContext)
   at System.Data.Entity.Core.EntityClient.Internal.EntityCommandDefinition.ExecuteStoreCommands(EntityCommand entityCommand, CommandBehavior behavior)

Project

public class MyEntity
{
    public int BitValues { get; set; }
}

public void Filter()
{
    DbSet<MyEntity> set = context.MyEntities;

    // Throws exception
    var bitMask = 1;
    var query = (from entity in set
                        where (entity.Bitvalues & bitMask) == bitMask
                        select entity).ToList();

    // Works fine
    query = (from entity in set
                        where (entity.Bitvalues & 1) == 1
                        select entity).ToList();
}

Further technical details

  • EF version: 6.3
  • EF Effort version: 2.2.6
  • Database Provider: NMemory 3.1.0
@JonathanMagnan JonathanMagnan self-assigned this Nov 12, 2019
@JonathanMagnan
Copy link
Member

Hello @Toxantron ,

Thank you for reporting,

We will look if that's possible to do something on our side.

Best Regards,

Jonathan


Performance Libraries
context.BulkInsert(list, options => options.BatchSize = 1000);
Entity Framework ExtensionsEntity Framework ClassicBulk OperationsDapper Plus

Runtime Evaluation
Eval.Execute("x + y", new {x = 1, y = 2}); // return 3
C# Eval FunctionSQL Eval Function

@JonathanMagnan
Copy link
Member

Hello @Toxantron ,

The v2.2.7 has been released.

Could you confirm for us that the issue is fixed on your side as well?

@JonathanMagnan
Copy link
Member

Hello @Toxantron,

Since our last conversation, we haven't heard from you.

Did you get the time to try the released version V2.2.7

Let us know if that issue is fixed on your side.

Best regards,

Jon

@Toxantron
Copy link
Author

Hello Jon,

sorry I did not get back to you sooner. We had disabled the unit test and didn't work on that part of the code in the last weeks.

But I just updated the package, enabled the test and it runs without errors. Thank you very much for the fix.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

2 participants