RavenDB Map/Reduce over属性是一个列表 [英] RavenDB Map/Reduce over property that is a list

查看:56
本文介绍了RavenDB Map/Reduce over属性是一个列表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

仅学习Map/Reduce,我就错过了一步.我已经阅读了这篇文章(使用.NET Client的RavenDB Map-Reduce示例),但不能完全满足我的需求.

Just learning Map/Reduce and I'm missing a step. I've read this post ( RavenDB Map-Reduce Example using .NET Client ) but can't quite make the jump to what I need.

我有一个对象:

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

    public IList<string> Favorites { get; protected set; }

    public string Id { get; set; }
}

我想要做的是在所有用户之间获取地图/减少收藏夹"属性.这样的事情(但这显然行不通):

What I want to do is get Map/Reduce the Favorites property across all Users. Something like this (but this obviously doesn't work):

 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) };

例如,如果用户1具有收藏夹1、2、3,用户2具有收藏夹1,2,则应返回{{OilId = 3,Count = 1},{OilId = 2,Count = 2}, {OilId = 1,Count = 2}}

For example, if User1 has favorites 1, 2, 3 and User 2 has favorites 1,2, then this should return back {{OilId=3, Count =1}, {OilId=2, Count = 2}, {OilId=1,Count = 2}}

当前代码产生一个异常:System.NotSupportedException:不支持的节点:调用

The current code produces an exception: System.NotSupportedException : Node not supported: Call

我觉得我已经接近了.有帮助吗?

I feel like I'm close. Any help?

推荐答案

我编写了一个小应用程序来复制您的代码,但是看不到抛出异常.在这里查看我的代码: http://pastie.org/2308175 .输出是

I wrote a small application replicating your code, but I don't see the exception thrown. See my code here: http://pastie.org/2308175. The output is

收藏夹:1,数量:2

Favorite: 1, Count: 2

收藏夹:2,数量:2

Favorite: 2, Count: 2

收藏夹:3,计数:1

Favorite: 3, Count: 1

这是我所期望的.

这篇关于RavenDB Map/Reduce over属性是一个列表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆