2

I have a problem querying data from a table with a nullable tinyint column.
The problem seems to be that the query is generated as:

AND ( CAST( [Extent1].[PositionEffect] AS int) = @p__linq__3)

=> @p__linq__3 = NULL

If i run that query manually it doesn't turn up any results. However, when I replace the query with:

AND ([Extent1].[PositionEffect] IS @p__linq__3)

it turns up the expected results.
My C# query looks like this:

 context.Allocations.Where(x => ... && x.PositionEffect == (byte?) positionEffect)

So, why is the entity framework generating the incorrect query here and is there any way to fix this?

Thanks,

Tom

2
  • 1
    Does this social.msdn.microsoft.com/forums/en-US/linqprojectgeneral/… shed any light on the issue? Commented Jul 8, 2010 at 23:01
  • thanks, yes this did help, though it was for linq to sql and not entity framework (object.Equals does not work in entity framework) and I had to resort to this nasty piece of code: (positionEffect == null ? x.PositionEffect == null : x.PositionEffect == (byte?)positionEffect) Commented Jul 9, 2010 at 13:12

1 Answer 1

1

as Will A pointed out, this seems to be a reported bug in Entity Framework and the workaround to generate the correct query is:

 (positionEffect == null ? x.PositionEffect == null : x.PositionEffect == (byte?)positionEffect)
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.