Browse Source

Update EfCoreIdentityUserRepository.cs

pull/17627/head
maliming 3 years ago
parent
commit
7dc1100e12
No known key found for this signature in database GPG Key ID: A646B9CB645ECEA4
  1. 25
      modules/identity/src/Volo.Abp.Identity.EntityFrameworkCore/Volo/Abp/Identity/EntityFrameworkCore/EfCoreIdentityUserRepository.cs

25
modules/identity/src/Volo.Abp.Identity.EntityFrameworkCore/Volo/Abp/Identity/EntityFrameworkCore/EfCoreIdentityUserRepository.cs

@ -57,24 +57,23 @@ public class EfCoreIdentityUserRepository : EfCoreRepository<IIdentityDbContext,
} }
public virtual async Task<List<IdentityUserIdWithRoleNames>> GetRoleNamesAsync( public virtual async Task<List<IdentityUserIdWithRoleNames>> GetRoleNamesAsync(
IEnumerable<Guid> userIds, IEnumerable<Guid> userIds,
CancellationToken cancellationToken = default) CancellationToken cancellationToken = default)
{ {
var dbContext = await GetDbContextAsync(); var dbContext = await GetDbContextAsync();
var query = from userRole in dbContext.Set<IdentityUserRole>() return await (from userRole in dbContext.Set<IdentityUserRole>()
join role in dbContext.Roles on userRole.RoleId equals role.Id join role in dbContext.Roles on userRole.RoleId equals role.Id
where userIds.Contains(userRole.UserId) where userIds.Contains(userRole.UserId)
select new group new
{ {
userRole.UserId, userRole.UserId,
role.Name role.Name
}; } by userRole.UserId
into gp
var result = await query select new IdentityUserIdWithRoleNames
.GroupBy(x => x.UserId) {
.ToDictionaryAsync(x => x.Key, x => x.Select(r => r.Name).ToArray(), cancellationToken: cancellationToken); Id = gp.Key, RoleNames = gp.Select(x => x.Name).ToArray()
}).ToListAsync(GetCancellationToken(cancellationToken));
return result.Select(x => new IdentityUserIdWithRoleNames() { Id = x.Key, RoleNames = x.Value }).ToList();
} }
public virtual async Task<List<string>> GetRoleNamesInOrganizationUnitAsync( public virtual async Task<List<string>> GetRoleNamesInOrganizationUnitAsync(

Loading…
Cancel
Save