Stephen Patten
Stephen Patten

Reputation: 6363

How to accomplish this query with RavenDb?

I'm wondering what's the best approach for getting back the total number of records for a search, and at the same time, get back the Nth 128 record block segment of data which seems to be the cap imposed by RavenDb run-time.

For instance given this query, I also need to know the total number of records.

var bookmarks = session.Query<Bookmark>()
  .OrderByDescending(i => i.DateCreated)
  .Skip(pageCount * (pageNumber – 1))
  .Take(pageCount)
  .ToList();

Thank you, Stephen

Upvotes: 4

Views: 173

Answers (1)

Daniel Lang
Daniel Lang

Reputation: 6839

RavenQueryStatistics stats;
var bookmarks = session.Query<Bookmark>()
  .OrderByDescending(i => i.DateCreated)
  .Skip(pageCount * (pageNumber – 1))
  .Take(pageCount)
  .Statistics(out stats)
  .ToList();

int bookmarksFound = stats.TotalResults;

Upvotes: 7

Related Questions