Linq-2-SQL左外部联接在C#中 [英] Linq-2-SQL Left Outer Join in C#
本文介绍了Linq-2-SQL左外部联接在C#中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
此SQL查询的linq-2-sql语法是什么?
What would be the linq-2-sql syntax for this SQL Query:
SELECT emp.id, Name, Count(t.id) as CNT
FROM employee emp
LEFT JOIN taskAssignment t
on emp.id = t.FKEmployeeID GROUP BY emp.id, Name
表是这样的:
推荐答案
这是答案
var lst = from emp in Employeetables
join task in TaskAssignmentTables
on emp.EmployeeId equals task.FKEmployeeId into j
from result in j.DefaultIfEmpty()
group result by new { emp.EmployeeId, emp.Name } into groupResult
select new
{
EmployeeId = groupResult.Key.EmployeeId,
Name = groupResult.Key.Name,
Count = groupResult.Count(r => r.FKEmployeeId != null)
};
This returns the same answer as your SQL question related to this SQL Left outer join question. I developed this simply using LinqPad
这篇关于Linq-2-SQL左外部联接在C#中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文