查询
var grpby4 = from u in dtEmp.AsEnumerable()
join v in dtDept.AsEnumerable() on u.Field<int>("DepartmentID") equals v.Field<int>("DepartmentID")
group u by v.Field<string>("DeptName") into g
select new { DeptName = g.Key, Records = g };
如何使用Lambda Expression编写相同的查询?
答案 0 :(得分:2)
dtEmp.AsEnumerable()
.Join(dtDept.AsEnumerable(),
u => u.Field<int>("DepartmentID"),
v => v.Field<int>("DepartmentID"),
(u, v) => new { u, v })
.GroupBy(τ0 => τ0.v.Field<string>("DeptName"), τ0 => τ0.u)
.Select(g => new { DeptName = g.Key, Records = g })