加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

c# – RavenDB Map / Reduce over属性是一个列表

发布时间:2020-12-16 01:45:56 所属栏目:百科 来源:网络整理
导读:刚学习Map / Reduce,我错过了一步.我已经读过这篇文章( RavenDB Map-Reduce Example using .NET Client),但不能完全跳到我需要的东西. 我有一个对象: public class User : IIdentifiable{ public User(string username) { Id = String.Format(@"users/{0}",
刚学习Map / Reduce,我错过了一步.我已经读过这篇文章( RavenDB Map-Reduce Example using .NET Client),但不能完全跳到我需要的东西.

我有一个对象:

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

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

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有收藏夹1,2,3,而用户2有收藏夹1,那么这应该返回{{OilId = 3,Count = 1},{OilId = 2,Count = 2},{OilId = 1,Count = 2}}

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

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

解决方法

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

Favorite: 1,Count: 2

Favorite: 2,Count: 2

Favorite: 3,Count: 1

这是我所期待的.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读