【发布时间】:2011-12-23 12:26:02
【问题描述】:
我已经阅读了 RavenDB 的 Ayende 的 blog post on the multi map feature 并尝试实现它。我无法让它通过。我所拥有的与博文中的示例基本相同:
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)
};
}
}
查询索引总是给我 Value 属性的值 0。稍微摆弄一下索引会使 ChildDocument 的映射似乎从不检索任何文档。
这应该在当前稳定的 RavenDB 版本 (1.0.573) 中工作吗?还是我做错了?
【问题讨论】: