I have a list of items that can be represented like this:
ClientNo Name Date Time
0001 Mike 01/12/2000 6
0002 Dave 01/12/2000 12
0001 Mike 01/12/2000 10
0002 Dave 02/12/2000 6
Is it possible to group and aggregate this to look something like this using LINQ?
ClientNo Name Date Time
0001 Mike 01/12/2000 16
0002 Dave 01/12/2000 12
0002 Dave 02/12/2000 6
I am trying to return an aggregate row for each client for a particular date. I have been fiddling with the following but have not been able to get it right. Unfortunately my knowledge of LINQ is quite poor.
var result = from p in ListofModel
group p by new { p.ClientNo, p.Date, p.Name, p.Time } into g
orderby g.key.Date
select new ModelClass
{
ClientNo = g.Key.ClientNo,
Name = g.key.Name,
.....
}
Not surprisingly this does not give me the results I would like. How can it be fixed?
I think it should look like this:
You don’t want to group by the time, so it should not be included in the group key.