开发者

IsNull and nullable types in LINQ

I am trying to convert the following line of SQL to LINQ code :

AND IsNull(Deleted,0) = 0

I have tried by doing this :

&开发者_运维百科amp;& Deleted != null ? Deleted : false

And this :

&& (bool)Deleted != null ? (bool)Deleted : false

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?


You can use

&& Deleted.GetValueOrDefault(false) == false


linq;

where !(u.Deleted ?? false)

sql output:

WHERE (CASE WHEN ([Extent1].[Deleted] IS NULL) THEN cast(0 as bit) ELSE [Extent1].[Deleted] END) <> cast(1 as bit)

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜