Mes*_*son 6 c# linq linq-to-sql
我正在左边加入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 ?
}
Run Code Online (Sandbox Code Playgroud)
查询得到了正确的答案,但如果我不检查那些几个字段为null抛出它object reference not set.....error.这到底是DefaultIfEmpty()什么?
| 归档时间: |
|
| 查看次数: |
6469 次 |
| 最近记录: |