sql语句w / case和左外连接到linq语句 [英] sql statement w/case and left outer join into linq statement
问题描述
任何人都可以帮我将这个sql语句转换为linq语句吗?如何在LINQ中实现多个左外连接和多个案例?
选择(A.EmployeeCommonMetric_Id不为空时的情况,然后当A.EmployeeSBU_Id不为空时ECM.Employee_Id然后ES.Employee_Id > else 0 end)作为'Employee_Id',
(当A.EmployeeCommonMetric_Id不为空时的情况(CME.Employee_FirstName +''+ CME.Employee_LastName)
当A.EmployeeSBU_Id不为空时(SE) .Employee_FirstName +''+ SE.Employee_LastName)else''end)作为'Evaluee'的名字',(当A.EmployeeSBU_Id不为空时的情况,然后S.SBU_Code否则'Common Metrics'结束)As' SBU',
A.Approver_Id,E.Employee_FirstName +''+ E.Employee_LastName As'Acverver Name',A.Approved_Date
来自Approvals A
内部联接员工E在A.Approver_Id = E.Employee_Id左外连接EmployeeCommonMetrics ECM on A.EmployeeCommonMetric_Id = ECM.EmployeeCommonMetric_Id左外连接EmployeeSBUs ES on A.EmployeeSBU_Id = ES.EmployeeSBU_Id
左外连接雇员CME在ECM.Employee_Id = CME.Employee_Id左左外连接员工SE在ES.Employee_Id = SE.Employee_Id左左外连接SBU S在ES.SBU_Id = S.SBU_Id
其中A.Approval_Deleted = 0
感谢高级
此链接可以帮助您 -
http://lancefisher.net/blog/archive/ 2008/05/07 / linq-to-sql --- case-statements.aspx
对于左外连接,如果这对您有帮助,请使用此示例 -
http://www.jeffblankenburg.com/2008/04/left-outer-加入合linq.aspx
Hi,
Can anyone help me convert this sql statement to a linq statement? How do you implement multiple left outer join and multiple case in LINQ?
Select (case when A.EmployeeCommonMetric_Id Is Not Null then ECM.Employee_Id when A.EmployeeSBU_Id Is Not Null then ES.Employee_Id
else 0 end) As 'Employee_Id',
(case when A.EmployeeCommonMetric_Id Is Not Null then (CME.Employee_FirstName + ' ' + CME.Employee_LastName)
when A.EmployeeSBU_Id Is Not Null then (SE.Employee_FirstName + ' ' + SE.Employee_LastName) else '' end) As 'Evaluee''s Name',
(case when A.EmployeeSBU_Id Is Not Null then S.SBU_Code else 'Common Metrics' end) As 'SBU',
A.Approver_Id, E.Employee_FirstName + ' ' + E.Employee_LastName As 'Approver Name' , A.Approved_Date
From Approvals A
inner join Employees E on A.Approver_Id = E.Employee_Id
left outer join EmployeeCommonMetrics ECM on A.EmployeeCommonMetric_Id = ECM.EmployeeCommonMetric_Id
left outer join EmployeeSBUs ES on A.EmployeeSBU_Id = ES.EmployeeSBU_Id
left outer join Employees CME on ECM.Employee_Id = CME.Employee_Id
left outer join Employees SE on ES.Employee_Id = SE.Employee_Id
left outer join SBUs S on ES.SBU_Id = S.SBU_Id
where A.Approval_Deleted=0
Thanks in Advanced
This link should help you-
http://lancefisher.net/blog/archive/2008/05/07/linq-to-sql---case-statements.aspx
And for left outer join, please use this sample if this helps you -
http://www.jeffblankenburg.com/2008/04/left-outer-join-in-linq.aspx
这篇关于sql语句w / case和左外连接到linq语句的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!