如何在Linq(VB.NET)中编写此查询?
select B.Name
from Company B
group by B.Name
having COUNT(1) > 1
像这样:
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);
如果有人想在VB中实现这个功能(就像我一样并且找不到任何东西),可以参考以下方法:
From c In db.Company
Select c.Name Group By Name Into Group
Where Group.Count > 1
Group By
在Select
子句之后。 - Arvinvar 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()
};