We know that we can use IdentityDbContext in order to have a useful table schema for a user system in our application. Then, through the DbContext, we will be able to access the list of users of our application, and also the list of roles of our application. However, what happens when we want to query the list of users, and each user with their respective role?
Well, we can do a join. With a join we can relate the data from different tables, in our case, from the AspNetUsers and AspNetUserRoles tables. Then we make a projection, where we extract the required data from both tables. In our case, we want the user’s Id, username, role id and role name:
We can verify that the query generated by the previous statement is correct: