【发布时间】:2012-03-28 23:09:31
【问题描述】:
在我的数据库中,我有一个案例列表:
{ Id: 1, Owner: "guid1", Text: "Question1" }
{ Id: 2, Owner: "guid1", Text: "Question2" }
{ Id: 3, Owner: "guid2", Text: "Question3" }
在查询数据时,我还希望(在我的索引中,结果中)每个所有者拥有的案例数。所以我在这个集合上创建了一个 map/reduce 索引:
public class RelatedCases
{
public Guid Owner { get; set; }
public int Count { get; set; }
}
public class RelatedCaseIndex : AbstractMultiMapIndexCreationTask<RelatedCases>
{
public RelatedCaseIndex()
{
AddMap<CaseDocument> (c => c.Select(a => new { a.Owner, Count = 1 }));
Reduce = result => result
.GroupBy(a => a.Owner)
.Select(a => new
{
Owner = a.Key,
Count = a.Sum(b => b.Count)
});
}
}
现在我只是不知道如何生成查询以包含索引中的数据。根据文档,我尝试了类似的方法:
session.Query<CaseDocument>().Customize(a => a.Include ...)
或 CaseIndex 上的 TransformResults,它没有正常工作。
我知道我可以在单独的查询中重新查询 raven 以获取所有相关案例的列表,但我想在一次往返中完成。
【问题讨论】:
标签: ravendb