2016-11-28 72 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()})