views:

36

answers:

1

Hi,

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

+1  A: 

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)
Tom Frey