Linq with group by having count

你离开我真会死。 提交于 2019-11-26 02:37:13

问题


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

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

回答1:


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);



回答2:


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


来源:https://stackoverflow.com/questions/2078736/linq-with-group-by-having-count

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!