我有一个我正在使用MySQL使用实体框架5执行的查询。
var employeeDetails = (from em in entities.employeemasters.AsEnumerable()
join sf in entities.salaryfitments.AsEnumerable()
on em.empID equals sf.empID into emsf
from x in emsf
where (x.edCode.ToString().Trim().Equals(txtEDCode.Text)
&& x.edCode != "SYS001")
select new { em, x });
where (x.edCode.ToString().Trim().Equals(txtEDCode.Text)
检查是否为该员工存储了任何收入/扣除额,如果这样,我就能获得金额数字。
我希望查询返回所有员工,如果他们没有匹配txtedCode.text的特定收入/扣除额,则返回默认值。
我不能将.DefaultIfEmpty()
放在where (x.edCode.ToString().Trim().Equals(txtEDCode.Text)
我该怎么做才能获得适当的结果?
,而不是返回整个实体,我将创建一个新对象,只有我感兴趣的字段并使用三元字段,例如在选择语句中提供默认值。
select new {
name = x.Name,
salary = x.Salary,
code = string.IsNullOrEmpty(x) ? "Blah" : x
}