9

我正在使用 RavenDB(在服务器模式下运行 @localhost:3000)和 ASP.NET MVC3

我有这个从 build 289 停止工作的代码段。它之前确实工作过几次,不确定是更新到 322 还是我做了什么。

Session.Query<Post>().ToList().ForEach(Session.Delete);

当我前一阵子尝试时,它正在删除所有帖子(我的示例数据中只有大约 50 个奇怪的帖子,还有 500 多个帖子),我能看到的唯一变化是这两个发生在运行时

A first chance exception of type 'System.Net.WebException' occurred in System.dll
A first chance exception of type 'System.Net.WebException' occurred in Raven.Client.Lightweight.dll

当上面的代码段(Session.Delete)实际运行时,这个日志出现在Visual Studio的输出窗口中

Executing query '' on index 'dynamic/Posts' in 'http://localhost:3000'
Query returned 0/0 results

在 Raven 日志中,(文本文件)没有任何不妥之处

Request #   7: GET     -    46 ms - ZaszStore  - 200 - /indexes/dynamic/Posts?query=&start=0&pageSize=128&aggregation=None

这个查询运行得很好:

Session.Load<Post>("MyPostId")

并获取正确的 Post Instance。

为什么一个简单的 Session.Query().ToList() 总是返回 0 个结果?并且 Session.Query().Count() 总是返回 0。考虑到 Raven DB 的 SilverLight-UI (SL-UI) 清楚地显示 DB 中有 50 多个帖子,什么可能导致这种行为?

“Raven-Entity-Name”已正确填写。

4

1 回答 1

1

对于这种查询,您可以获得所有文档,如下所示:

documentStore.DatabaseCommands.StartsWith("post", <page>, <size>) 

这应该比发出查询以返回所有文档更容易和更有效,因为它直接从数据存储中提取它们,绕过 Lucene 索引。

但是,它仅在您想要获取所有将保存前缀作为其 ID 的文档时才有效。

于 2011-08-02T19:51:19.140 回答