4

我有一个 Linq 查询

var mdls = (from mdl in query dbSession.Query<MyModel>("MyIndex")
              orderby mdl.Name
              select dept).Skip(page.Value).Take(4);

其中“MyIndex”是 RavenDB 中定义的简单索引。我知道在 RavenDB 中查询索引时,它会返回“TotalResults”。看这里

如何获得具有该TotalResult属性的查询结果?

4

3 回答 3

6

如果你正在执行一个 LuceneQuery,你会得到一个返回的 DocumentQuery,它有一个包含 TotalResults 的 QueryResult 属性,所以你可以按如下方式访问它:

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;

如果您正在执行 LINQ 查询,那么您可以在使用 Skip 和 Take 限制查询之前调用 Count():

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);
于 2010-09-01T09:11:33.440 回答
0

您需要在查询结束时执行类似的操作

.Customize(x => x.TotalResult)

TotalResult 属性仅在 LuceneQuery 上可用,在 LINQ 查询上不可用。

于 2010-08-31T16:47:51.583 回答
0

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") ?

于 2010-09-02T15:28:11.440 回答