Click here to Skip to main content
15,888,273 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I want to convert this sql query to Linq C#...Please Help me.. and thanks
SQL
SELECT p.CodGestion
FROM tabla p
GROUP BY p.CodGestion
HAVING COUNT(*) =
        ( SELECT MAX(contador) max_contador
                FROM ( SELECT pro.CodGestion, COUNT(*) contador
                            FROM tabla pro GROUP BY pro.CodGestion
) T);
Posted
Updated 26-Feb-15 10:40am
v3
Comments
Maciej Los 26-Feb-15 16:58pm    
What an ugly query!

1 solution

Some ideas you'll find here:
Take result with max count using LINQ[^]
Return List with Maximum Count using Linq[^]
How to get the Max() of a Count() with LINQ[^]

The simplest way is to use query as is shown below:
C#
var qry = tabla.OrderByDescending(x=>x.Count()).Select(x=>x.CodeGestion);
 
Share this answer
 
Comments
shopishepa02 27-Feb-15 11:12am    
Thanks for your response, but I am not able to use x.Count()
I mean, Count() doesnt appear in the list

tabla is a reference of database table.
Maciej Los 27-Feb-15 12:49pm    
Follow the links i provided ;)

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900