使用linq查询时我收到错误
System.NullReferenceException:对象引用未设置为 对象的实例。
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()
};
我在论坛上找到了一些帮助,但没有解决我的问题,请指教。感谢。,
答案 0 :(得分:3)
试
Create = results == null || string.IsNullOrEmpty(results.Budgetmasterid) ? "null": "value",
或
Create = results == null || string.IsNullOrWhitespace(results.Budgetmasterid) ? "null": "value",
答案 1 :(得分:2)
这应该有帮助
Create = results == null || results.Budgetmasterid == null ? "null": "value", //ERROR HERE