views:

29

answers:

1

I got a scenario where we are doing soft delete on the rows in database. I want to include the rows that are not deleted. How can I achieve it using LINQ.

Say

from c in context.ASDSet
where (c => c.DeletedFlag.HasValue && !c.DeletedFlag.Value)

But I couldn't achieve the result.

I want the resultant SQL to be of form:

select *  from table where IsNull(column, 0) = 0
+2  A: 

It sounds like you actually want:

var query = Context.ASDSet.Where(c => c.DeletedFlag == null || 
                                      c.DeletedFlag.Value == false);

In other words, that includes rows where the flag is null, whereas your current query excludes rows where the flag is null.

Jon Skeet