实体框架 - 查询可空列的问题 [英] Entity Framework - Problem with querying nullable column
问题描述
AND(CAST([Extent1]。[PositionEffect] AS int)= @ p__linq__3)
=> @ p__linq__3 = NULL
如果我手动运行该查询,则不会显示任何结果。但是,当我用以下代码替换查询:
AND([Extent1]。[PositionEffect] IS @ p__linq__3)
它会显示预期的结果。
我的C#查询如下所示:
context.Allocations.Where(x => ...&& x.PositionEffect ==(byte?)positionEffect)
那么为什么实体框架在这里生成错误的查询,有没有办法解决这个问题? p>
谢谢,
Tom
如Will A指出的,这似乎是实体框架中报告的错误,生成正确查询的解决方法是:
(positionEffect == null?x.PositionEffect == null:x.PositionEffect ==(byte?)positionEffect)
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
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)
这篇关于实体框架 - 查询可空列的问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!