@item.qmsCallAudit.Employee.EmployeeProcesses
.Select(e=> e.Employee1.employee_code).SingleOrDefault().ToString();
如何检查e.Employee1.employee_code的空值
答案 0 :(得分:0)
你可以这样做:
var result = item.qmsCallAudit.Employee.EmployeeProcesses
.Where(e => e.Employee1 != null && e.Employee1.employee_code != null)
.Select(e=> e.Employee1.employee_code)
.SingleOrDefault();
var code = result != null ? result.ToString() : null;
ToString()
之后SingleOrDefault()
不能返回null,然后会抛出异常。
答案 1 :(得分:0)
@item.qmsCallAudit.Employee.EmployeeProcesses.Where(e => e.Employee1.employee_code != null).Select(e => e.Employee1.employee_code).SingleOrDefault().ToString();
试试这个^^