asp.net - Linq,如何检查字段的值是否为空

标签 asp.net linq null nullreferenceexception

在使用 linq 查询时我收到错误

System.NullReferenceException: Object reference not set to an instance of an object.

var db = from d in DepartmentBLL.GetDepartmentList()
     join b in BudgetMasterBLL.GetBudgetMasterList()            
     on d.Departmentid equals b.Departmentid into leftJoin                     
     from results in leftJoin.DefaultIfEmpty()
     select new
     {
         Name = d.Name,
         Create = results.Budgetmasterid == null ? "null": "value", //ERROR HERE
         CreateURL = "frmBudgetInitial.aspx?departmentid=" + d.Departmentid.ToString() + "&departmentcategoryid=" + d.Departmentcategoryid.ToString()
     };

我在论坛上找到了一些帮助,但没有解决我的问题,请指教。谢谢,

最佳答案

尝试

Create = results == null || string.IsNullOrEmpty(results.Budgetmasterid) ? "null": "value",

Create = results == null || string.IsNullOrWhitespace(results.Budgetmasterid) ? "null": "value",

关于asp.net - Linq,如何检查字段的值是否为空,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9194229/

相关文章:

c# - 使用 linq 从 select new 返回多行

c++ - 从普通指针中减去空指针?

asp.net - 寻找最好的 Asp.net 调查应用程序

c# - 尝试将 SMTP 与 gmail 一起使用

c# - 文件上传 60 分钟后启动线程进程

postgresql - PostgreSQL 范围类型中的 NULL 与 `infinity`

c - 为什么这种形式在 C 中是正确的?

asp.net - 使用 NUnit、NSubstitute 和异步方法进行单元测试时出现 NullReferenceException

c# - 如何使用 LINQ 计算最长连胜?

linq - Task.WhenAll 何时枚举?