Вопрос

I have an index that works great when I query it using the .Net client API with a server based RavenDb.

However, if I change the RavenDb to an embedded type then I cannot query the index directly unless I first query the document that the index uses.

For instance if I have the following document objects which reside as separate collections in the 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; }
        }

Then I have the following object which represents the output document that the index maps to:

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

Here is the index definition:

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

My code to call the index looks like so:

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

This returns almost immediately and fails unless I do the following:

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

My Ravendb embedded definition looks like so:

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

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

                IndexCreation.CreateIndexes(typeof(TestJoinIndex).Assembly, docstore);
Это было полезно?

Решение

You aren't waiting for indexing to complete, call WaitForNonStaleResultsAsOfNow

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top