Include Time Series with Raw Queries



Include time series when making a raw query

In this example, we use a raw query to retrieve a document
and include entries from the document's "HeartRates" time series.

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

    var from = baseTime;
    var to = baseTime.AddMinutes(5);

    // Define the Raw Query:
    IRawDocumentQuery<User> query = session.Advanced.RawQuery<User>
               // Use 'include timeseries' in the RQL
              ("from Users include timeseries('HeartRates', $from, $to)")
               // Pass optional parameters
              .AddParameter("from", from)
              .AddParameter("to", to);

    // Execute the query:
    // For each document in the query results,
    // the time series entries will be 'loaded' to the session along with the document
    var users = query.ToList();

    // 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[0], "HeartRates")
        .Get(from, to);
}

Syntax

Advanced.RawQuery

IRawDocumentQuery<T> RawQuery<T>(string query);
Parameter Type Description
query string The raw RQL query