【问题标题】:How to Select All Documents of a Type in RavenDB如何在 RavenDB 中选择一个类型的所有文档
【发布时间】:2010-09-28 13:47:29
【问题描述】:

到目前为止,我已经尝试了以下方法:

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。我意识到这通常不是获取数据的最佳方法。

【问题讨论】:

    标签: c# ravendb


    【解决方案1】:

    是的

    使用 DocumentsByName 查询 - 据我所知,目前在客户端界面中这并不直观,但看起来像这样:

    documentSession.LuceneQuery<ImageDocument>("Raven/DocumentsByEntityName")
                     .Where("Tag:Widgets")
                     .Take(100)
                     .ToArray();
    

    如果您有时了解 HTTP API 会有所帮助:)

    注意:请注意它的复数形式,这是一种约定,可以被覆盖。

    注意:在不稳定的分叉中(所以可能很快就会稳定,上面可以很容易地实现

    documentSession.Query<ImageDocument>().Take(100).ToArray()
    

    更好

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-04-12
      • 1970-01-01
      相关资源
      最近更新 更多