【问题标题】:how to use group by LINQ [duplicate]如何通过LINQ使用组[重复]
【发布时间】:2016-08-02 11:01:41
【问题描述】:

我需要在每个员工人数(人数)中显示公司名称。

var result2 = (from c in NoOfEntities.listOfCompanies
               join s in NoOfEntities.listOfStores on c.Id equals s.CompanyId
               join p in NoOfEntities.listOfPersons on s.Id equals p.StoreId
               group c by c.Name into newGroup
               select newGroup );

我需要添加员工人数,但我不知道如何添加该计数器。

【问题讨论】:

    标签: c# .net linq


    【解决方案1】:
    var result2 = (from c in NoOfEntities.listOfCompanies
                    join s in NoOfEntities.listOfStores on c.Id equals s.CompanyId
                    join p in NoOfEntities.listOfPersons on s.Id equals p.StoreId
                    group p by c.Name into newGroup
                    select new
                    {
                        CompanyName = newGroup.Key,
                        NumberOfEmployees = newGroup.Count()
                    });
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2010-10-08
      • 1970-01-01
      • 1970-01-01
      • 2011-12-16
      相关资源
      最近更新 更多