2012-04-24 261 views
0

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

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); 

回答

0

使用EmbeddedDocumentStore,并且一定要初始化。创建会话并使用会话对象来查询嵌入式数据库。

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

var session = documentStore.OpenSession(); 

比你能做到session.Load(id)session.QuerydocumentStore .DatabaseCommands

+0

感谢FitZchak但我没有使用EmbeddedDocumentStore,我正在使用简单的DocumentStore,而且我正在服务器模式下运行RavenDB。我在询问DocumentDatabase和InMemoryRavenConfiguration类。你用过它们吗? – 2012-04-24 07:09:42

+0

您自己创建DocumentStore实在没有什么好的理由。你试图做什么? – 2012-04-24 09:14:32

+0

我正在尝试使用DocumentDatabase类的对象。因为我想检索单个数据库中的所有文档,并且此类提供了一个函数“GetDocuments()”。 – 2012-04-24 09:34:04