【发布时间】:2015-05-11 20:35:16
【问题描述】:
我有一个项目列表{Id, Name, CategoryId} 和一个类别列表{Id, Name, IsActive}。
如何获取列表{CategoryId, Count}包括具有零项的类别。
目前我有这样的索引:
public class CategoryCountIndex : AbstractIndexCreationTask<Item, CategoryCountIndex.Result>
{
public class Result
{
public string CategoryId { get; set; }
public int Count { get; set; }
}
public CategoryCountIndex()
{
Map = items => from item in items
select new Result
{
CategoryId = item.CategoryId,
Count = 1
};
Reduce = results => from result in results
group result by result.CategoryId
into c
select new Result
{
CategoryId = c.Key,
Count = c.Sum(x => x.Count)
};
}
}
改进/更改我的解决方案以使类别没有项目的最佳方法是什么?
【问题讨论】:
标签: c# mapreduce ravendb nosql