Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/sql/74.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 将LinQ中的where子句中的可空子句强制转换为实体而不进行空检查_C#_Sql_Linq_Linq To Entities - Fatal编程技术网

C# 将LinQ中的where子句中的可空子句强制转换为实体而不进行空检查

C# 将LinQ中的where子句中的可空子句强制转换为实体而不进行空检查,c#,sql,linq,linq-to-entities,C#,Sql,Linq,Linq To Entities,我知道我不能将值为“null”的可为null的int强制转换为不可为null的int int? v = null; int w = (int)v; 因此,我首先使用空检查生成where子句。但现在我看到,即使没有它,它似乎仍然有效,这怎么可能呢 我知道数据库中有许多LogEmneId为空 foreach (var logMaaler in ctx.LogMaalers.Where(lm => // (lm.LogEmneId != null &&

我知道我不能将值为“null”的可为null的int强制转换为不可为null的int

int? v = null;
int w = (int)v;
因此,我首先使用空检查生成where子句。但现在我看到,即使没有它,它似乎仍然有效,这怎么可能呢

我知道数据库中有许多
LogEmneId
为空

foreach (var logMaaler in ctx.LogMaalers.Where(lm =>
              // (lm.LogEmneId != null && logEmner.Contains((short)lm.LogEmneId))
                                          logEmner.Contains((short)lm.LogEmneId)
                                                ))
{
}
LinQ to entity语句是否被重写为一个sql查询,为我处理空检查

LinQ to entity语句是否被重写为一个sql查询,为我处理空检查

有点<在SQL查询中,code>Contains被转换为子句中的
,这对于
NULL
值非常有效。考虑以下查询:

SELECT *
FROM Table
WHERE Id IN (1,2,3,4,5,6,7)

当您在
Id
列中有一行
NULL
时,它可以正常工作。这正是这里发生的事情。

谢谢,那么我将跳过我自己的检查,确认它是多余的。