linq get sum of two columns in one query
Posted
by Axarydax
on Stack Overflow
See other posts from Stack Overflow
or by Axarydax
Published on 2010-03-12T11:15:21Z
Indexed on
2010/03/12
11:17 UTC
Read the original article
Hit count: 407
Hi, let's say that I have a table called Items (ID int, Done int, Total int)
I can do it by two queries:
int total = m.Items.Sum(p=>p.Total)
int done = m.Items.Sum(p=>p.Done)
But I'd like to do it in one query, something like this:
var x = from p in m.Items select new { Sum(p.Total), Sum(p.Done)};
Surely there is a way to call aggregate functions from LINQ syntax...?
© Stack Overflow or respective owner