linq to sql检查是否为空 [英] linq to sql checking for null

查看:88
本文介绍了linq to sql检查是否为空的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的数据库字段int_ParentId由Null值组成.我将如何在此linq查询中检查它是否为null.它不起作用

my database field int_ParentId consist of a Null value . how would i check it for a null in this linq query . it is not working

  return _db.Categories.Where(m => m.int_ParentId==null);

推荐答案

您是否已将int_ParentId数据库字段映射到int?类型(例如<Column Name="int_ParentId" Type="System.Int32" DbType="Int" CanBeNull="true" />)?如果是,则两者:

Have you mapped you int_ParentId database field to int? type (e.g. <Column Name="int_ParentId" Type="System.Int32" DbType="Int" CanBeNull="true" />)? If yes, both:

return _db.Categories.Where(m => m.int_ParentId == null);

return _db.Categories.Where(m => m.int_ParentId.HasValue);

应该工作.

这篇关于linq to sql检查是否为空的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆