Linq Adding a Sum or Count field

Posts   
 
    
smurrell
User
Posts: 59
Joined: 22-Feb-2007
# Posted on: 22-Oct-2020 09:16:42   

Hello

I trust this message finds everyone well. I have an example Linq query. How do I add a SUM or COUNT field to a linq query?

                    q = from u in metaData.Customers
                         join x in metaData.Orders
                         on u.CustomersId equals x.CustomersId 
                         orderby u.Name

Regards, Simon

Walaa avatar
Walaa
Support Team
Posts: 14993
Joined: 21-Aug-2005
# Posted on: 22-Oct-2020 20:18:01   

You need to Group By to use add an Aggregate to the select list, right?

Here is an example of a Group By from the documentation

And since this is not an LLBLGen specific construct, you can find many examples and tutorials on using LinQ on the internet.