2012-04-24 139 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