我有这个查询:
from e in Employee
join t in TimeTable
on e.Id equals t.EmpId
group new {e,t} by e.Id into g
orderby g.Key
select new
{
Emp = g.Key,
Items = g.Select(c => c.t.OtherTable.Somevalue).Distinct()
}
它工作正常,但我需要反转分组,以便将 OtherTable.Somevalue
上的所有 Employees
分组
我该怎么做?
最佳答案
可能喜欢遵循这个它会起作用
from e in Employee
join t in TimeTable
on e.Id equals t.EmpId
group new {e,t} by t.OtherTable.Somevalue into g
orderby g.Key
select new
{
SomeValue = g.Key,
Emplyees = g.Select(c => c.e.Id).Distinct()
}
关于c# - Linq反向GroupBy,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15272867/