题
到目前为止,我已经试过如下:
public class Widget
{
public int Id;
public string Name;
}
public static class Main
{
public static void Main()
{
// Initialize store and preload with widgets...
using (var session = store.OpenSession())
{
var widgets = session.Load<Widget>();
foreach(var widget in widgets)
{
Console.WriteLine(widget.Name);
}
}
}
}
我已经能够通过添加一个索引,然后使用该索引作为查询加载所有:
var store = new DocumentStore();
store.DatabaseCommands.PutIndex("AllWidgets", new IndexDefinition<Widget>
{
Map = widget => from widget in widgets
select new { widget }
});
// Back in Main
var widgets = session.Query<Widget>("AllWidgets");
// Do stuff with widgets.
有没有办法只得到类型Widget
的所有文档,而无需创建一个索引?
在这一点上,我只是打RavenDB在沙箱环境。我认识到,这通常是不获取数据的最佳方法。
解决方案
是
使用DocumentsByName查询 - 这是据我可以工作了是不是在此刻的客户端界面直观,但看起来是这样的:
documentSession.LuceneQuery<ImageDocument>("Raven/DocumentsByEntityName")
.Where("Tag:Widgets")
.Take(100)
.ToArray();
有帮助,如果你知道HTTP API有时:)
注:注意它是如何pluralises对你来说,这是一个惯例,可以覆盖
注意:在不稳定的叉(因此可能是稳定不久,上面可以很容易地与实现
documentSession.Query<ImageDocument>().Take(100).ToArray()
的效果好很多
不隶属于 StackOverflow