I have a Measurements table as follows:
SourceId : int
TimeStamp: date/time
Measurement: int
Sample data looks like this (more on the asterisks below):
SID| TimeStamp | Measurement
10 | 02-01-2011 12:00:00 | 30 *
10 | 02-01-2011 12:10:00 | 30
10 | 02-01-2011 12:17:00 | 32 *
10 | 02-01-2011 12:29:00 | 30 *
10 | 02-01-2011 12:34:00 | 30
10 | 02-01-2011 12:39:00 | 35 *
10 | 02-01-2011 12:46:00 | 36 *
10 | 02-01-2011 12:39:00 | 36
10 | 02-01-2011 12:54:00 | 36
11 | 02-01-2011 12:00:00 | 36 *
11 | 02-01-2011 12:10:00 | 36
11 | 02-01-2011 12:17:00 | 37 *
11 | 02-01-2011 12:29:00 | 38 *
11 | 02-01-2011 12:34:00 | 38
11 | 02-01-2011 12:39:00 | 37 *
11 | 02-01-2011 12:46:00 | 36 *
11 | 02-01-2011 12:39:00 | 36
11 | 02-01-2011 12:54:00 | 36
I need a LINQ query that will return only the rows when the Measurement value is different from the prior row having the same SourceId (i.e. each row marked with an asterisk). The table should be sorted by SourceId, then TimeStamp.
The data from the query will be used to plot a graph where each SourceId is a series. The source table has several million rows and the repeating measurements are in the thousands. Since these repeating measurement values don’t make any difference to the resulting graph I’d like to eliminate them before passing the data to my graph control for rendering.
I have tried using Distinct() in various ways, and reviewed the Aggregate queries here http://msdn.microsoft.com/en-us/vcsharp/aa336746 but don’t see an obvious solution.
Sometimes a plain old foreach loop will suffice.