Linq与分组和总和 [英] Linq with Grouping And Sum

查看:54
本文介绍了Linq与分组和总和的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图用以下查询对数据进行分组。但它没有任何组合。我缺少什么?



Hi, I was trying to group my data with the following query. But it does not group anything. What I am missing?

var myList= (from t1 in liste
             group t1 by t1.ApprovalDate into x
             select new Invoice
             {
                CustomerID = x.FirstOrDefault().CustomerID,
                CustomerName = x.FirstOrDefault().CustomerName,
                CustomerSurname = x.FirstOrDefault().CustomerSurname,
                ApprovalDate  = x.FirstOrDefault().ApprovalDate,
                Total = x.Sum(t => t.Total)
              }
              ).ToList();

推荐答案

ApprovalDate =l.ApprovalDate.Date





我解决了DateTime with Time导致不按日期分组。分裂时间解决了我的问题。谢谢。



I solved DateTime with Time causes not to group by date. Splitting the time solved my problem. Thank you.


这篇关于Linq与分组和总和的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆