Title: Sum and Group By in Linq to SQL?
Tags: vb.net;linq-to-sql
Question: Just getting started with Linq to SQL so forgive the newbie question. I'm trying to reproduce the following (working) query in Linq to SQL (VB.NET):
Select
f.Title,
TotalArea = Sum(c.Area)
From Firms f
Left Join Concessions c on c.FirmID = f.FirmID
Group By f.Title
Order by Sum(c.Area) DESC
(A Firm has many Concessions; a Concession has an area in hectares. I want a list of Firms starting with the ones that have the greatest total area of all their concessions.)
I'm imagining something like this as the Linq to SQL equivalent (pseudo-code)
From f As Firm In Db.Firms _
Order By f.Concessions.Sum(Area)
... but that's not right. Can anyone point me in the right direction?
Comment: I usually don't post meta comments, but 29k views and 7 upvotes? That is sad

Here is the accepted answer: Answer
Here's the correct Linq to SQL equivalent
From c In Concessions _
Join f In Firms on f.FirmID equals c.FirmID _
Group by f.Title _
Into TotalArea = sum(c.OfficialArea)  _
Order by TotalArea Descending _
Select Title, TotalArea
Thanks to @CMS for pointing me to LinqPad - what a great tool. You just point it to your database and you're off and running. Not only are hundreds of samples included, but you can run them against included live databases. I was able to arrive at the above query in just a few minutes starting from the provided samples.
Comment for this answer: Can you provide the C# version of this segment?  I've tried but not successful.

Here is another answer: Here you can find many examples about using aggregate functions and grouping, additionally I recommend you very much LinqPad, it's a great tool to test your queries on the fly and it's very good way to learn LINQ, it comes preloaded with 200 examples.

{'source': 'StackExchangeDataset', 'subset': 'stackoverflow.com', 'metadata': {'AnswerCount': 2, 'CommentCount': 1, 'ContentLicense': 'CC BY-SA 2.5', 'CreationDate': '2008:00:10/19/08', 'FavoriteCount': 6.0, 'PostTypeId': 1, 'Tags': '<vb.net><linq-to-sql>', 'Title': 'Sum and Group By in Linq to SQL?', 'ViewCount': 59452, 'id': 216513, 'user_AboutMe': '<p>Herb is the founder and CTO of DevResults, a web app for managing foreign aid projects. DevResults is intended to make international development, grant-making, humanitarian assistance, and disaster relief programs more effective. It includes tools for monitoring &amp; evaluation, mapping, project management, and collaboration. </p>\n', 'user_AccountId': 86096.0, 'user_DisplayName': 'Herb Caudill', 'user_Reputation': 49993.0, 'user_Views': 2476.0, 'user_id': 239663.0}}