2016-11-28 31 views
0

我一直在開發一個小項目,並且無法將sql存儲過程轉換爲lambda。我的項目是C#MVC代碼。我已經看過這裏的一些帖子,但沒有成功。SQL存儲過程到Lambda

第一個版本,其中總的是向上舍入(爲每分鐘)分鐘和第二隻是轉換成分所有秒: 四捨五入每分鐘:

select ISNULL(noT,'?') as NType,count(*) as TotalCount,SUM((Duration + 59)/60) as TotalMinutes 
    from cHis 
    where hDate between @fromDate AND @toDate And Customer_CustomerID = @CustomerID and I_ID = @I_ID 
    group by ISNULL(noT,'?') 

總四捨五入成分:

select ISNULL(noT,'?') as NType,count(*) as TotalCount,SUM((Duration)/60) as TotalMinutes 
    from cHis 
    where hDate between @fromDate AND @toDate And Customer_CustomerID = @CustomerID and I_ID = @I_ID 
    group by ISNULL(noT,'?') 

我很樂意提供建議,希望有解決方案的一些想法。

感謝您提前給予幫助。

回答

0

您可以使用lambda通過對類型進行分組然後對每條記錄進行求和和舍入來獲得單個舍入記錄的總和。

假設你想圓了各自的記錄持續時間,拉姆達將是這個東西接近:

cHis.Where(c=>c.Date > StartDate && c.Date< EndDate && Customer_CustomerID == CustomerId && I_ID == ID) 
.Select(c=>new {Type = (c.noT != null), c.Duration}) 
.GroupBy(c=>c.Type).ToList() 
.Select(c=> new {Type = c.Key, TotalDuration = c.Sum(d=>Math.Ceiling((decimal)d.Duration/60)), Count = c.Count()})