我正在创建以下索引以获取特定用户的所有权限。在转换中,roles.SelectMany(x => x.Permissions)
可能包含重复项,所以我想放上.Distinct()
它。但是,当我这样做时,它似乎被翻译到Enumerable.Distinct(roles.SelectMany(x => x.Permissions)
了 Raven 内部,它没有返回任何结果。如果我直接在 Raven 中将索引更改为 use.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()
};
}
}