SQL 到 Lambda 的存储过程
SQL stored procedure to Lambda
我一直在开发一个小项目,但无法将 sql 存储过程转换为 lambda。我的项目首先是 C# MVC 代码。我查看了这里的一些帖子,但没有成功。
第一个版本是 Total 是四舍五入的分钟数(每分钟),第二个版本只是将所有秒数转换为分钟数:
每分钟向上取整:
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,'?')
我乐于接受建议,并希望有一些解决方案的想法。
提前感谢您的帮助。
您可以使用 lambda 执行此操作,方法是对类型进行分组,然后对每条记录进行求和和舍入,从而获得各个舍入记录的总和。
假设您想对每个记录的持续时间进行四舍五入,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()})
我一直在开发一个小项目,但无法将 sql 存储过程转换为 lambda。我的项目首先是 C# MVC 代码。我查看了这里的一些帖子,但没有成功。
第一个版本是 Total 是四舍五入的分钟数(每分钟),第二个版本只是将所有秒数转换为分钟数: 每分钟向上取整:
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,'?')
我乐于接受建议,并希望有一些解决方案的想法。
提前感谢您的帮助。
您可以使用 lambda 执行此操作,方法是对类型进行分组,然后对每条记录进行求和和舍入,从而获得各个舍入记录的总和。
假设您想对每个记录的持续时间进行四舍五入,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()})