It will be hard to explain but I’ll try
I’ve got a table with some fields, and that table got subtable with rows (I’m not talking about SQL, its DB4O, but I use linq). Rows got timefrom and timeto, example:
maintable:
Description,
CreateDate,
....
mainTableRows:
08:00,
09:00,
some description
Now I need to make a query that will sum hours from rows, like this:
09:00-08:00 = 1hour(first row) + 10:00-09:00 (second row)
and so on.
Something like:
var item = from mainTable m
select new
{
m.Id,
Hours = m.Rows.Sum(c=> new { Hour = c.TimeTo - c.TimeFrom })
}
Thanks all for help, this is mine full solution:
var item = from mainTable m
select new
{
m.Id,
Hours = String.Format("{0:HH:mm}", (new DateTime((p.TimesheetRows.Aggregate(TimeSpan.Zero, (subtotal, t) => subtotal += (t.TimeTo - t.TimeFrom)).Ticks))))
}
If you want the total elapsed time, you can do: