我希望获得一个属于类似角色的linq用户列表;像这样的东西:
{
{
string i_want_to_delete_this = "I don't want this cleared, but
completely gone";
} // it's gone
}
答案 0 :(得分:0)
首先创建查询以查找相关的userId然后使用此查询来获取用户列表。因为第一个查询尚未执行,所以最后只会在此处发出一个SQL查询:
public IList<User> GetApplicationUsersInRole(string roleName)
{
var roleUserIdsQuery = from role in _context.Roles
where role.Name == roleName
from user in role.Users
select user.UserId;
return _context.Users.Where(applicationUser =>
roleUserIdsQuery.Contains(applicationUser.Id))
.ToList();
}