163

how do I write this query in linq (vb.net)?

 select B.Name
 from Company B
 group by B.Name
 having COUNT(1) > 1
Fernando
  • 2,033
  • 4
  • 17
  • 20

3 Answers3

347

Like this:

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

Or, using the method syntax:

Company
    .GroupBy(c => c.Name)
    .Where(grp => grp.Count() > 1)
    .Select(grp => grp.Key);
Thomas Levesque
  • 278,830
  • 63
  • 599
  • 738
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
Michael Andrews
  • 194
  • 6
  • 16
-2

Below solution may help you.

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()
};
matthias_h
  • 11,260
  • 9
  • 20
  • 39
Sudhanshu Pal
  • 76
  • 2
  • 12