GROUP By and Having count in LinQ

P

Paul

Hi

How can i do this:

SELECT Name, COUNT(*) AS Num
FROM Table1
GROUP BY Name
HAVING COUNT(*)>1

What would be the equivalent:
var lst=from cust in datacontext.customer ....

Any idea?

Thanks
 
G

Gregory A. Beamer

Hi

How can i do this:

SELECT Name, COUNT(*) AS Num
FROM Table1
GROUP BY Name
HAVING COUNT(*)>1

What would be the equivalent:
var lst=from cust in datacontext.customer ....

Any idea?


Don't have the code, but subset the count(*) > 1 and join it to your
main query to filter that way. Grouping is fairly easy.

group x by x into y

for example. This link hits the grouping:
http://msdn.microsoft.com/en-us/vcsharp/aa336754.aspx#simple1

I saw a good workaround for having (to subset) yesterday, but I cannot
find it in my history today ... at least not yet. If I find it, I will
post. I know I found it through a google search, however.

Peace and Grace,


--
Gregory A. Beamer
MVP; MCP: +I, SE, SD, DBA

Twitter: @gbworld
Blog: http://gregorybeamer.spaces.live.com

My vacation and childhood cancer awareness site:
http://www.crazycancertour.com

*******************************************
| Think outside the box! |
*******************************************
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads

Linq to BindingList 1
linq group by month problem 8
Group By In LINQ 2
How do I do this in Linq 3
Anonymous Types, LINQ and Generics 3
Group By multiple fields in LINQ? 1
Linq. Select 1
LINQ Newbie 3

Top