在视图模型中获取用户及其角色的列表

时间:2018-11-02 15:51:13

标签: c# asp.net-core asp.net-core-2.1

我有一个模型,其中包含有关此应用程序用户的信息

public class ApplicationUser : IdentityUser
{
    public string Name { get; set; }
    public string Payroll { get; set; }
}

我有一个视图模型,该模型应该显示有关用户及其角色的一些信息

public class VM_UserAdmin
{
    public string Name { get; set; }
    public string Payroll { get; set; }
    public string Email { get; set; }
    public string Role { get; set; }
}

我可以获取名称,工资单,电子邮件作为ApplicationUser的属性,这没有问题:

return await _applicationDbContext.Users.ToListAsync();

其中_applicationDbContext是我的数据库上下文。

任何人都可以告诉我如何达到角色,以便可以将其包含在VM_UserAdmin模型中。在asp.net core 2.1中,不再提供User.Roles...。我与用户和角色具有一对一的关系。

谢谢。

0 个答案:

没有答案
相关问题