Query to sum on grouped field

391 Views Asked by At

I've a list of tasks. Ie I've struct like

struct Task
{
    public DateTime Completed { get; set; }
    public string TaskKind { get; set; }
    public float Effort { get; set; }
}

And I've a IList<Task>.

Now I want to group the tasks based on the date and group by TaskKind on each day with the summed effort. For eg for I want to print like the below:

01-09-09     Design:10     Coding:5    Coordination:15
02-09-09     Coding:5       Meeting:2

Can anyone help me in constructing a LINQ query to achieve this?

1

There are 1 best solutions below

0
On BEST ANSWER

This is a combination of a simple aggregate (COUNT by TaskKind) and a PIVOT. Take a look at this question: Is it possible to Pivot data using LINQ?