How can I subsample data from a time series with LINQ to SQL?

Posted by Chris Farmer on Stack Overflow See other posts from Stack Overflow or by Chris Farmer
Published on 2010-04-09T16:21:50Z Indexed on 2010/04/09 16:23 UTC
Read the original article Hit count: 347

Filed under:
|

I have a database table full of time points and experimental values at those time points. I need to retrieve the values for an experiment and create a thumbnail image showing an XY plot of its data. Because the actual data set for each experiment is potentially 100,000 data points and my image is only 100 pixels wide, I want to sample the data before creating the image.

My current query (which retrieves all the data without sampling) is something simple like this:

var points = from p in db.DataPoints
             where p.ExperimentId == myExperimentId
             orderby p.Time
             select new {
                            X = p.Time,
                            Y = p.Value
                        }

So, how can I best take every nth point from my result set in a LINQ to SQL query?

© Stack Overflow or respective owner

Related posts about linq-to-sql

Related posts about c#