【发布时间】:2018-04-20 16:47:45
【问题描述】:
我正在使用 Identity 开发一个 Asp.net core 2.0 项目。我的项目使用核心 1.1 创建和开发,一段时间后迁移到核心 2.0。 迁移到核心 2.0 后一切都很好,但在项目的一部分中,我需要让所有用户都具有特定角色。 在 Asp.Net Core 1.1 中,我使用以下代码计算所有特定角色的数量:
r.Users.Count
完成的代码:
public IActionResult Index()
{
List<ApplicationRoleViewModel> model = new List<ApplicationRoleViewModel>();
model = _roleManager.Roles.Select(r => new ApplicationRoleViewModel
{
Id = r.Id,
Name = r.Name,
Description = r.Description,
NumberOfUsers = r.Users.Count
}).ToList();
return View(model);
}
和:
public class ApplicationRoleViewModel
{
public string Id { get; set; }
public string Name { get; set; }
public string Description { get; set; }
public int NumberOfUsers { get; set; }
}
但是核心 2.0 中没有 Users 对象。
我也看到了这个question,但我无法解决我的问题。
现在如何计算 ASP.NET Core 2.0 中具有特定角色的所有用户?
【问题讨论】:
标签: asp.net-core asp.net-core-2.0 identity