Click here to Skip to main content
15,867,686 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Select id from table person where per=123 group by a,b having count(*)=max(d)

Myentity.Person.where(x=>x.per=123).GroupBy(x=>new {x.a,x.b})

What I have tried:

How to lambda expression this query.
Posted
Updated 27-May-20 23:11pm

 
Share this answer
 
Comments
Maciej Los 28-May-20 5:11am    
5ed!
Try:
C#
var result = Myentity.Person
    .Where(x=>x.per==123)
    .GroupBy(x=>new {x.a, x.b})
    .Select(grp=> grp.OrderByDescending(x=> x.d).First())
    .ToList();
 
Share this answer
 
v2
Comments
Richard MacCutchan 28-May-20 5:50am    
5ed for a proper solution.
Maciej Los 28-May-20 5:54am    
Thank you, Richard.
Member 14169626 28-May-20 6:21am    
Thank you
Maciej Los 28-May-20 6:33am    
You're very welcome.
George Swan 29-May-20 1:39am    
Shouldn't the 'Where' clause be x=>x.per==123?

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