I'm trying to build what's essentially a specialized timeclock. Last piece of the puzzle is, once I've extracted a list of timeclock "events" by employee to sum the differences between events. It's this last part that's not working... I always wind up with a result of 0. Here's what I've tried so far:
var worked =
from workDays in dc.Events
where
workDays.Time >= PayPeriodStartPicker.SelectedDate &&
workDays.Time <= PayPeriodEndPicker.SelectedDate
orderby workDays.Time
select workDays;
TimeSpan totalTime = new TimeSpan();
for (int i = 0; i < worked.ToList().Count - 1; i++)
{
totalTime.Add(worked.ToList()[i + 1].Time - worked.ToList()[i].Time);
}
I've never worked with timespans so probably something very stupid but...
ToList(), you're creating a new copy of the list. If you wantworkedas aList, then you can callToListon the original result:var worked = (<insertQueryHere>).ToList();