Skip to main content

Include Time Series With Query

You can include time series data while retrieving a document via session.Query.

session.Query and IncludeTimeSeries

To include time series data via session.Query, use session.Query with the Include LINQ expression and pass it the IncludeTimeSeries method of the IQueryIncludeBuilder interface as an argument.

Syntax

  • IncludeTimeSeries
    • Definition
TBuilder IncludeTimeSeries(string name, DateTime? from = null, DateTime? to = null);
  • Parameters

    ParametersTypeDescription
    namestringTime series Name
    fromDateTime?Time series range start
    toDateTime?Time series range end

Usage Flow

  • Open a session
  • Call session.Query with the Include Linq expression
    Pass it the IncludeTimeSeries method as an argument
  • Pass IncludeTimeSeries its arguments:
    • Time series name
    • Range start
    • Range end

Usage Sample

In this sample, we retrieve a document using session.Query and include entries from the time series "Heartrate".

using (var session = store.OpenSession())
{
// Query for a document and include a whole time-series
User user = session.Query<User>()
.Where(u => u.Name == "John")
.Include(includeBuilder => includeBuilder.IncludeTimeSeries("HeartRates"))
.FirstOrDefault();

// The following call to 'Get' will Not trigger a server request,
// the entries will be retrieved from the session's cache.
IEnumerable<TimeSeriesEntry> val = session.TimeSeriesFor(user, "HeartRates")
.Get();
}

The entries we Get after including the time series, are retrieved from the session's cache.