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)
精彩评论