0
我有以下索引我創建爲了獲得特定用戶的所有權限。在轉換中,roles.SelectMany(x => x.Permissions)
可能包含重複項,所以我想把.Distinct()
放在它上面。然而,當我這樣做的時候,它似乎在Raven裏面被翻譯成Enumerable.Distinct(roles.SelectMany(x => x.Permissions)
,它沒有返回結果。如果我直接在Raven中更改索引以使用.Distinct()
而不是Enumerable.Distinct(...)
,則它可以很好地工作。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()
};
}
}