Map / Transform中的Distinct()

时间:2012-06-22 17:55:33

标签: indexing mapreduce distinct ravendb

我正在创建以下索引以获取特定用户的所有权限。在转换中,roles.SelectMany(x => x.Permissions)可能包含重复项,因此我想在其上添加.Distinct()。但是,当我这样做时,它似乎被转换为Raven内部的Enumerable.Distinct(roles.SelectMany(x => x.Permissions),后者没有返回任何结果。如果我直接在Raven中更改索引以使用.Distinct()而不是Enumerable.Distinct(...),则效果非常好。

如何编写它以便在Raven中正确翻译?

public class PermissionsByUser : AbstractIndexCreationTask<User, UserWithPermissions>
{
    public override string IndexName
    {
        get
        {
            return "Users/PermissionsByUser";
        }
    }
    public PermissionsByUser()
    {
        Map = users => from user in users
                       from role in user.Roles
                       select new {role.Id};

        TransformResults = (database, users) => from user in users
                                                let roles = database.Load<Role>(user.Roles.Select(x => x.Id))
                                                select new
                                                        {
                                                            Id = user.Id,
                                                            Username = user.Username,
                                                            Password = user.Password,
                                                            Roles = user.Roles,
                                                            Permissions = roles.SelectMany(x => x.Permissions)//.Distinct()
                                                        };
    }
}

1 个答案:

答案 0 :(得分:0)

我认为这实际上只是陈旧结果的问题。在https://groups.google.com/forum/?fromgroups#!topic/ravendb/0hO8TOQicwc

回答