Linq与组通过计数


Answers:


285

像这样:

from c in db.Company
group c by c.Name into grp
where grp.Count() > 1
select grp.Key

或者,使用方法语法:

Company
    .GroupBy(c => c.Name)
    .Where(grp => grp.Count() > 1)
    .Select(grp => grp.Key);

18
感谢您提供两种形式的语法!:D
Jess 2015年

感谢您的解决方案
sudhanshu Pal

6

对于希望在vb中执行此操作的任何人(就像我过去一样,也找不到任何东西)

From c In db.Company 
Select c.Name Group By Name Into Group 
Where Group.Count > 1

1
我发现很难理解为什么在VB中Group BySelect子句之后。
Arvin

-1

以下解决方案可能会为您提供帮助。

var unmanagedDownloadcountwithfilter = from count in unmanagedDownloadCount.Where(d =>d.downloaddate >= startDate && d.downloaddate <= endDate)
group count by count.unmanagedassetregistryid into grouped
where grouped.Count() > request.Download
select new
{
   UnmanagedAssetRegistryID = grouped.Key,
   Count = grouped.Count()
};

这与问题有什么关系?
Gert Arnold
By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.