RavenDB paging index
I have a Linq query as
var mdls = (开发者_开发技巧from mdl in query dbSession.Query<MyModel>("MyIndex")
orderby mdl.Name
select dept).Skip(page.Value).Take(4);
Where "MyIndex" is a simple index defined in RavenDB. I know that while querying an Index in RavenDB it returns "TotalResults". See here
How can i get the query result which has the TotalResult
property?
If you are executing a LuceneQuery you get a DocumentQuery returned that has a QueryResult property that contains TotalResults so you can access it as follows:
var documentQuery = (from mdl in query dbSession.LuceneQuery<MyModel>("MyIndex")
orderby mdl.Name
select dept).Skip(page.Value).Take(4);
var totalResults = documentQuery.QueryResult.TotalResults;
If you're executing a LINQ Query instead then you can call Count() on the query before limiting it with Skip and Take:
var linqQuery = (from mdl in query dbSession.Query<MyModel>("MyIndex")
orderby mdl.Name
select dept);
var totalResults = linqQuery.Count();
var pageOfResults = linqQuery.Skip(page.Value).Take(4);
You need to do something like this at the end of your query
.Customize(x => x.TotalResult)
The TotalResult property is only available on the LuceneQuery, not the LINQ Query.
It seems that you can get QueryResult
through session.LuceneQuery<YouModel>("YourIndex")
and not from session.Query<YourModel>("YourIndex")
. But, I wonder why would one use session.Query<YourModel>("YourIndex")
?
精彩评论