Session: Include Time Series With Load


You can include a time series or a part of it while loading a document via session.Load.


session.Load and IncludeTimeSeries

To include time series data while retrieving documents via session.Load, pass session.Load the IncludeTimeSeries method of the IIncludeBuilder interface as an argument.

Syntax

  • session.Load

    • Definition
      T Load<T>(string id, Action<IIncludeBuilder<T>> includes);
    • Parameters

      Parameters Type Description
      id string Document ID
      includes Action<IIncludeBuilder<T>> Include Object
  • 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
      when null, from will default to DateTime.MinValue.
      to DateTime? Time series range end

      when null, to will default to DateTime.MaxValue.

Usage Flow

  • Open a session
  • Call session.Load and pass it -
    • The Document ID
    • The IncludeTimeSeries method with its arguments:
      Time series name
      Range start
      Range end

Usage Sample

In this sample, we load a document using session.Load and include a selected range of entries from a time series named "Heartrate".

// Load a document and Include a specified range of a time-series
using (var session = store.OpenSession())
{
    var baseline = DateTime.Today;

    User user = session.Load<User>("users/1-A", includeBuilder =>
        includeBuilder.IncludeTimeSeries("HeartRates",
        baseline.AddMinutes(3), baseline.AddMinutes(8)));

    IEnumerable<TimeSeriesEntry> val = session.TimeSeriesFor("users/1-A", "HeartRates")
        .Get(baseline.AddMinutes(3), baseline.AddMinutes(8));
}

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