Asp.net 检查实体框架中Linq查询中的空值

Asp.net 检查实体框架中Linq查询中的空值,asp.net,linq,entity-framework,null,Asp.net,Linq,Entity Framework,Null,如何比较.Net Entity framework 4.1中Linq查询部分的整型空值?如果int可为空,则只能将int与null进行比较。如果不是,则int的默认值将是0,并且从不null 您可以这样定义一个可为null的int属性: int? value { get; set; } if ( value != null ) { int x = value.Value; } 然后像这样检查: int? value { get; set; } if ( value != null )

如何比较.Net Entity framework 4.1中Linq查询部分的整型空值?

如果
int
可为
空,则只能将
int
null
进行比较。如果不是,则
int
的默认值将是
0
,并且从不
null

您可以这样定义一个可为null的int属性:

int? value { get; set; }
if ( value != null )
{
   int x = value.Value;
}
然后像这样检查:

int? value { get; set; }
if ( value != null )
{
   int x = value.Value;
}
在Linq查询的where子句中

var result = from d in data
             where d.Value != null
             select d

如果要与
null
值进行比较,则由于存在错误,必须首先将值与
null
进行比较

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