2011-09-26 41 views
3

當我使用基於RavenDb的服務器使用.Net客戶端API查詢時,我的索引效果很好。從嵌入式RavenDB中的索引中檢索結果時出現問題

但是,如果我將RavenDb更改爲嵌入類型,則除非我首先查詢索引使用的文檔,否則我無法直接查詢索引。

例如,如果我有駐留如RavenDb單獨集合以下文檔對象:

private class TestParentDocument 
     { 
      public string Id { get { return GetType().Name + "/" + AggregateRootId; } } 
      public Guid AggregateRootId { get; set; } 
      public string Name { get; set; } 
      public string Description { get; set; } 
     } 

private class TestChildProductFlagDocument 
     { 
      public string TestParentDocumentId { get; set; } 
      public short ProductFlagTypeId { get; set; } 
     } 

然後我有以下的對象,表示輸出文件,所述索引映射到:

private class TestJoinIndexOutput 
     { 
      public string TestParentDocumentId { get; set; } 
      public string Name { get; set; } 
      public short ProductFlagTypeId { get; set; } 
     } 

這是該指數定義:

private class TestJoinIndex : AbstractIndexCreationTask<TestChildProductFlagDocument, TestJoinIndexOutput> 
     { 
      public TestJoinIndex() 
      { 
       Map = docs => from doc in docs 
           select new 
           { 
            TestParentDocumentId = doc.TestParentDocumentId, 
            ProductFlagTypeId = doc.ProductFlagTypeId 
           }; 

       TransformResults = (database, results) => 
        from result in results 
        let parentDoc = database.Load<TestParentDocument>(result.TestParentDocumentId) 
        select new 
        { 
         TestParentDocumentId = result.TestParentDocumentId, 
         ProductFlagTypeId = result.ProductFlagTypeId, 
         Name = parentDoc.Name 
        }; 
      } 

我的代碼致電指數看起來像這樣:

var theJoinIndexes = ravenSession.Query<TestJoinIndexOutput, TestJoinIndex>().ToList(); 

這幾乎立即返回,失敗,除非我做到以下幾點:

var theParentDocuments = ravenSession.Query<TestParentDocument>().ToList(); 
var theJoinIndexes = ravenSession.Query<TestJoinIndexOutput, TestJoinIndex>().ToList(); 

我Ravendb嵌入式定義看起來像這樣:

docStore = new EmbeddableDocumentStore 
       { 
        UseEmbeddedHttpServer = false, 
        RunInMemory = true 

       }; 
       docStore.Configuration.Port = 7777; 
       docStore.Initialize(); 

       IndexCreation.CreateIndexes(typeof(TestJoinIndex).Assembly, docstore); 

回答

2

你AREN等待索引完成,請致電WaitForNonStaleResultsAsOfNow

+0

這很有效!謝謝Ayende - 「我可能是一個傻瓜,但我打算成爲一個活的傻瓜」 - Matrim Cauthon –

相關問題