Tuesday 27 August 2013

How to differentiate between SQL Null ints in c#/ linq

How to differentiate between SQL Null ints in c#/ linq

In MVC we can declare nullable ints in our database context models as
public int? SomeField { get; set; }
But how do you check if a record for SomeField is Null in Linq. For
example if I want to get a list of rows with value not zero I use the
following Linq statement.
var k = db.TableSet.Where( u => u.Somefield != 0 )
Is there a Linq equivalent to include/exclude either/both Zeros and Null?
Edit: I am currently testing this but I am sure it will either be Null
exception or Null fields return as zero.

No comments:

Post a Comment