Click here to Skip to main content
15,887,485 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
SQL
Select Top 10 Component, SUM([Down Time (Down day)])
from CMMS 
Where Unit = '{0}' 
and Section = '{1}' 
Group By Component 
Order By SUM([Down Time (Down day)]) 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:

SQL
Select Top 10 Component, SUM([Down Time (Down day)])
from CMMS 
Where Unit = '{0}' 
and Section = '{1}' 
Group By Component 
Order By SUM([Down Time (Down day)]) DESC




hello dear all programming
how to write Equivalent to the above codes in linq&lambda?
please help me
regards yarian
Posted
Updated 13-Dec-16 22:28pm
v3

I should make you aware of apps like Linqer | SQL to LINQ converter[^] before I continue. These types of app translate sql to linq syntax.

Here's what I got for lamda:

C#
var results = db.CMMS
    .Where(c=>c.Unit == prop1 && c.Section == prop2)
    .GroupBy(c=>c.Component)
    .Select(g=>new {Component = g.Key, DownTime = g.Sum(c=>c.DownTimeDownDay})
    .Take(10)


Please note :
The var result is an ienumerable of an anonymous type
I assumed the property names as if you had used LinqToSql to link to the database

I hope that helps ^_^
 
Share this answer
 

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