首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > .NET > .NET >

linq动态查询中字段为null的,该如何处理

2012-04-09 
linq动态查询中字段为null的[codeC#]publicxxfind(int?value){varquery....wherefiledvalueselect...}[

linq动态查询中字段为null的
  [code=C#]
public   xx   find(int?   value)
{
        var   query=....
                            where   filed=value
                            select   ...
}
[/code]

如果filed有null的数据   value为null的时候却查不到。请问该如何处理。

[解决办法]
DBNull.Value
[解决办法]
"int?" 说明你这个字段在数据库内设置了可空类型
在使用时要强制转化一下 where filed!=null && (int)filed==value
[解决办法]
var query=(...from ... select..)
.Where(i=>value.HasValue ? i.filed==value.Value : true);

热点排行