c# - Linq反向GroupBy

标签 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()
}

它工作正常,但我需要反转分组,以便将 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/

相关文章:

c# - 为什么列表框模板中的绑定(bind)命令无法运行?

c# - 如果形状的高度大于表单的高度,则显示滚动条

c# - 为什么不处理 MemoryStream?

c# - 将 BitArray 转换为 UInt32 C#

c# - 带有两个可为空的日期列的 Linq OrderByDescending

c# - 如何使用 System.Linq.Dynamic.Core 将复杂的查询字符串转换为 lambda 表达式

c# - LINQ 到 Azure 搜索

c# - LINQ 到实体 : Orderby statement involving extension method

c++ - 临时对象上的 std::transform

lambda - Scheme 中的 Y 组合器,使用惰性求值?