How to use LINQ to get multiple totals

Viewed 73

Let's say I have the following data in a database.

class Data
{
    public int Category { get; set; }
    public int ValueA { get; set; }
    public int ValueB { get; set; }
}

How can I write a LINQ query to get the sum of ValueA and also the sum of ValueB for all rows with Category == 1?

I know I could load all the data and then use Sum on the loaded data but would prefer to total them in the database.

I know I can use group by but I'm not grouping by anything. I just want these two totals from the data.

2 Answers
Related