-1
我想在LINQ中重写下面的sql查询。但我的问题是,我不知道如何用LINQ LEFT JOIN写入添加AND(& &)运算符(查看我的第二个左连接)。任何人都可以帮忙吗?如何将以下SQL查询重写为LINQ查询?
SELECT emp.EmployeeId,
dsg.Name,
pob.CompanyContribution,
pob.EmployeeContribution,
pob.OpeningIncome
FROM HrmEmployees AS emp
LEFT JOIN HrmDesignations AS dsg ON emp.HrmDesignationId=dsg.Id
LEFT JOIN PfmOpeningBalance AS pob ON emp.Id=pob.HrmEmployeeId AND pob.CmnCalendarYearId=2
WHERE emp.Id=6
我试了下面的一个。但编译错误 -
from emp in dbContext.EmployeeList
join dsg in dbContext.hrmDesig on emp.HrmDesignationId equals dsg.Id into DSGLeftJoin
from dsglj in DSGLeftJoin.DefaultIfEmpty()
join pob in dbContext.PfOpeningBalances on emp.Id equals pob.HrmEmployeeId into POBLeftJoin
from poblj in POBLeftJoin.DefaultIfEmpty() && poblj.CmnCalendarYearId == clndrId
where emp.Id==empId
select new
{
empIdr = emp.Id,
EmployeeId = emp.EmployeeId,
EmployeeName = emp.Name,
Designation = dsglj.Name,
OpeningIncome = poblj.OpeningIncome,
EmployeeContribution = poblj.EmployeeContribution,
CompanyContribution = poblj.CompanyContribution
}
任何你试过的东西? – Irshad
是的,但得到编译错误。可能是错误是为wron语法@Irshad –
在帖子中显示代码,我们可以帮助您 – Irshad