diff --git a/modules/identity/src/Volo.Abp.Identity.MongoDB/Volo/Abp/Identity/MongoDB/MongoIdentityUserRepository.cs b/modules/identity/src/Volo.Abp.Identity.MongoDB/Volo/Abp/Identity/MongoDB/MongoIdentityUserRepository.cs index 0a84a429f0..80ea4fca3d 100644 --- a/modules/identity/src/Volo.Abp.Identity.MongoDB/Volo/Abp/Identity/MongoDB/MongoIdentityUserRepository.cs +++ b/modules/identity/src/Volo.Abp.Identity.MongoDB/Volo/Abp/Identity/MongoDB/MongoIdentityUserRepository.cs @@ -362,8 +362,21 @@ public class MongoIdentityUserRepository : MongoDbRepository(cancellationToken)) + .Where(x => x.Id == sourceOrganizationId) + .FirstOrDefaultAsync(cancellationToken: cancellationToken); + if (sourceOrganizationUnit == null) + { + throw new EntityNotFoundException(typeof(OrganizationUnit), sourceOrganizationId); + } + + var allSourceOrganizationIds = await (await GetQueryableAsync(cancellationToken)) + .Where(x => x.Code.StartsWith(sourceOrganizationUnit.Code)) + .Select(x => x.Id) + .ToListAsync(cancellationToken: cancellationToken); + var users = await (await GetQueryableAsync(cancellationToken)) - .Where(x => x.OrganizationUnits.Any(r => r.OrganizationUnitId == sourceOrganizationId)) + .Where(x => x.OrganizationUnits.Any(r => allSourceOrganizationIds.Contains(r.OrganizationUnitId))) .ToListAsync(GetCancellationToken(cancellationToken)); foreach (var user in users) @@ -458,7 +471,7 @@ public class MongoIdentityUserRepository : MongoDbRepository x.Id == id); } - + if (roleId.HasValue) { var organizationUnitIds = (await GetQueryableAsync(cancellationToken))