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.


  • IncludeTimeSeries

    • Definition

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

      Parameters Type Description
      name string Time series Name
      from DateTime? Time series range start
      to DateTime? 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".

// Query for a document and include a whole time-series
using (var session = store.OpenSession())
    var baseline = DateTime.Today;

    IRavenQueryable<User> query = session.Query<User>()
        .Where(u => u.Name == "John")
        .Include(includeBuilder => includeBuilder.IncludeTimeSeries(
            "HeartRates", DateTime.MinValue, DateTime.MaxValue));

    var result = query.ToList();

    IEnumerable<TimeSeriesEntry> val = session.TimeSeriesFor(result[0], "HeartRates")
        .Get(DateTime.MinValue, DateTime.MaxValue);

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