In Entity Framework, check for null values in Linq queries.

asp.net entity-framework linq null

Question

How can I compare null values of the integer type? In what part of the.Net Entity Framework 4.1 does Linq query?

1
2
1/18/2012 3:41:20 PM

Accepted Answer

You can only contrast two things.int to NULL if theint is nullable If not, the standard setting forint should be0 but nevernull .

A nullable int property is defined as follows:

int? value { get; set; }

And verify it as follows:

if ( value != null )
{
   int x = value.Value;
}

It would be in the where clause of a Linq query.

var result = from d in data
             where d.Value != null
             select d
11
1/18/2012 3:43:37 PM

Popular Answer

If you are evaluating against anull value, you must first contrast it withnull caused by a bug.

var field = from field in table
            where (value == null ? field.property == null : field.property == value)
            select field;


Related Questions





Related

Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow