.NET Core 2.1 Identity get all users with their associated roles




I'm trying to pull out all my Identity users and their associated roles for a user management admin page. I thought this would be reasonably easy but apparently not. I've tried following the following solution: <https://stackoverflow.com/a/43562544/5392786> but it hasn't worked out so far.


Here is what I have so far:


**ApplicationUser:**



```
public class ApplicationUser : IdentityUser
{
    public List<IdentityUserRole<string>> Roles { get; set; }
}

```

**DBContext**



```
public class ApplicationDbContext : IdentityDbContext<ApplicationUser>
{
    public ApplicationDbContext(DbContextOptions<ApplicationDbContext> options)
        : base(options)
    {
    }
}

```

**Startup Identity code**



```
services.AddIdentity<ApplicationUser, IdentityRole>(options => options.Stores.MaxLengthForKeys = 128)
            .AddEntityFrameworkStores<ApplicationDbContext>()
            .AddDefaultTokenProviders();

```

**Razor Page where I want to display the list:**



```
public class IndexModel : PageModel
{
    private readonly UserManager<ApplicationUser> userManager;

    public IndexModel(UserManager<ApplicationUser> userManager)
    {
        this.userManager = userManager;
    }

    public IEnumerable<ApplicationUser> Users { get; set; }

    public void OnGetAsync()
    {
        this.Users = userManager.Users.Include(u => u.Roles).ToList();
    }
}

```

I get the following error when calling `userManager.Users.Include(u => u.Roles).ToList();`:



> 
> MySql.Data.MySqlClient.MySqlException: 'Unknown column 'u.Roles.ApplicationUserId' in 'field list''
> 
> 
>
I have now implemented the following solution.


As CodeNotFound pointed out in the comments, IdentityUser used to have a `Roles` property. This is no longer the case in .NET Core. This [comment/issue](https://github.com/aspnet/Identity/issues/1361#issuecomment-348863959) on GitHub seems to be the current solution for .Net Core. I have attempted to implemented it with the following code:


**ApplicationUser**



```
public class ApplicationUser : IdentityUser
{
    public ICollection<ApplicationUserRole> UserRoles { get; set; }
}

```

**ApplicationUserRole**



```
public class ApplicationUserRole : IdentityUserRole<string>
{
    public virtual ApplicationUser User { get; set; }
    public virtual ApplicationRole Role { get; set; }
}

```

**ApplicationRole**



```
public class ApplicationRole : IdentityRole
{
    public ICollection<ApplicationUserRole> UserRoles { get; set; }
}

```

**DBContext**



```
public class ApplicationDbContext
    : IdentityDbContext<ApplicationUser, ApplicationRole, string, IdentityUserClaim<string>,
    ApplicationUserRole, IdentityUserLogin<string>,
    IdentityRoleClaim<string>, IdentityUserToken<string>>
{
    public ApplicationDbContext(DbContextOptions<ApplicationDbContext> options)
        : base(options)
    {
    }

    protected override void OnModelCreating(ModelBuilder builder)
    {
        base.OnModelCreating(builder);

        builder.Entity<ApplicationUserRole>(userRole =>
        {
            userRole.HasKey(ur => new { ur.UserId, ur.RoleId });

            userRole.HasOne(ur => ur.Role)
                .WithMany(r => r.UserRoles)
                .HasForeignKey(ur => ur.RoleId)
                .IsRequired();

            userRole.HasOne(ur => ur.User)
                .WithMany(r => r.UserRoles)
                .HasForeignKey(ur => ur.UserId)
                .IsRequired();
        });
    }
}

```

**Startup**



```
services.AddIdentity<ApplicationUser, ApplicationRole>(options => options.Stores.MaxLengthForKeys = 128)
            .AddEntityFrameworkStores<ApplicationDbContext>()
            .AddDefaultTokenProviders();

```

Finally, make sure when you're using it that you eagerly load the User's UserRoles, and then the UserRole's Role like so:



```
this.Users = userManager.Users.Include(u => u.UserRoles).ThenInclude(ur => ur.Role).ToList();

```

I had an issue where the `Role` property of each `UserRole` was null and this was resolved by adding in the `.ThenInclude(ur => ur.Role)` part.


Microsoft doc on multi-level eager loading: <https://docs.microsoft.com/en-us/ef/core/querying/related-data#including-multiple-levels>
hi [@mateus\_cruz](/u/mateus_cruz),

thanks again for your details that really helped and i’m able to extract logs successfully as expected.

below steps:

authenticate and fetch the access token using endpoint <https://account.uipath.com/oauth/token>

get the job key using endpoint [uipath](https://cloud.uipath.com/%5baccountlogicalname%5d/%5btenantlogicalname%5d/odata/jobs?%24filter=releasename) eq ‘processname’&$orderby=sta… ok. i have solved it. the problem was a misunderstanding of what freecodecamp wanted me to do. first they stated:

you can make a get request to /api/exercise/log with a parameter of userid=\_id to retrieve “a full exercise of " any user”

so i thought they meant all the exercises of users in the … was caused because there was an "unhandled rejection error: eacces: permission denied, mkdir '/home//.npm/\_cache/index-<…>/

solved problem by just adding “sudo” in front

sudo npx create-react-app . def render("show.json", %{user: user} = assigns) do

%{

data: render\_one(user, admin.userview, "user.json", assigns)

}

end

there’s no “implicit” assigns map, which all functions would automatically inherit somehow. you need to explicitly pass the assigns map onwards into rend… [@udo](/u/udo),

you should be verifying the token no matter what, which would require decoding it. if you are using our sdk then this is already happening.

the important distinction here is which token. are you talking about the id token or the access token? the permissions may be in the at, but the at is n… For a long time HtmlAgilityPack [didn't had the ability to directly query an attribute value](http://htmlagilitypack.codeplex.com/Thread/View.aspx?ThreadId=1720). You had to loop over the list of meta nodes. Here's one way - 



```
var doc = new HtmlDocument();
doc.LoadHtml(htmlString);

var list = doc.DocumentNode.SelectNodes("//meta"); 
foreach (var node in list)
{
    string content = node.GetAttributeValue("content", "");
}

```

But looks like in there is an [experimental xpath release](http://htmlagilitypack.codeplex.com/releases/view/46681) that will let you do that. 



```
doc.Document.SelectNodes("//meta/@content") 

```

will return a list of HtmlAttribute objects. you would need something like this then pull a list of people in that database after the ammount of time 
 /**
 * @event discordmessagereaction
 */
 $.bind('discordmessagereaction', function (event) {
 var reactionevent = event.getevent(),
 reactionuser = reactioneve… your link leads to an inactive developer message btw.

rest does not yet provide a way to list tags except by id. you can use the standard api with the same oauth2 access key that you would use for rest… using the data object you would want to query on the group table using the groupname field. tab visibility is currently only based on the user profile sheet. if you want to control tab visibility from a value in another sheet, you need to use relation/lookup, relation/rollup, or single value columns to bring in whatever value you need into the user profile sheet.

[https://docs.glideapps.c…](https://docs.glideapps.com/all/reference/design-and-structure/visibility-conditions#tab-visibility) if you want each cart item to to have each selected employee,

pass item to select\_emplyee(i) method not index for ex. (click)=“select\_emplyee(item)”.

then in implementation add one more extended property to your cartlist json called employeename.

select\_emplyee(item) {



this.employee\_alert…