在 LINQ To SQL 中使用“Is NULL/not NULL”
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/9498300/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Using " Is NULL/not NULL" in LINQ To SQL
提问by Mario Corchero
i would like to translate this request in LINQ to SQL:
我想将此请求在 LINQ 中转换为 SQL:
SELECT * from Agir where NouvelIncident='1' AND facturable is null
My try:
我的尝试:
public static List<Agir> GetINDEFAgir()
{
DataClassesActilogDataContext db = ContextSingleton.GetDataContext();
List<Agir> list;
var v = from i in db.Agir
where i.facturable is null && i.NouvelIncident == true
select i;
list = v.ToList();
return list;
}
Looks like "is null" is not allowed in LINQ to SQL... i have a mistake.
看起来在 LINQ to SQL 中不允许“为空”......我有一个错误。
Thanks in advance for your help
在此先感谢您的帮助
回答by Mario Corchero
Use ==
, 'is'
is to check types
用途==
,'is'
是检查类型
public static List<Agir> GetINDEFAgir()
{
DataClassesActilogDataContext db = ContextSingleton.GetDataContext();
List<Agir> list;
var v = from i in db.Agir
where i.facturable == null && i.NouvelIncident == true
select i;
list = v.ToList();
return list;
}
回答by Mike Mooney
Doesn't this work?
这不行吗?
var v = from i in db.Agir
where i.facturable == null && i.NouvelIncident == true
select i;
Linq-to-SQL should translate that to the proper SQL.
Linq-to-SQL 应该将其转换为正确的 SQL。