C# Linq反向分组
我有一个疑问:C# Linq反向分组,c#,linq,lambda,grouping,C#,Linq,Lambda,Grouping,我有一个疑问: 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() } 它工作正常,但我需要反转分组,以便将所有员工分组到其他表中。Some
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()
}
它工作正常,但我需要反转分组,以便将所有员工分组到其他表中。Somevalue
我该怎么做呢?可能希望遵循此操作,它会起作用
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()
}
先生,你是个天才,谢谢你。我对select
进行了一些编辑,以使其正常工作,但您的解决方案仍然非常聪明。感谢you@JensKloster-请记住在你们有能力的时候接受答案。@JensKloster-几分钟后,点击投票表下方的右键,你们就可以接受答案了。。