我寫在LINQ寫這個SQL查詢,但沒有工作..如何在SQL查詢轉換爲LINQ與ORDERBY,GROUPBY
select [ProcessTime], Count([ID]) as 'amount of processes'
from [DB].[dbo].[TableX]
where [ID] in ('ServerX', 'ServerY') and [Type] ='Complete'
group by [ProcessTime]
order by [ProcessTime]
我想實現這個LINQ &什麼我都試過了,我將查詢分爲兩個,一個用於處理時間group by子句和另一計數ID的
var query1 = (from a in this.db.Processes
where (a.ID =='ServerX' || a.ID =='ServerY') && a.Type =='Complete'
group a by a.ProcessTime into b
//here I dont know where to place orderby
select b);
var query2 = (from a in this.db.Processes
where (a.ID =='ServerX' || a.ID =='ServerY') && a.Type =='Complete'
orderby a.ProcessTime
select a).Count();
這是對查詢分成兩個正確的方式再後來將它們結合起來?
請仔細閱讀http://meta.stackexchange.com/questions/10647/how-do-i -write-a-good-title – 2013-04-30 06:36:48