SQL存储了lambda的程序



我一直在开发一个小型项目,并且很难将SQL存储过程绕到lambda中。我的项目首先是C#MVC代码。我在这里调查了一些帖子,但没有成功。

第一个版本是总数为分钟(每分钟),第二个版本仅将所有秒转换为分钟:每分钟四舍五入:

    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将与之接近:

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()})

相关内容

  • 没有找到相关文章

最新更新