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

Markdown supported.
Copy, paste, or drag & drop images and files (max 100 MB per file, 100 MB total per post)

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>().*******
    
    Markdown supported.
    Copy, paste, or drag & drop images and files (max 100 MB per file, 100 MB total per post)
Boost Your Development
ABP Live Training
Packages
See Trainings
Mastering ABP Framework Book
The Official Guide
Mastering
ABP Framework
Learn More
Mastering ABP Framework Book
Made with ❤️ on ABP v10.8.0-preview. Updated on September 16, 2026, 14:50
1
ABP Assistant
🔐 You need to be logged in to use the chatbot. Please log in first.