From 06889783f8c9e1c07c85847522ad7a760e4df621 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Halil=20=C4=B0brahim=20Kalkan?= Date: Mon, 21 Dec 2020 18:03:23 +0300 Subject: [PATCH] Apply async changes for EF Core repos. --- .../EfCoreFeatureValueRepository.cs | 6 +-- .../MongoDB/MongoFeatureValueRepository.cs | 6 +-- .../ApiResources/ApiResourceRepository.cs | 34 +++++++----- .../ApiScopes/ApiScopeRepository.cs | 25 +++++---- .../Clients/ClientRepository.cs | 52 +++++++++++-------- .../Devices/DeviceFlowCodesRepository.cs | 6 +-- .../Grants/PersistedGrantRepository.cs | 18 ++++--- .../IdentityResourceRepository.cs | 14 +++-- .../EfCorePermissionGrantRepository.cs | 6 +-- .../MongoDb/MongoPermissionGrantRepository.cs | 15 +++--- .../EfCoreSettingRepository.cs | 6 +-- .../MongoDB/MongoSettingRepository.cs | 12 +++-- .../EfCoreAbpUserRepositoryBase.cs | 8 +-- .../Users/MongoDB/MongoUserRepositoryBase.cs | 20 ++++--- 14 files changed, 139 insertions(+), 89 deletions(-) diff --git a/modules/feature-management/src/Volo.Abp.FeatureManagement.EntityFrameworkCore/Volo/Abp/FeatureManagement/EntityFrameworkCore/EfCoreFeatureValueRepository.cs b/modules/feature-management/src/Volo.Abp.FeatureManagement.EntityFrameworkCore/Volo/Abp/FeatureManagement/EntityFrameworkCore/EfCoreFeatureValueRepository.cs index c559851bf1..be75e600d8 100644 --- a/modules/feature-management/src/Volo.Abp.FeatureManagement.EntityFrameworkCore/Volo/Abp/FeatureManagement/EntityFrameworkCore/EfCoreFeatureValueRepository.cs +++ b/modules/feature-management/src/Volo.Abp.FeatureManagement.EntityFrameworkCore/Volo/Abp/FeatureManagement/EntityFrameworkCore/EfCoreFeatureValueRepository.cs @@ -17,7 +17,7 @@ namespace Volo.Abp.FeatureManagement.EntityFrameworkCore public virtual async Task FindAsync(string name, string providerName, string providerKey) { - return await DbSet + return await (await GetDbSetAsync()) .OrderBy(x => x.Id) .FirstOrDefaultAsync( s => s.Name == name && s.ProviderName == providerName && s.ProviderKey == providerKey @@ -26,7 +26,7 @@ namespace Volo.Abp.FeatureManagement.EntityFrameworkCore public async Task> FindAllAsync(string name, string providerName, string providerKey) { - return await DbSet + return await (await GetDbSetAsync()) .Where( s => s.Name == name && s.ProviderName == providerName && s.ProviderKey == providerKey ).ToListAsync(); @@ -34,7 +34,7 @@ namespace Volo.Abp.FeatureManagement.EntityFrameworkCore public virtual async Task> GetListAsync(string providerName, string providerKey) { - return await DbSet + return await (await GetDbSetAsync()) .Where( s => s.ProviderName == providerName && s.ProviderKey == providerKey ).ToListAsync(); diff --git a/modules/feature-management/src/Volo.Abp.FeatureManagement.MongoDB/Volo/Abp/FeatureManagement/MongoDB/MongoFeatureValueRepository.cs b/modules/feature-management/src/Volo.Abp.FeatureManagement.MongoDB/Volo/Abp/FeatureManagement/MongoDB/MongoFeatureValueRepository.cs index 2b96ca876a..21d4784f6e 100644 --- a/modules/feature-management/src/Volo.Abp.FeatureManagement.MongoDB/Volo/Abp/FeatureManagement/MongoDB/MongoFeatureValueRepository.cs +++ b/modules/feature-management/src/Volo.Abp.FeatureManagement.MongoDB/Volo/Abp/FeatureManagement/MongoDB/MongoFeatureValueRepository.cs @@ -18,20 +18,20 @@ namespace Volo.Abp.FeatureManagement.MongoDB public virtual async Task FindAsync(string name, string providerName, string providerKey) { - return await GetMongoQueryable() + return await (await GetMongoQueryableAsync()) .OrderBy(x => x.Id) .FirstOrDefaultAsync(s => s.Name == name && s.ProviderName == providerName && s.ProviderKey == providerKey); } public async Task> FindAllAsync(string name, string providerName, string providerKey) { - return await GetMongoQueryable() + return await (await GetMongoQueryableAsync()) .Where(s => s.Name == name && s.ProviderName == providerName && s.ProviderKey == providerKey).ToListAsync(); } public virtual async Task> GetListAsync(string providerName, string providerKey) { - return await GetMongoQueryable() + return await (await GetMongoQueryableAsync()) .Where(s => s.ProviderName == providerName && s.ProviderKey == providerKey) .ToListAsync(); } diff --git a/modules/identityserver/src/Volo.Abp.IdentityServer.EntityFrameworkCore/Volo/Abp/IdentityServer/ApiResources/ApiResourceRepository.cs b/modules/identityserver/src/Volo.Abp.IdentityServer.EntityFrameworkCore/Volo/Abp/IdentityServer/ApiResources/ApiResourceRepository.cs index 3cdcb7e49d..16a789048d 100644 --- a/modules/identityserver/src/Volo.Abp.IdentityServer.EntityFrameworkCore/Volo/Abp/IdentityServer/ApiResources/ApiResourceRepository.cs +++ b/modules/identityserver/src/Volo.Abp.IdentityServer.EntityFrameworkCore/Volo/Abp/IdentityServer/ApiResources/ApiResourceRepository.cs @@ -20,7 +20,7 @@ namespace Volo.Abp.IdentityServer.ApiResources public async Task FindByNameAsync(string apiResourceName, bool includeDetails = true, CancellationToken cancellationToken = default) { - var query = from apiResource in DbSet.IncludeDetails(includeDetails) + var query = from apiResource in (await GetDbSetAsync()).IncludeDetails(includeDetails) where apiResource.Name == apiResourceName orderby apiResource.Id select apiResource; @@ -31,7 +31,7 @@ namespace Volo.Abp.IdentityServer.ApiResources public async Task> FindByNameAsync(string[] apiResourceNames, bool includeDetails = true, CancellationToken cancellationToken = default) { - var query = from apiResource in DbSet.IncludeDetails(includeDetails) + var query = from apiResource in (await GetDbSetAsync()).IncludeDetails(includeDetails) where apiResourceNames.Contains(apiResource.Name) orderby apiResource.Name select apiResource; @@ -44,7 +44,7 @@ namespace Volo.Abp.IdentityServer.ApiResources bool includeDetails = false, CancellationToken cancellationToken = default) { - var query = from api in DbSet.IncludeDetails(includeDetails) + var query = from api in (await GetDbSetAsync()).IncludeDetails(includeDetails) where api.Scopes.Any(x => scopeNames.Contains(x.Scope)) select api; @@ -58,7 +58,7 @@ namespace Volo.Abp.IdentityServer.ApiResources bool includeDetails = false, CancellationToken cancellationToken = default) { - return await DbSet + return await (await GetDbSetAsync()) .IncludeDetails(includeDetails) .WhereIf(!filter.IsNullOrWhiteSpace(), x => x.Name.Contains(filter) || x.Description.Contains(filter) || @@ -70,41 +70,49 @@ namespace Volo.Abp.IdentityServer.ApiResources public virtual async Task CheckNameExistAsync(string name, Guid? expectedId = null, CancellationToken cancellationToken = default) { - return await DbSet.AnyAsync(ar => ar.Id != expectedId && ar.Name == name, GetCancellationToken(cancellationToken)); + return await (await GetDbSetAsync()).AnyAsync(ar => ar.Id != expectedId && ar.Name == name, GetCancellationToken(cancellationToken)); } public async override Task DeleteAsync(Guid id, bool autoSave = false, CancellationToken cancellationToken = default) { - var resourceClaims = DbContext.Set().Where(sc => sc.ApiResourceId == id); + var dbContext = await GetDbContextAsync(); + + var resourceClaims = dbContext.Set().Where(sc => sc.ApiResourceId == id); foreach (var scopeClaim in resourceClaims) { - DbContext.Set().Remove(scopeClaim); + dbContext.Set().Remove(scopeClaim); } - var resourceScopes = DbContext.Set().Where(s => s.ApiResourceId == id); + var resourceScopes = dbContext.Set().Where(s => s.ApiResourceId == id); foreach (var scope in resourceScopes) { - DbContext.Set().Remove(scope); + dbContext.Set().Remove(scope); } - var resourceSecrets = DbContext.Set().Where(s => s.ApiResourceId == id); + var resourceSecrets = dbContext.Set().Where(s => s.ApiResourceId == id); foreach (var secret in resourceSecrets) { - DbContext.Set().Remove(secret); + dbContext.Set().Remove(secret); } - var apiResourceProperties = DbContext.Set().Where(s => s.ApiResourceId == id); + var apiResourceProperties = dbContext.Set().Where(s => s.ApiResourceId == id); foreach (var property in apiResourceProperties) { - DbContext.Set().Remove(property); + dbContext.Set().Remove(property); } await base.DeleteAsync(id, autoSave, cancellationToken); } + [Obsolete("Use WithDetailsAsync method.")] public override IQueryable WithDetails() { return GetQueryable().IncludeDetails(); } + + public override async Task> WithDetailsAsync() + { + return (await GetQueryableAsync()).IncludeDetails(); + } } } diff --git a/modules/identityserver/src/Volo.Abp.IdentityServer.EntityFrameworkCore/Volo/Abp/IdentityServer/ApiScopes/ApiScopeRepository.cs b/modules/identityserver/src/Volo.Abp.IdentityServer.EntityFrameworkCore/Volo/Abp/IdentityServer/ApiScopes/ApiScopeRepository.cs index c2a962ead6..4cece3209e 100644 --- a/modules/identityserver/src/Volo.Abp.IdentityServer.EntityFrameworkCore/Volo/Abp/IdentityServer/ApiScopes/ApiScopeRepository.cs +++ b/modules/identityserver/src/Volo.Abp.IdentityServer.EntityFrameworkCore/Volo/Abp/IdentityServer/ApiScopes/ApiScopeRepository.cs @@ -20,7 +20,7 @@ namespace Volo.Abp.IdentityServer.ApiScopes public async Task GetByNameAsync(string scopeName, bool includeDetails = true, CancellationToken cancellationToken = default) { - return await DbSet + return await (await GetDbSetAsync()) .OrderBy(x=>x.Id) .FirstOrDefaultAsync(x => x.Name == scopeName, GetCancellationToken(cancellationToken)); } @@ -28,7 +28,7 @@ namespace Volo.Abp.IdentityServer.ApiScopes public async Task> GetListByNameAsync(string[] scopeNames, bool includeDetails = false, CancellationToken cancellationToken = default) { - var query = from scope in DbSet.IncludeDetails(includeDetails) + var query = from scope in (await GetDbSetAsync()).IncludeDetails(includeDetails) where scopeNames.Contains(scope.Name) orderby scope.Id select scope; @@ -38,7 +38,7 @@ namespace Volo.Abp.IdentityServer.ApiScopes public async Task> GetListAsync(string sorting, int skipCount, int maxResultCount, string filter = null, bool includeDetails = false, CancellationToken cancellationToken = default) { - return await DbSet + return await (await GetDbSetAsync()) .IncludeDetails(includeDetails) .WhereIf(!filter.IsNullOrWhiteSpace(), x => x.Name.Contains(filter) || x.Description.Contains(filter) || @@ -50,29 +50,36 @@ namespace Volo.Abp.IdentityServer.ApiScopes public async Task CheckNameExistAsync(string name, Guid? expectedId = null, CancellationToken cancellationToken = default) { - return await DbSet.AnyAsync(x => x.Id != expectedId && x.Name == name, GetCancellationToken(cancellationToken)); + return await (await GetDbSetAsync()).AnyAsync(x => x.Id != expectedId && x.Name == name, GetCancellationToken(cancellationToken)); } - public async override Task DeleteAsync(Guid id, bool autoSave = false, CancellationToken cancellationToken = new CancellationToken()) + public override async Task DeleteAsync(Guid id, bool autoSave = false, CancellationToken cancellationToken = new CancellationToken()) { - var scopeClaims = DbContext.Set().Where(sc => sc.ApiScopeId == id); + var dbContext = await GetDbContextAsync(); + var scopeClaims = dbContext.Set().Where(sc => sc.ApiScopeId == id); foreach (var claim in scopeClaims) { - DbContext.Set().Remove(claim); + dbContext.Set().Remove(claim); } - var scopeProperties = DbContext.Set().Where(s => s.ApiScopeId == id); + var scopeProperties = dbContext.Set().Where(s => s.ApiScopeId == id); foreach (var property in scopeProperties) { - DbContext.Set().Remove(property); + dbContext.Set().Remove(property); } await base.DeleteAsync(id, autoSave, cancellationToken); } + [Obsolete("Use WithDetailsAsync method.")] public override IQueryable WithDetails() { return GetQueryable().IncludeDetails(); } + + public override async Task> WithDetailsAsync() + { + return (await GetQueryableAsync()).IncludeDetails(); + } } } diff --git a/modules/identityserver/src/Volo.Abp.IdentityServer.EntityFrameworkCore/Volo/Abp/IdentityServer/Clients/ClientRepository.cs b/modules/identityserver/src/Volo.Abp.IdentityServer.EntityFrameworkCore/Volo/Abp/IdentityServer/Clients/ClientRepository.cs index 671d98d822..7607a189ca 100644 --- a/modules/identityserver/src/Volo.Abp.IdentityServer.EntityFrameworkCore/Volo/Abp/IdentityServer/Clients/ClientRepository.cs +++ b/modules/identityserver/src/Volo.Abp.IdentityServer.EntityFrameworkCore/Volo/Abp/IdentityServer/Clients/ClientRepository.cs @@ -23,7 +23,7 @@ namespace Volo.Abp.IdentityServer.Clients bool includeDetails = true, CancellationToken cancellationToken = default) { - return await DbSet + return await (await GetDbSetAsync()) .IncludeDetails(includeDetails) .OrderBy(x => x.ClientId) .FirstOrDefaultAsync(x => x.ClientId == clientId, GetCancellationToken(cancellationToken)); @@ -33,7 +33,7 @@ namespace Volo.Abp.IdentityServer.Clients string sorting, int skipCount, int maxResultCount, string filter, bool includeDetails = false, CancellationToken cancellationToken = default) { - return await DbSet + return await (await GetDbSetAsync()) .IncludeDetails(includeDetails) .WhereIf(!filter.IsNullOrWhiteSpace(), x => x.ClientId.Contains(filter)) .OrderBy(sorting ?? nameof(Client.ClientName) + " desc") @@ -43,7 +43,7 @@ namespace Volo.Abp.IdentityServer.Clients public virtual async Task> GetAllDistinctAllowedCorsOriginsAsync(CancellationToken cancellationToken = default) { - return await DbContext.ClientCorsOrigins + return await (await GetDbContextAsync()).ClientCorsOrigins .Select(x => x.Origin) .Distinct() .ToListAsync(GetCancellationToken(cancellationToken)); @@ -51,62 +51,70 @@ namespace Volo.Abp.IdentityServer.Clients public virtual async Task CheckClientIdExistAsync(string clientId, Guid? expectedId = null, CancellationToken cancellationToken = default) { - return await DbSet.AnyAsync(c => c.Id != expectedId && c.ClientId == clientId, cancellationToken: cancellationToken); + return await (await GetDbSetAsync()).AnyAsync(c => c.Id != expectedId && c.ClientId == clientId, cancellationToken: cancellationToken); } public async override Task DeleteAsync(Guid id, bool autoSave = false, CancellationToken cancellationToken = default) { - foreach (var clientGrantType in DbContext.Set().Where(x => x.ClientId == id)) + var dbContext = await GetDbContextAsync(); + + foreach (var clientGrantType in dbContext.Set().Where(x => x.ClientId == id)) { - DbContext.Set().Remove(clientGrantType); + dbContext.Set().Remove(clientGrantType); } - foreach (var clientRedirectUri in DbContext.Set().Where(x => x.ClientId == id)) + foreach (var clientRedirectUri in dbContext.Set().Where(x => x.ClientId == id)) { - DbContext.Set().Remove(clientRedirectUri); + dbContext.Set().Remove(clientRedirectUri); } - foreach (var clientPostLogoutRedirectUri in DbContext.Set().Where(x => x.ClientId == id)) + foreach (var clientPostLogoutRedirectUri in dbContext.Set().Where(x => x.ClientId == id)) { - DbContext.Set().Remove(clientPostLogoutRedirectUri); + dbContext.Set().Remove(clientPostLogoutRedirectUri); } - foreach (var clientScope in DbContext.Set().Where(x => x.ClientId == id)) + foreach (var clientScope in dbContext.Set().Where(x => x.ClientId == id)) { - DbContext.Set().Remove(clientScope); + dbContext.Set().Remove(clientScope); } - foreach (var clientSecret in DbContext.Set().Where(x => x.ClientId == id)) + foreach (var clientSecret in dbContext.Set().Where(x => x.ClientId == id)) { - DbContext.Set().Remove(clientSecret); + dbContext.Set().Remove(clientSecret); } - foreach (var clientClaim in DbContext.Set().Where(x => x.ClientId == id)) + foreach (var clientClaim in dbContext.Set().Where(x => x.ClientId == id)) { - DbContext.Set().Remove(clientClaim); + dbContext.Set().Remove(clientClaim); } - foreach (var clientIdPRestriction in DbContext.Set().Where(x => x.ClientId == id)) + foreach (var clientIdPRestriction in dbContext.Set().Where(x => x.ClientId == id)) { - DbContext.Set().Remove(clientIdPRestriction); + dbContext.Set().Remove(clientIdPRestriction); } - foreach (var clientCorsOrigin in DbContext.Set().Where(x => x.ClientId == id)) + foreach (var clientCorsOrigin in dbContext.Set().Where(x => x.ClientId == id)) { - DbContext.Set().Remove(clientCorsOrigin); + dbContext.Set().Remove(clientCorsOrigin); } - foreach (var clientProperty in DbContext.Set().Where(x => x.ClientId == id)) + foreach (var clientProperty in dbContext.Set().Where(x => x.ClientId == id)) { - DbContext.Set().Remove(clientProperty); + dbContext.Set().Remove(clientProperty); } await base.DeleteAsync(id, autoSave, cancellationToken); } + [Obsolete("Use WithDetailsAsync method.")] public override IQueryable WithDetails() { return GetQueryable().IncludeDetails(); } + + public override async Task> WithDetailsAsync() + { + return (await GetQueryableAsync()).IncludeDetails(); + } } } diff --git a/modules/identityserver/src/Volo.Abp.IdentityServer.EntityFrameworkCore/Volo/Abp/IdentityServer/Devices/DeviceFlowCodesRepository.cs b/modules/identityserver/src/Volo.Abp.IdentityServer.EntityFrameworkCore/Volo/Abp/IdentityServer/Devices/DeviceFlowCodesRepository.cs index 819c90d402..a6fd6e196b 100644 --- a/modules/identityserver/src/Volo.Abp.IdentityServer.EntityFrameworkCore/Volo/Abp/IdentityServer/Devices/DeviceFlowCodesRepository.cs +++ b/modules/identityserver/src/Volo.Abp.IdentityServer.EntityFrameworkCore/Volo/Abp/IdentityServer/Devices/DeviceFlowCodesRepository.cs @@ -23,7 +23,7 @@ namespace Volo.Abp.IdentityServer.Devices string userCode, CancellationToken cancellationToken = default) { - return await DbSet + return await (await GetDbSetAsync()) .Where(d => d.UserCode == userCode) .OrderBy(d => d.Id) .FirstOrDefaultAsync(GetCancellationToken(cancellationToken)); @@ -33,7 +33,7 @@ namespace Volo.Abp.IdentityServer.Devices string deviceCode, CancellationToken cancellationToken = default) { - return await DbSet + return await (await GetDbSetAsync()) .Where(d => d.DeviceCode == deviceCode) .OrderBy(d => d.Id) .FirstOrDefaultAsync(GetCancellationToken(cancellationToken)); @@ -42,7 +42,7 @@ namespace Volo.Abp.IdentityServer.Devices public virtual async Task> GetListByExpirationAsync(DateTime maxExpirationDate, int maxResultCount, CancellationToken cancellationToken = default) { - return await DbSet + return await (await GetDbSetAsync()) .Where(x => x.Expiration != null && x.Expiration < maxExpirationDate) .OrderBy(x => x.ClientId) .Take(maxResultCount) diff --git a/modules/identityserver/src/Volo.Abp.IdentityServer.EntityFrameworkCore/Volo/Abp/IdentityServer/Grants/PersistedGrantRepository.cs b/modules/identityserver/src/Volo.Abp.IdentityServer.EntityFrameworkCore/Volo/Abp/IdentityServer/Grants/PersistedGrantRepository.cs index aa7a27804f..2dbdfc1a3b 100644 --- a/modules/identityserver/src/Volo.Abp.IdentityServer.EntityFrameworkCore/Volo/Abp/IdentityServer/Grants/PersistedGrantRepository.cs +++ b/modules/identityserver/src/Volo.Abp.IdentityServer.EntityFrameworkCore/Volo/Abp/IdentityServer/Grants/PersistedGrantRepository.cs @@ -21,7 +21,7 @@ namespace Volo.Abp.IdentityServer.Grants public async Task> GetListAsync(string subjectId, string sessionId, string clientId, string type, bool includeDetails = false, CancellationToken cancellationToken = default) { - return await Filter(subjectId, sessionId, clientId, type) + return await (await FilterAsync(subjectId, sessionId, clientId, type)) .ToListAsync(GetCancellationToken(cancellationToken)); } @@ -29,7 +29,7 @@ namespace Volo.Abp.IdentityServer.Grants string key, CancellationToken cancellationToken = default) { - return await DbSet + return await (await GetDbSetAsync()) .Where(x => x.Key == key) .OrderBy(x => x.Id) .FirstOrDefaultAsync(GetCancellationToken(cancellationToken)); @@ -39,7 +39,7 @@ namespace Volo.Abp.IdentityServer.Grants string subjectId, CancellationToken cancellationToken = default) { - return await DbSet + return await (await GetDbSetAsync()) .Where(x => x.SubjectId == subjectId) .ToListAsync(GetCancellationToken(cancellationToken)); } @@ -49,7 +49,7 @@ namespace Volo.Abp.IdentityServer.Grants int maxResultCount, CancellationToken cancellationToken = default) { - return await DbSet + return await (await GetDbSetAsync()) .Where(x => x.Expiration != null && x.Expiration < maxExpirationDate) .OrderBy(x => x.ClientId) .Take(maxResultCount) @@ -63,21 +63,23 @@ namespace Volo.Abp.IdentityServer.Grants string type = null, CancellationToken cancellationToken = default) { - var persistedGrants = await Filter(subjectId, sessionId, clientId, type).ToListAsync(GetCancellationToken(cancellationToken)); + var persistedGrants = await (await FilterAsync(subjectId, sessionId, clientId, type)).ToListAsync(GetCancellationToken(cancellationToken)); + + var dbSet = await GetDbSetAsync(); foreach (var persistedGrant in persistedGrants) { - DbSet.Remove(persistedGrant); + dbSet.Remove(persistedGrant); } } - private IQueryable Filter( + private async Task> FilterAsync( string subjectId, string sessionId, string clientId, string type) { - return DbSet + return (await GetDbSetAsync()) .WhereIf(!subjectId.IsNullOrWhiteSpace(), x => x.SubjectId == subjectId) .WhereIf(!sessionId.IsNullOrWhiteSpace(), x => x.SessionId == sessionId) .WhereIf(!clientId.IsNullOrWhiteSpace(), x => x.ClientId == clientId) diff --git a/modules/identityserver/src/Volo.Abp.IdentityServer.EntityFrameworkCore/Volo/Abp/IdentityServer/IdentityResources/IdentityResourceRepository.cs b/modules/identityserver/src/Volo.Abp.IdentityServer.EntityFrameworkCore/Volo/Abp/IdentityServer/IdentityResources/IdentityResourceRepository.cs index 6ddf38e2db..1b83b46158 100644 --- a/modules/identityserver/src/Volo.Abp.IdentityServer.EntityFrameworkCore/Volo/Abp/IdentityServer/IdentityResources/IdentityResourceRepository.cs +++ b/modules/identityserver/src/Volo.Abp.IdentityServer.EntityFrameworkCore/Volo/Abp/IdentityServer/IdentityResources/IdentityResourceRepository.cs @@ -24,22 +24,28 @@ namespace Volo.Abp.IdentityServer.IdentityResources bool includeDetails = false, CancellationToken cancellationToken = default) { - var query = from identityResource in DbSet.IncludeDetails(includeDetails) + var query = from identityResource in (await GetDbSetAsync()).IncludeDetails(includeDetails) where scopeNames.Contains(identityResource.Name) select identityResource; return await query.ToListAsync(GetCancellationToken(cancellationToken)); } + [Obsolete("Use WithDetailsAsync method.")] public override IQueryable WithDetails() { return GetQueryable().IncludeDetails(); } + public override async Task> WithDetailsAsync() + { + return (await GetQueryableAsync()).IncludeDetails(); + } + public virtual async Task> GetListAsync(string sorting, int skipCount, int maxResultCount, string filter, bool includeDetails = false, CancellationToken cancellationToken = default) { - return await DbSet + return await (await GetDbSetAsync()) .IncludeDetails(includeDetails) .WhereIf(!filter.IsNullOrWhiteSpace(), x => x.Name.Contains(filter) || x.Description.Contains(filter) || @@ -54,7 +60,7 @@ namespace Volo.Abp.IdentityServer.IdentityResources bool includeDetails = true, CancellationToken cancellationToken = default) { - return await DbSet + return await (await GetDbSetAsync()) .IncludeDetails(includeDetails) .Where(x => x.Name == name) .OrderBy(x => x.Id) @@ -63,7 +69,7 @@ namespace Volo.Abp.IdentityServer.IdentityResources public virtual async Task CheckNameExistAsync(string name, Guid? expectedId = null, CancellationToken cancellationToken = default) { - return await DbSet.AnyAsync(ir => ir.Id != expectedId && ir.Name == name, cancellationToken: cancellationToken); + return await (await GetDbSetAsync()).AnyAsync(ir => ir.Id != expectedId && ir.Name == name, cancellationToken: cancellationToken); } } } diff --git a/modules/permission-management/src/Volo.Abp.PermissionManagement.EntityFrameworkCore/Volo/Abp/PermissionManagement/EntityFrameworkCore/EfCorePermissionGrantRepository.cs b/modules/permission-management/src/Volo.Abp.PermissionManagement.EntityFrameworkCore/Volo/Abp/PermissionManagement/EntityFrameworkCore/EfCorePermissionGrantRepository.cs index 5a479c348b..bc0ea04cf2 100644 --- a/modules/permission-management/src/Volo.Abp.PermissionManagement.EntityFrameworkCore/Volo/Abp/PermissionManagement/EntityFrameworkCore/EfCorePermissionGrantRepository.cs +++ b/modules/permission-management/src/Volo.Abp.PermissionManagement.EntityFrameworkCore/Volo/Abp/PermissionManagement/EntityFrameworkCore/EfCorePermissionGrantRepository.cs @@ -24,7 +24,7 @@ namespace Volo.Abp.PermissionManagement.EntityFrameworkCore string providerKey, CancellationToken cancellationToken = default) { - return await DbSet + return await (await GetDbSetAsync()) .OrderBy(x => x.Id) .FirstOrDefaultAsync(s => s.Name == name && @@ -39,7 +39,7 @@ namespace Volo.Abp.PermissionManagement.EntityFrameworkCore string providerKey, CancellationToken cancellationToken = default) { - return await DbSet + return await (await GetDbSetAsync()) .Where(s => s.ProviderName == providerName && s.ProviderKey == providerKey @@ -49,7 +49,7 @@ namespace Volo.Abp.PermissionManagement.EntityFrameworkCore public virtual async Task> GetListAsync(string[] names, string providerName, string providerKey, CancellationToken cancellationToken = default) { - return await DbSet + return await (await GetDbSetAsync()) .Where(s => names.Contains(s.Name) && s.ProviderName == providerName && diff --git a/modules/permission-management/src/Volo.Abp.PermissionManagement.MongoDB/Volo/Abp/PermissionManagement/MongoDb/MongoPermissionGrantRepository.cs b/modules/permission-management/src/Volo.Abp.PermissionManagement.MongoDB/Volo/Abp/PermissionManagement/MongoDb/MongoPermissionGrantRepository.cs index a8f95ee6b9..823d5e63a3 100644 --- a/modules/permission-management/src/Volo.Abp.PermissionManagement.MongoDB/Volo/Abp/PermissionManagement/MongoDb/MongoPermissionGrantRepository.cs +++ b/modules/permission-management/src/Volo.Abp.PermissionManagement.MongoDB/Volo/Abp/PermissionManagement/MongoDb/MongoPermissionGrantRepository.cs @@ -24,13 +24,14 @@ namespace Volo.Abp.PermissionManagement.MongoDB string providerKey, CancellationToken cancellationToken = default) { - return await GetMongoQueryable() + cancellationToken = GetCancellationToken(cancellationToken); + return await (await GetMongoQueryableAsync(cancellationToken)) .OrderBy(x => x.Id) .FirstOrDefaultAsync(s => s.Name == name && s.ProviderName == providerName && s.ProviderKey == providerKey, - GetCancellationToken(cancellationToken) + cancellationToken ); } @@ -39,22 +40,24 @@ namespace Volo.Abp.PermissionManagement.MongoDB string providerKey, CancellationToken cancellationToken = default) { - return await GetMongoQueryable() + cancellationToken = GetCancellationToken(cancellationToken); + return await (await GetMongoQueryableAsync(cancellationToken)) .Where(s => s.ProviderName == providerName && s.ProviderKey == providerKey - ).ToListAsync(GetCancellationToken(cancellationToken)); + ).ToListAsync(cancellationToken); } public virtual async Task> GetListAsync(string[] names, string providerName, string providerKey, CancellationToken cancellationToken = default) { - return await GetMongoQueryable() + cancellationToken = GetCancellationToken(cancellationToken); + return await (await GetMongoQueryableAsync(cancellationToken)) .Where(s => names.Contains(s.Name) && s.ProviderName == providerName && s.ProviderKey == providerKey - ).ToListAsync(GetCancellationToken(cancellationToken)); + ).ToListAsync(cancellationToken); } } } diff --git a/modules/setting-management/src/Volo.Abp.SettingManagement.EntityFrameworkCore/Volo/Abp/SettingManagement/EntityFrameworkCore/EfCoreSettingRepository.cs b/modules/setting-management/src/Volo.Abp.SettingManagement.EntityFrameworkCore/Volo/Abp/SettingManagement/EntityFrameworkCore/EfCoreSettingRepository.cs index c3323f331e..e90d2fc63a 100644 --- a/modules/setting-management/src/Volo.Abp.SettingManagement.EntityFrameworkCore/Volo/Abp/SettingManagement/EntityFrameworkCore/EfCoreSettingRepository.cs +++ b/modules/setting-management/src/Volo.Abp.SettingManagement.EntityFrameworkCore/Volo/Abp/SettingManagement/EntityFrameworkCore/EfCoreSettingRepository.cs @@ -17,7 +17,7 @@ namespace Volo.Abp.SettingManagement.EntityFrameworkCore public virtual async Task FindAsync(string name, string providerName, string providerKey) { - return await DbSet + return await (await GetDbSetAsync()) .OrderBy(x => x.Id) .FirstOrDefaultAsync( s => s.Name == name && s.ProviderName == providerName && s.ProviderKey == providerKey @@ -26,7 +26,7 @@ namespace Volo.Abp.SettingManagement.EntityFrameworkCore public virtual async Task> GetListAsync(string providerName, string providerKey) { - return await DbSet + return await (await GetDbSetAsync()) .Where( s => s.ProviderName == providerName && s.ProviderKey == providerKey ).ToListAsync(); @@ -34,7 +34,7 @@ namespace Volo.Abp.SettingManagement.EntityFrameworkCore public virtual async Task> GetListAsync(string[] names, string providerName, string providerKey) { - return await DbSet + return await (await GetDbSetAsync()) .Where( s => names.Contains(s.Name) && s.ProviderName == providerName && s.ProviderKey == providerKey ).ToListAsync(); diff --git a/modules/setting-management/src/Volo.Abp.SettingManagement.MongoDB/Volo/Abp/SettingManagement/MongoDB/MongoSettingRepository.cs b/modules/setting-management/src/Volo.Abp.SettingManagement.MongoDB/Volo/Abp/SettingManagement/MongoDB/MongoSettingRepository.cs index 1acaf50d56..e81e76dfcc 100644 --- a/modules/setting-management/src/Volo.Abp.SettingManagement.MongoDB/Volo/Abp/SettingManagement/MongoDB/MongoSettingRepository.cs +++ b/modules/setting-management/src/Volo.Abp.SettingManagement.MongoDB/Volo/Abp/SettingManagement/MongoDB/MongoSettingRepository.cs @@ -19,17 +19,23 @@ namespace Volo.Abp.SettingManagement.MongoDB public virtual async Task FindAsync(string name, string providerName, string providerKey) { - return await GetMongoQueryable().OrderBy(x => x.Id).FirstOrDefaultAsync(s => s.Name == name && s.ProviderName == providerName && s.ProviderKey == providerKey); + return await (await GetMongoQueryableAsync()) + .OrderBy(x => x.Id) + .FirstOrDefaultAsync(s => s.Name == name && s.ProviderName == providerName && s.ProviderKey == providerKey); } public virtual async Task> GetListAsync(string providerName, string providerKey) { - return await GetMongoQueryable().Where(s => s.ProviderName == providerName && s.ProviderKey == providerKey).ToListAsync(); + return await (await GetMongoQueryableAsync()) + .Where(s => s.ProviderName == providerName && s.ProviderKey == providerKey) + .ToListAsync(); } public virtual async Task> GetListAsync(string[] names, string providerName, string providerKey) { - return await GetMongoQueryable().Where(s => names.Contains(s.Name) && s.ProviderName == providerName && s.ProviderKey == providerKey).ToListAsync(); + return await (await GetMongoQueryableAsync()) + .Where(s => names.Contains(s.Name) && s.ProviderName == providerName && s.ProviderKey == providerKey) + .ToListAsync(); } } } diff --git a/modules/users/src/Volo.Abp.Users.EntityFrameworkCore/Volo/Abp/Users/EntityFrameworkCore/EfCoreAbpUserRepositoryBase.cs b/modules/users/src/Volo.Abp.Users.EntityFrameworkCore/Volo/Abp/Users/EntityFrameworkCore/EfCoreAbpUserRepositoryBase.cs index 87a8fbc507..de27a05fbd 100644 --- a/modules/users/src/Volo.Abp.Users.EntityFrameworkCore/Volo/Abp/Users/EntityFrameworkCore/EfCoreAbpUserRepositoryBase.cs +++ b/modules/users/src/Volo.Abp.Users.EntityFrameworkCore/Volo/Abp/Users/EntityFrameworkCore/EfCoreAbpUserRepositoryBase.cs @@ -27,7 +27,9 @@ namespace Volo.Abp.Users.EntityFrameworkCore public virtual async Task> GetListAsync(IEnumerable ids, CancellationToken cancellationToken = default) { - return await DbSet.Where(u => ids.Contains(u.Id)).ToListAsync(GetCancellationToken(cancellationToken)); + return await (await GetDbSetAsync()) + .Where(u => ids.Contains(u.Id)) + .ToListAsync(GetCancellationToken(cancellationToken)); } public async Task> SearchAsync( @@ -37,7 +39,7 @@ namespace Volo.Abp.Users.EntityFrameworkCore string filter = null, CancellationToken cancellationToken = default) { - return await DbSet + return await (await GetDbSetAsync()) .WhereIf( !filter.IsNullOrWhiteSpace(), u => @@ -55,7 +57,7 @@ namespace Volo.Abp.Users.EntityFrameworkCore string filter = null, CancellationToken cancellationToken = default) { - return await DbSet + return await (await GetDbSetAsync()) .WhereIf( !filter.IsNullOrWhiteSpace(), u => diff --git a/modules/users/src/Volo.Abp.Users.MongoDB/Volo/Abp/Users/MongoDB/MongoUserRepositoryBase.cs b/modules/users/src/Volo.Abp.Users.MongoDB/Volo/Abp/Users/MongoDB/MongoUserRepositoryBase.cs index cf4d860def..996b6e314c 100644 --- a/modules/users/src/Volo.Abp.Users.MongoDB/Volo/Abp/Users/MongoDB/MongoUserRepositoryBase.cs +++ b/modules/users/src/Volo.Abp.Users.MongoDB/Volo/Abp/Users/MongoDB/MongoUserRepositoryBase.cs @@ -23,12 +23,18 @@ namespace Volo.Abp.Users.MongoDB public virtual async Task FindByUserNameAsync(string userName, CancellationToken cancellationToken = default) { - return await GetMongoQueryable().OrderBy(x => x.Id).FirstOrDefaultAsync(u => u.UserName == userName, GetCancellationToken(cancellationToken)); + cancellationToken = GetCancellationToken(cancellationToken); + return await (await GetMongoQueryableAsync(cancellationToken)) + .OrderBy(x => x.Id) + .FirstOrDefaultAsync(u => u.UserName == userName, cancellationToken); } public virtual async Task> GetListAsync(IEnumerable ids, CancellationToken cancellationToken = default) { - return await GetMongoQueryable().Where(u => ids.Contains(u.Id)).ToListAsync(GetCancellationToken(cancellationToken)); + cancellationToken = GetCancellationToken(cancellationToken); + return await (await GetMongoQueryableAsync(cancellationToken)) + .Where(u => ids.Contains(u.Id)) + .ToListAsync(cancellationToken); } public async Task> SearchAsync( @@ -38,7 +44,8 @@ namespace Volo.Abp.Users.MongoDB string filter = null, CancellationToken cancellationToken = default) { - return await GetMongoQueryable() + cancellationToken = GetCancellationToken(cancellationToken); + return await (await GetMongoQueryableAsync(cancellationToken)) .WhereIf>( !filter.IsNullOrWhiteSpace(), u => @@ -50,12 +57,13 @@ namespace Volo.Abp.Users.MongoDB .OrderBy(sorting ?? nameof(IUserData.UserName)) .As>() .PageBy>(skipCount, maxResultCount) - .ToListAsync(GetCancellationToken(cancellationToken)); + .ToListAsync(cancellationToken); } public async Task GetCountAsync(string filter = null, CancellationToken cancellationToken = default) { - return await GetMongoQueryable() + cancellationToken = GetCancellationToken(cancellationToken); + return await (await GetMongoQueryableAsync(cancellationToken)) .WhereIf>( !filter.IsNullOrWhiteSpace(), u => @@ -64,7 +72,7 @@ namespace Volo.Abp.Users.MongoDB u.Name.Contains(filter) || u.Surname.Contains(filter) ) - .LongCountAsync(GetCancellationToken(cancellationToken)); + .LongCountAsync(cancellationToken); } } }