简体   繁体   English

使用Join在LINQ查询中进行分组和求和

[英]Group By and Sum In LINQ query with Join

I have a query in C# and i need to group by this query for c.Same_invoice and sum the column price in the row grouped. 我在C#中有一个查询,我需要按此查询对c.Same_invoice进行分组,并对汇总的行中的列价格求和。

I know how to do group by and sum but i don't know the solution for my case, with a join and a large amount of data. 我知道如何进行分组和求和,但是我不知道针对我的案例的解决方案,因为它具有联接和大量数据。

The actual code is: 实际的代码是:

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
            };

Thank to all 谢谢大家

You can use something like: 您可以使用类似:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM