LINQ中的IsNull和可为空类型 [英] IsNull and nullable types in LINQ
本文介绍了LINQ中的IsNull和可为空类型的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试将SQL的以下行转换为LINQ代码:
I am trying to convert the following line of SQL to LINQ code :
AND IsNull(Deleted,0) = 0
我已经尝试过这样做:
&& Deleted != null ? Deleted : false
这:
&& (bool)Deleted != null ? (bool)Deleted : false
第一次尝试给了我一个错误,因为Deleted是可空的类型,第二次尝试没有返回与原始SQL相同的数据集.有人可以告诉我我在做什么错吗?
The first attempt gave me an error as Deleted is a nullable type, and the second attempt does not return the same dataset as the original SQL. Can anybody tell me what I am doing wrong?
推荐答案
您可以使用
&& Deleted.GetValueOrDefault(false)== false
&& Deleted.GetValueOrDefault(false) == false
这篇关于LINQ中的IsNull和可为空类型的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文