【问题标题】:Instantiation of a DocumentDatabase objectDocumentDatabase 对象的实例化
【发布时间】:2012-05-04 18:45:12
【问题描述】:

我想使用 DocumentDatabase 对象。为此,我正在编写以下代码,但它不起作用。它给出 NullReferenceException “对象引用未设置为对象的实例。”请告诉我这样做的正确方法。 代码是:

 Raven.Database.Config.InMemoryRavenConfiguration configure1 =
            new Raven.Database.Config.InMemoryRavenConfiguration 
            { 
                DatabaseName = databaseName,
                Port=8080 ,
                DataDirectory="~/Data"
            };
        DocumentDatabase database1 = new DocumentDatabase(configure1);
        //database1.GetDocuments(0,3,null);

【问题讨论】:

    标签: database ravendb document-database


    【解决方案1】:

    使用EmbeddedDocumentStore,并确保初始化它。然后创建一个会话并使用会话对象来查询嵌入式数据库。

    var documentStore = new EmbeddableDocumentStore
    {
         DataDirectory = "Data"
    }.Initialize();
    
    var session = documentStore.OpenSession();
    

    你可以做到session.Load(id)session.QuerydocumentStore .DatabaseCommands

    【讨论】:

    • 谢谢 FitZchak 但我没有使用 EmbeddedDocumentStore ,我使用的是简单的 DocumentStore 并且我在服务器模式下运行 RavenDB。我在询问 DocumentDatabase 和 InMemoryRavenConfiguration 类。你用过吗?
    • 您自己创建 DocumentStore 确实没有充分的理由。你想做什么?
    • 我正在尝试使用 DocumentDatabase 类的对象。因为我想检索单个数据库中的所有文档,而这个类为我提供了一个函数“GetDocuments()”。
    • 不要使用 DocumentDatabase 类,这不是你应该使用 RavenDB 的方式。使用会话对象从数据库中获取文档。
    • 非常感谢 Fitzchak 的正确方法,那么我如何从单个数据库中获取所有文档。请帮助我。因为我使用了这行代码: var list = session.Query ("Raven/DocumentsByEntityName").ToArray();但我没有得到文件的名称.. :)
    猜你喜欢
    • 1970-01-01
    • 2013-03-28
    • 1970-01-01
    • 2013-03-29
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多