在使用 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/