LINQ在SQL语句中生成额外的IS NULL条件 [英] LINQ is Generating Extra IS NULL Condition in SQL Statement
本文介绍了LINQ在SQL语句中生成额外的IS NULL条件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在写一些LINQ来基于电子邮件获取记录,但是,生成的SQL包含一个附加的 IS NULL
条件,该条件不需要存在,因为我正在检查参数值在将条件添加到查询之前,在代码中输入null.
I'm writing some LINQ to fetch records based on an email, however, the generated SQL contains an additional IS NULL
condition which doesn't need to be there because I am checking the parameter value for null in the code prior to adding the condition to the query.
我的LINQ代码是:
if (email != null)
{
query = query.Where(r => r.Email == email);
}
由此产生的SQL条件是:
The SQL condition generated from this is:
(([Extent1].[Email] = @p__linq__0) OR (([Extent1].[Email] IS NULL) AND (@p__linq__0 IS NULL)))
The
(([Extent1].[Email] IS NULL) AND (@p__linq__0 IS NULL))
据我所见,
不需要在那里.
doesn't need to be there as far as I can see.
有什么办法让LINQ忽略它?
Is there any way to get LINQ to omit it?
推荐答案
如果 email
为null,它们就在那儿.
They're there in case email
is null.
查看全文