In my .NET 6 application I want to display all users with their claims.
Currently I use the UserManager to get all users like this:
var users = await _userManager
.Users
.AsNoTracking()
.ToListAsync(cancellationToken);
Then I loop through all the users and call await _userManager.GetClaimsAsync(user)
to get the claims for each user.
This results in many database requests as a request gets fired for every user. When there are multiple thousand users present it really harms the performance.
Is there a better way to do these kind of bulk operations with AspNetCore.Identity?
if role-related services are enabled and claims are related to roles you can use
var users = await _userManager.GetUsersInRoleAsync("Role1");
otherwise, you will have to create navigational properties manually.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.