Include Time Series with Load


  • When loading a document via session.Load,
    you can include all entries of a time series or a specific range of entries.

  • The included time series data is stored within the session
    and can be provided instantly when requested without any additional server calls.

  • In this page:


Include time series when loading a document

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

using (var session = store.OpenSession())
{
    var baseline = DateTime.Today;

    // Load a document
    User user = session.Load<User>("users/john", includeBuilder =>
        // Call 'IncludeTimeSeries' to include time series entries, pass:
        // * The time series name
        // * Start and end timestamps indicating the range of entries to include
        includeBuilder.IncludeTimeSeries("HeartRates", baseline.AddMinutes(3), baseline.AddMinutes(8)));

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

Syntax

session.Load

T Load<T>(string id, Action<IIncludeBuilder<T>> includes);
Parameter Type Description
id string Document ID
includes Action<IIncludeBuilder<T>> Include Object

Include builder methods:

TBuilder IncludeTimeSeries(string name, DateTime? from = null, DateTime? to = null);
Parameter Type Description
name string Time series name.
from DateTime? Time series range start (inclusive).
Default: DateTime.MinValue.
to DateTime? Time series range end (inclusive).
Default: DateTime.MaxValue.