Asp.net Identity GetUsersByRole在2.0版之后停止工作

时间:2014-04-07 21:14:53

标签: c# asp.net asp.net-identity

我使用以下方法通过角色获取所有用户,并且在版本2.0发布之前它正常工作。有什么变化?角色不再存在,只有RoleId,但由于我需要通过名称访问而不是有用...出现Microsoft删除/移动到另一个类?但是无法在任何地方找到它。

    public List<ApplicationUser> GetUsersByRole(string userRole)
    {
        return (_accountRepository.Get.SelectMany(user => user.Roles, (user, role) => new { user, role })
            .Where(x => x.role.Role.Name == userRole).Select(x => x.user)).ToList();
    }

x.role.Role.Name中的Role对象不再解析。

1 个答案:

答案 0 :(得分:1)

在版本2.0中删除了IdentityUserRole上的角色/用户导航属性,解决方法是在适当的db上下文特定层编写您自己的linq查询,以获取特定角色中的用户列表。从长远来看,我们会向GetUsersInRole添加RoleManager方法(暂时应该在2.1中)。