【发布时间】:2020-11-21 10:34:01
【问题描述】:
我想显示每个客户进行了多少次转账。
我想显示CustomerId、Name 和Totaly 的转账金额。
我的意思是我也想显示CustomerId,而不仅仅是Name 和Amount 转移。
除CustomerId 外,一切正常:在我的 DataGridview 中它是空的。
我不知道该怎么做,如果能提供任何帮助,我将不胜感激。
这是我的代码:
using (Db db = new Db())
{
var statistic = (from u in db.Transfers
join c in db.Customers on u.CustomerId equals c.CustomerId
where u.IsActive == true && u.Paid == true
group u by c.FirstName into g
select new
{
// here I get Headertext but not Id's value
Id = g.Select(x =>x.CustomerId),
Name = g.Key,
Totaly = g.Sum(x => x.Amount)
}).OrderByDescending(x => x.Totaly).ToList();
if (statistic != null)
{
dgvCustomerList.DataSource = statistic;
}
}
【问题讨论】:
标签: c# winforms linq group-by datagridview