161

如何在 linq (vb.net) 中编写此查询?

 select B.Name
 from Company B
 group by B.Name
 having COUNT(1) > 1
4

3 回答 3

344

像这样:

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);
于 2010-01-16T20:03:56.967 回答
7

For anyone looking to do this in vb (as I was and couldn't find anything)

From c In db.Company 
Select c.Name Group By Name Into Group 
Where Group.Count > 1
于 2015-07-21T22:28:12.510 回答
-2

以下解决方案可能会对您有所帮助。

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()
};
于 2020-04-19T11:11:58.033 回答