具有加入

时间:2016-09-07 08:12:15

标签: c# linq

我在C#中有一个查询,我需要通过此查询对c.Same_invoice进行分组,并对分组行中的列价进行求和。

我知道怎么做分组和总和,但我不知道我的情况的解决方案,有一个连接和大量的数据。

实际代码是:

var query = from c in snd.external_invoices.OrderByDescending(x => x.date)
            join o in snd.invoices on c.idexternal_invoices equals o.id_external_invoice
            select new{
               c.idexternal_invoices,
               c.businessname,
               o.number,
               c.message,
               c.price,
               c.date,
               c.iduser
            };

感谢所有

1 个答案:

答案 0 :(得分:2)

您可以使用以下内容:

var query = from c in snd.external_invoices.OrderByDescending(x => x.date)
            join o in snd.invoices on c.idexternal_invoices equals o.id_external_invoice into grouped
            select new{
               Invoice =grouped.key, Price = grouped.Sum(x => x.Price)};