Open Closed

How to access the data of UserRole from DbContext #824


User avatar
0
huy.quan created

Check the docs before asking a question: https://docs.abp.io/en/commercial/latest/ Check the samples, to see the basic tasks: https://docs.abp.io/en/commercial/latest/samples/index The exact solution to your question may have been answered before, please use the search on the homepage.

  • ABP Framework version: v4.0.2
  • UI type: Angular
  • DB provider: EF Core
  • Identity Server Seperated (Angular): no

<br> I have a query need to check Role of User, I can get list of user by using DbContext.Users but also need to check role of each user from list. How can I do that? Is it possible to get UserRoles by something like DbContext.UserRoles?

Thanks support team


1 Answer(s)
  • User Avatar
    0
    cotur created

    Hi,

    There is an entity that named IdentityUserRole that represents the link between a user and a role.

    You can user IIdentityDbContext and get those by;

    var dbContext = await GetDbContextAsync();
    
    dbContext.Set<IdentityUserRole>().*******
    
Made with ❤️ on ABP v8.2.0-preview Updated on March 25, 2024, 15:11