Does a lot of maps / abbreviations work in RavenDb?

I read Ayende 's blog post on the RavenDB multi- photographic feature and tried to implement it. I can not make it work. What I have is basically the same as the example in the blog post:

class RootDocument { public string Id { get; set; } public string Foo { get; set; } public string Bar { get; set; } } public class ChildDocument { public string Id { get; set; } public string RootId { get; set; } public int Value { get; set; } } class RootsByIdIndex: AbstractMultiMapIndexCreationTask<RootsByIdIndex.Result> { public class Result { public string Id { get; set; } public string Foo { get; set; } public string Bar { get; set; } public int Value { get; set; } } public RootsByIdIndex() { AddMap<ChildDocument>(children => from child in children select new { Id = child.RootId, Foo = (string)null, Bar = (string)null, Value = child.Value }); AddMap<RootDocument>(roots => from root in roots select new { Id = root.Id, Foo = root.Foo, Bar = root.Bar, Value = 0 }); Reduce = results => from result in results group result by result.Id into g select new { Id = g.Key, Foo = g.Select(x => x.Foo).Where(x => x != null).First(), Bar = g.Select(x => x.Bar).Where(x => x != null).First(), Value = g.Sum(x => x.Value) }; } } 

An index query always gives me a value of 0 for the Value attribute. A little attempt at the index makes it seem like the ChildDocument card never retrieves any documents.

Should this work in the current stable version of RavenDB (1.0.573)? Or am I doing it wrong?

+4
source share
1 answer

The reduced portion of your index is incorrect in the Foo and Bar fields.

In the first Map function, you set Foo and Boo to null, since the structure for displaying all Map functions must be exactly the same in the MultiMap index. You should use FirstOrDefault() instead of First()

 Foo = g.Select(x => x.Foo).Where(x => x != null).FirstOrDefault(), Bar = g.Select(x => x.Bar).Where(x => x != null).FirstOrDefault(), 
+4
source

Source: https://habr.com/ru/post/1387648/


All Articles