Click here to Skip to main content
15,881,424 members
Please Sign up or sign in to vote.
1.00/5 (3 votes)
Select IdSystem, Count(*)
from [DBTurboRAM-TT].[dbo].[TblCMMS]
Where
IdUnit = 10 and IdSection = 5 Group By IdSystem Order By Count(*) DESC

hello dear all programming
how to write Equivalent to the above codes in linq&lambda?
please help me
regards yarian

What I have tried:

Select IdSystem, Count(*)
from [DBTurboRAM-TT].[dbo].[TblCMMS]
Where
IdUnit = 10 and IdSection = 5 Group By IdSystem Order By Count(*) DESC

hello dear all programming
how to write Equivalent to the above codes in linq&lambda?
please help me
regards yarian
Posted
Updated 11-Dec-16 18:32pm
Comments
dan!sh 12-Dec-16 0:30am    
People here are volunteers. You can't expect them to do your work. Please try doing the task yourself and comeback with specific questions.
Jon McKee 12-Dec-16 0:33am    
Lol, I was bored =S Also I see a lot of groupby/orderby confusion with a computed value like a count and all that so it may be useful to have an example laying around I suppose.
dan!sh 14-Dec-16 2:01am    
Still bored? OP posted another question with same "request".
Jon McKee 14-Dec-16 9:54am    
Everything he needs is already right here. The only thing new would be Sum() and Take(). I'll let him figure that one out on his own =)

1 solution

C#
var query = from row in table
            where row.IdUnit == 10 && row.IdSection == 5
            group row by row.IdSystem into rowGroup
            let count = rowGroup.Count()
            orderby count descending
            select new { IdSystem = rowGroup.Key, Count = count };


Replace table with whatever you're using to access the database =)
 
Share this answer
 
v2

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