获取角色中的用户

时间:2015-04-24 18:30:52

标签: asp.net asp.net-mvc-5 entity-framework-6

我写了一个=VLOOKUP( A2; # 1st argument: search criterion: the current PN Sheet1!$A$2:$B$7; # 2nd argument: search array (both search criterion and return value!) 2 # 3rd argument: index of column with return value. ) * B2 # multiply the returned value with quantity ViewModel,我希望收集所有RoleUsers Users成员Role

我知道我不能在身份上使用Name = string id。我考虑过使用Roles.GetUsersInRoleApplicationDbContext的实例,但我不确定如何使用此方法,因为描述不太清楚。

如何通过_db.Users.Where()找到所有users

编辑目前,我正在尝试在控制器的Details方法中创建role = string id

new RoleUsers{}

我该怎样用点替换? 我在考虑在这里使用RoleUsers roleUsers = new RoleUsers { Role = new Role(id), Users = ... }

EDIT2 :到目前为止,我已经解决了很多问题。

userManager

现在我得到所有用户,我在这里做错了什么?

1 个答案:

答案 0 :(得分:0)

用这段代码解决了这个问题:

var roleId = roleManager.FindByName(id);
var roleUsers = new RoleUsers
{
    Role = new Role(id),
    Users = _db.Users.Where(x => x.Roles.Any(y => y.RoleId == roleId.Id)).ToList()
};