RavenDB Map / Reduce属于列表的属性

刚刚学习Map / Reduce,我错过了一步。 我已经阅读过这篇文章( 使用.NET客户端的RavenDB Map-Reduce示例 ),但不能完全跳到我需要的地方。

我有一个对象:

public class User : IIdentifiable { public User(string username) { Id = String.Format(@"users/{0}", username); Favorites = new List(); } public IList Favorites { get; protected set; } public string Id { get; set; } } 

我想要做的是在所有用户中获取Map / Reducecollections夹属性。 像这样的东西(但这显然不起作用):

  Map = users => from user in users from oil in user.Favorites select new { OilId = oil, Count = 1 }; Reduce = results => from result in results group result by result.OilId into g select new { OilId = g.Key, Count = g.Sum(x => x.Count) }; 

例如,如果User1有collections夹1,2,3,而用户2有collections夹1,2,那么这应该返回{{OilId = 3,Count = 1},{OilId = 2,Count = 2},{OilId = 1,Count = 2}}

当前代码生成exception:System.NotSupportedException:不支持节点:调用

我觉得我很亲密。 有帮助吗?

我写了一个复制代码的小应用程序,但我没有看到抛出的exception。 请在此处查看我的代码: http : //pastie.org/2308175 。 输出是

collections:1,伯爵:2

collections:2,伯爵:2

collections:3,数量:1

这是我所期待的。

MBonig,Map / Reduce仅对文档进行聚合有用。 对于这样的事情,通过做类似的事情,你会得到更好的服务:

  session.Query().Select(u=>u.Favorites).ToList()