我做的左连接LINQ到SQL,所以我的问题是,当选择正确的表字段,我检查每个字段wheather连接的对象是否为空,这是正确的方法吗?或者还有其他方法可以做到吗?我的查询是像LINQ到SQL的左连接,需要检查为空表为
from u in user
join x in employeee on u.id equals x.userId
into ux from ujoinx in ux.DefaultIfEmpty()
join y in department on x.id equals y.employeeId
into xy from xjoiny in xy.DefaultIfEmpty()
select new {
EmployeeSal = ujoinx!=null?ujoinx.employeeSal:0, // see checkig for null
EmployeeTax = ujoinx!=null?ujoinx.employeeTax:0, // in this 3 lines
UserName = u.username,
DeptName = xjoiny!=null?xjoiny.name:"" //is this a correct way ?
}
正确造成的答案查询,但如果我不检查空 其扔object reference not set.....error
那几个领域。 这是什么DefaultIfEmpty()
干什么?
谢谢,实际上我有一个相当大数量的字段,每个字段都必须检查null im感觉有点肮脏的编程,所以认为有没有其他的方式来做到这一点.. – Meson