LINQ多表连接查询
var query = from et in _unitOfWork.Repository<EmployeeTarget>().Table
join bra in _unitOfWork.Repository<BranchInfo>().Table
on et.BranchCode equals bra.BranchCode
into temp1
from b in temp1.DefaultIfEmpty()
join emp in _unitOfWork.Repository<EmployeeInfo>().Table
on et.EmpCode equals emp.EmpCode
into temp2
from e in temp2.DefaultIfEmpty()
where et.EtYear == searchCriterria.Year && et.EtMonth == searchCriterria.Month
&& et.TargetModuleId == searchCriterria.MId && et.BranchCode == searchCriterria.BranchCode
orderby et.EmpCode ascending
select new
{
et.EtId,
et.EtYear,
et.EtMonth,
et.EtTargetValue,
et.TargetModuleId,
et.BranchCode,
b.BranchName,
et.EmpCode,
e.EmpSaleCode,
e.EmpName,
e.PostName
};
var result = query.ToList().ConvertAll<EmployeeTarget>(item => new EmployeeTarget()
{
EtId = item.EtId,
EtYear = item.EtYear,
EtMonth = item.EtMonth,
EtTargetValue = item.EtTargetValue,
TargetModuleId = item.TargetModuleId,
BranchCode = item.BranchCode,
BranchName = item.BranchName,
EmpCode = item.EmpCode,
EmpSaleCode = item.EmpSaleCode,
EmpName = item.EmpName,
PostName = item.PostName
});