diff --git a/Directory.Packages.props b/Directory.Packages.props index 3e8410e9c4..8cd134d1d8 100644 --- a/Directory.Packages.props +++ b/Directory.Packages.props @@ -37,6 +37,10 @@ + + + + @@ -111,7 +115,7 @@ - + diff --git a/build/common.ps1 b/build/common.ps1 index 85f18edb21..51ab56d972 100644 --- a/build/common.ps1 +++ b/build/common.ps1 @@ -34,11 +34,13 @@ if ($full -eq "-f") "../templates/module/aspnet-core", "../templates/app/aspnet-core", "../templates/console", - "../templates/wpf", "../templates/app-nolayers/aspnet-core", "../abp_io/AbpIoLocalization", "../source-code" - ) + ) + if ($env:OS -eq "Windows_NT") { + $solutionPaths += "../templates/wpf" + } }else{ Write-host "" Write-host ":::::::::::::: !!! You are in development mode !!! ::::::::::::::" -ForegroundColor red -BackgroundColor yellow diff --git a/docs/en/framework/architecture/best-practices/mongodb-integration.md b/docs/en/framework/architecture/best-practices/mongodb-integration.md index 1930984e2e..c39f6443a0 100644 --- a/docs/en/framework/architecture/best-practices/mongodb-integration.md +++ b/docs/en/framework/architecture/best-practices/mongodb-integration.md @@ -114,7 +114,7 @@ public async Task FindByNormalizedUserNameAsync( bool includeDetails = true, CancellationToken cancellationToken = default) { - return await (await GetMongoQueryableAsync()) + return await (await GetQueryableAsync()) .FirstOrDefaultAsync( u => u.NormalizedUserName == normalizedUserName, GetCancellationToken(cancellationToken) @@ -125,10 +125,10 @@ public async Task FindByNormalizedUserNameAsync( `GetCancellationToken` fallbacks to the `ICancellationTokenProvider.Token` to obtain the cancellation token if it is not provided by the caller code. * **Do** ignore the `includeDetails` parameters for the repository implementation since MongoDB loads the aggregate root as a whole (including sub collections) by default. -* **Do** use the `GetMongoQueryableAsync()` method to obtain an `IQueryable` to perform queries wherever possible. Because; - * `GetMongoQueryableAsync()` method automatically uses the `ApplyDataFilters` method to filter the data based on the current data filters (like soft delete and multi-tenancy). +* **Do** use the `GetQueryableAsync()` method to obtain an `IQueryable` to perform queries wherever possible. Because; + * `GetQueryableAsync()` method automatically uses the `ApplyDataFilters` method to filter the data based on the current data filters (like soft delete and multi-tenancy). * Using `IQueryable` makes the code as much as similar to the EF Core repository implementation and easy to write and read. -* **Do** implement data filtering if it is not possible to use the `GetMongoQueryable()` method. +* **Do** implement data filtering if it is not possible to use the `GetQueryableAsync()` method. ## Module Class diff --git a/docs/en/framework/architecture/domain-driven-design/repositories.md b/docs/en/framework/architecture/domain-driven-design/repositories.md index 9050e7d3c3..04848a59e8 100644 --- a/docs/en/framework/architecture/domain-driven-design/repositories.md +++ b/docs/en/framework/architecture/domain-driven-design/repositories.md @@ -393,19 +393,6 @@ This method is suggested; * If you are developing an application and you **don't plan to change** EF Core in the future, or you can **tolerate** it if you need to change it later. We believe that's reasonable if you are developing a final application. -#### MongoDB Case - -If you are using [MongoDB](../../data/mongodb), you need to add the [Volo.Abp.MongoDB](https://www.nuget.org/packages/Volo.Abp.MongoDB) NuGet package to your project. Even in this case, you can't directly use async LINQ extensions (like `ToListAsync`) because MongoDB doesn't provide async extension methods for `IQueryable`, but provides for `IMongoQueryable`. You need to cast the query to `IMongoQueryable` first to be able to use the async extension methods. - -**Example: Cast `IQueryable` to `IMongoQueryable` and use `ToListAsync()`** - -````csharp -var queryable = await _personRepository.GetQueryableAsync(); -var people = ((IMongoQueryable) queryable - .Where(p => p.Name.Contains(nameFilter))) - .ToListAsync(); -```` - ### Option-2: Use the IRepository Async Extension Methods ABP provides async extension methods for the repositories, just similar to async LINQ extension methods. diff --git a/docs/en/guides/microservice-mongodb.md b/docs/en/guides/microservice-mongodb.md index c9b63ecf4e..087668ba7a 100644 --- a/docs/en/guides/microservice-mongodb.md +++ b/docs/en/guides/microservice-mongodb.md @@ -97,9 +97,9 @@ Here we use `BookStore.ProductService` project as an example: int skipCount = 0, CancellationToken cancellationToken = default) { - var query = ApplyFilter(await GetMongoQueryableAsync(cancellationToken), filterText, name, priceMin, priceMax); + var query = ApplyFilter(await GetQueryableAsync(cancellationToken), filterText, name, priceMin, priceMax); query = query.OrderBy(string.IsNullOrWhiteSpace(sorting) ? ProductConsts.GetDefaultSorting(false) : sorting); - return await query.As>().PageBy>(skipCount, maxResultCount).ToListAsync(cancellationToken); + return await query.PageBy(skipCount, maxResultCount).ToListAsync(cancellationToken); } public async Task GetCountAsync( @@ -109,8 +109,8 @@ Here we use `BookStore.ProductService` project as an example: float? priceMax = null, CancellationToken cancellationToken = default) { - var query = ApplyFilter(await GetMongoQueryableAsync(cancellationToken), filterText, name, priceMin, priceMax); - return await query.As>().LongCountAsync(GetCancellationToken(cancellationToken)); + var query = ApplyFilter(await GetQueryableAsync(cancellationToken), filterText, name, priceMin, priceMax); + return await query.LongCountAsync(GetCancellationToken(cancellationToken)); } protected virtual IQueryable ApplyFilter( diff --git a/docs/en/release-info/migration-guides/MongoDB-Driver-2-to-3.md b/docs/en/release-info/migration-guides/MongoDB-Driver-2-to-3.md new file mode 100644 index 0000000000..79c0d70573 --- /dev/null +++ b/docs/en/release-info/migration-guides/MongoDB-Driver-2-to-3.md @@ -0,0 +1,59 @@ +# Migrating from MongoDB Driver 2 to 3 + +## Introduction + +The release of MongoDB Driver 3 includes numerous user-requested fixes and improvements that were deferred in previous versions due to backward compatibility concerns. It also features internal improvements to reduce technical debt and enhance maintainability. One major update is the removal of a significant portion of the public API (primarily from `MongoDB.Driver.Core`), which was not intended for public use. The removed APIs were marked as deprecated in version 2.30.0. + +Please refer to the [upgrade guide](https://www.mongodb.com/docs/drivers/csharp/current/upgrade/v3/) for a complete list of breaking changes and upgrade guidelines. + +## Repository Changes + +Some method signatures in the `MongoDbRepository` class have been updated because the `IMongoQueryable` has been removed. The specific changes are as follows: + +- The new `GetQueryableAsync` method has been added to return `IQueryable`. +- The `GetMongoQueryable` and `GetMongoQueryableAsync` methods return `IQueryable` instead of `IMongoQueryable`, +- The `GetMongoQueryable` and `GetMongoQueryableAsync` methods are marked as obsolete, You should use the new `GetQueryableAsync` method instead. + +Please update your application by searching for and replacing these method calls. + +> The return value of the `GetQueryableAsync` method is `IQueryable`, which can be used directly to perform queries, similar to EF Core. Remove all instances of `IMongoQueryable` in your project and replace them with `IQueryable`. + +**Previous code example:** + +```csharp +var myEntity = await (await GetMongoQueryableAsync()).As>().FirstOrDefaultAsync(x => x.Id == id); +``` + +**Updated code example:** + +```csharp +var myEntity = await GetQueryableAsync().FirstOrDefaultAsync(x => x.Id == id); +``` + +## Unit Test Changes + +Previously, we used the [EphemeralMongo](https://github.com/asimmon/ephemeral-mongo) library for unit testing. However, it does not support the latest version of [MongoDB.Driver 3.x](https://github.com/mongodb/mongo-go-driver). You should replace it with [MongoSandbox](https://github.com/wassim-k/MongoSandbox). + +In your unit test project files, replace the following: + +```xml + + + + +``` + +With: + +```xml + + + + +``` + +In your unit test classes, replace `using EphemeralMongo` with `using MongoSandbox`. + +## Official Upgrade Guide + +We recommend reviewing the [upgrade guide](https://www.mongodb.com/docs/drivers/csharp/current/upgrade/v3/) for MongoDB Driver 3 to ensure a smooth migration process. diff --git a/docs/en/tutorials/book-store/part-07.md b/docs/en/tutorials/book-store/part-07.md index 0708ecfcb9..92108c4a35 100644 --- a/docs/en/tutorials/book-store/part-07.md +++ b/docs/en/tutorials/book-store/part-07.md @@ -180,7 +180,7 @@ public class MongoDbAuthorRepository public async Task FindByNameAsync(string name) { - var queryable = await GetMongoQueryableAsync(); + var queryable = await GetQueryableAsync(); return await queryable.FirstOrDefaultAsync(author => author.Name == name); } @@ -190,14 +190,13 @@ public class MongoDbAuthorRepository string sorting, string filter = null) { - var queryable = await GetMongoQueryableAsync(); + var queryable = await GetQueryableAsync(); return await queryable - .WhereIf>( + .WhereIf>( !filter.IsNullOrWhiteSpace(), author => author.Name.Contains(filter) ) .OrderBy(sorting) - .As>() .Skip(skipCount) .Take(maxResultCount) .ToListAsync(); diff --git a/framework/src/Volo.Abp.MongoDB/Volo/Abp/Domain/Repositories/MongoDB/IMongoDbRepository.cs b/framework/src/Volo.Abp.MongoDB/Volo/Abp/Domain/Repositories/MongoDB/IMongoDbRepository.cs index a687ba2bf9..acd905b8c6 100644 --- a/framework/src/Volo.Abp.MongoDB/Volo/Abp/Domain/Repositories/MongoDB/IMongoDbRepository.cs +++ b/framework/src/Volo.Abp.MongoDB/Volo/Abp/Domain/Repositories/MongoDB/IMongoDbRepository.cs @@ -1,8 +1,8 @@ using System; +using System.Linq; using System.Threading; using System.Threading.Tasks; using MongoDB.Driver; -using MongoDB.Driver.Linq; using Volo.Abp.Domain.Entities; namespace Volo.Abp.Domain.Repositories.MongoDB; @@ -20,10 +20,13 @@ public interface IMongoDbRepository : IRepository Task> GetCollectionAsync(CancellationToken cancellationToken = default); - [Obsolete("Use GetMongoQueryableAsync method.")] - IMongoQueryable GetMongoQueryable(); + [Obsolete("Use GetQueryable method.")] + IQueryable GetMongoQueryable(); - Task> GetMongoQueryableAsync(CancellationToken cancellationToken = default, AggregateOptions? options = null); + [Obsolete("Use GetQueryableAsync method.")] + Task> GetMongoQueryableAsync(CancellationToken cancellationToken = default, AggregateOptions? options = null); + + Task> GetQueryableAsync(CancellationToken cancellationToken = default, AggregateOptions? options = null); Task> GetAggregateAsync(CancellationToken cancellationToken = default, AggregateOptions? options = null); } diff --git a/framework/src/Volo.Abp.MongoDB/Volo/Abp/Domain/Repositories/MongoDB/MongoDbRepository.cs b/framework/src/Volo.Abp.MongoDB/Volo/Abp/Domain/Repositories/MongoDB/MongoDbRepository.cs index 45629f76e5..fdc7464d6b 100644 --- a/framework/src/Volo.Abp.MongoDB/Volo/Abp/Domain/Repositories/MongoDB/MongoDbRepository.cs +++ b/framework/src/Volo.Abp.MongoDB/Volo/Abp/Domain/Repositories/MongoDB/MongoDbRepository.cs @@ -455,19 +455,19 @@ public class MongoDbRepository public async override Task> GetListAsync(bool includeDetails = false, CancellationToken cancellationToken = default) { cancellationToken = GetCancellationToken(cancellationToken); - return await (await GetMongoQueryableAsync(cancellationToken)).ToListAsync(cancellationToken); + return await (await GetQueryableAsync(cancellationToken)).ToListAsync(cancellationToken); } public async override Task> GetListAsync(Expression> predicate, bool includeDetails = false, CancellationToken cancellationToken = default) { cancellationToken = GetCancellationToken(cancellationToken); - return await (await GetMongoQueryableAsync(cancellationToken)).Where(predicate).ToListAsync(cancellationToken); + return await (await GetQueryableAsync(cancellationToken)).Where(predicate).ToListAsync(cancellationToken); } public async override Task GetCountAsync(CancellationToken cancellationToken = default) { cancellationToken = GetCancellationToken(cancellationToken); - return await (await GetMongoQueryableAsync(cancellationToken)).LongCountAsync(cancellationToken); + return await (await GetQueryableAsync(cancellationToken)).LongCountAsync(cancellationToken); } public async override Task> GetPagedListAsync( @@ -479,10 +479,9 @@ public class MongoDbRepository { cancellationToken = GetCancellationToken(cancellationToken); - return await (await GetMongoQueryableAsync(cancellationToken)) + return await (await GetQueryableAsync(cancellationToken)) .OrderByIf>(!sorting.IsNullOrWhiteSpace(), sorting) - .As>() - .PageBy>(skipCount, maxResultCount) + .PageBy>(skipCount, maxResultCount) .ToListAsync(cancellationToken); } @@ -493,14 +492,14 @@ public class MongoDbRepository { cancellationToken = GetCancellationToken(cancellationToken); - var entities = await (await GetMongoQueryableAsync(cancellationToken)) + var entities = await (await GetQueryableAsync(cancellationToken)) .Where(predicate) .ToListAsync(cancellationToken); await DeleteManyAsync(entities, autoSave, cancellationToken); } - public override async Task DeleteDirectAsync(Expression> predicate, CancellationToken cancellationToken = default) + public async override Task DeleteDirectAsync(Expression> predicate, CancellationToken cancellationToken = default) { cancellationToken = GetCancellationToken(cancellationToken); @@ -527,12 +526,16 @@ public class MongoDbRepository [Obsolete("Use GetQueryableAsync method.")] protected override IQueryable GetQueryable() { - return GetMongoQueryable(); + return ApplyDataFilters( + SessionHandle != null + ? Collection.AsQueryable(SessionHandle) + : Collection.AsQueryable() + ); } public async override Task> GetQueryableAsync() { - return await GetMongoQueryableAsync(); + return await GetQueryableAsync(); } public async override Task FindAsync( @@ -542,34 +545,36 @@ public class MongoDbRepository { cancellationToken = GetCancellationToken(cancellationToken); - return await (await GetMongoQueryableAsync(cancellationToken)) + return await (await GetQueryableAsync(cancellationToken)) .Where(predicate) .SingleOrDefaultAsync(cancellationToken); } - [Obsolete("Use GetMongoQueryableAsync method.")] - public virtual IMongoQueryable GetMongoQueryable() + [Obsolete("Use GetQueryableAsync method.")] + public virtual IQueryable GetMongoQueryable() { - return ApplyDataFilters( - SessionHandle != null - ? Collection.AsQueryable(SessionHandle) - : Collection.AsQueryable() - ); + return GetQueryable(); + } + + [Obsolete("Use GetQueryableAsync method.")] + public virtual Task> GetMongoQueryableAsync(CancellationToken cancellationToken = default, AggregateOptions? options = null) + { + return GetQueryableAsync(cancellationToken, options); } - public virtual Task> GetMongoQueryableAsync(CancellationToken cancellationToken = default, AggregateOptions? aggregateOptions = null) + public virtual async Task> GetQueryableAsync(CancellationToken cancellationToken = default, AggregateOptions? options = null) { - return GetMongoQueryableAsync(cancellationToken, aggregateOptions); + return await GetQueryableAsync(cancellationToken, options); } - protected virtual async Task> GetMongoQueryableAsync(CancellationToken cancellationToken = default, AggregateOptions? aggregateOptions = null) + protected virtual async Task> GetQueryableAsync(CancellationToken cancellationToken = default, AggregateOptions? aggregateOptions = null) { cancellationToken = GetCancellationToken(cancellationToken); var dbContext = await GetDbContextAsync(cancellationToken); var collection = dbContext.Collection(); - return ApplyDataFilters, TOtherEntity>( + return ApplyDataFilters, TOtherEntity>( dbContext.SessionHandle != null ? collection.AsQueryable(dbContext.SessionHandle, aggregateOptions) : collection.AsQueryable(aggregateOptions) @@ -810,7 +815,7 @@ public class MongoDbRepository { cancellationToken = GetCancellationToken(cancellationToken); - return await (await GetMongoQueryableAsync(cancellationToken)) + return await (await GetQueryableAsync(cancellationToken)) .Where(x => x.Id!.Equals(id)) .FirstOrDefaultAsync(cancellationToken); } @@ -827,7 +832,7 @@ public class MongoDbRepository { cancellationToken = GetCancellationToken(cancellationToken); - var entities = await (await GetMongoQueryableAsync(cancellationToken)) + var entities = await (await GetQueryableAsync(cancellationToken)) .Where(x => ids.Contains(x.Id)) .ToListAsync(cancellationToken); diff --git a/framework/src/Volo.Abp.MongoDB/Volo/Abp/Domain/Repositories/MongoDbCoreRepositoryExtensions.cs b/framework/src/Volo.Abp.MongoDB/Volo/Abp/Domain/Repositories/MongoDbCoreRepositoryExtensions.cs index 676450a5b8..353185c8e3 100644 --- a/framework/src/Volo.Abp.MongoDB/Volo/Abp/Domain/Repositories/MongoDbCoreRepositoryExtensions.cs +++ b/framework/src/Volo.Abp.MongoDB/Volo/Abp/Domain/Repositories/MongoDbCoreRepositoryExtensions.cs @@ -1,8 +1,8 @@ using System; +using System.Linq; using System.Threading; using System.Threading.Tasks; using MongoDB.Driver; -using MongoDB.Driver.Linq; using Volo.Abp.Domain.Entities; using Volo.Abp.Domain.Repositories.MongoDB; @@ -36,19 +36,26 @@ public static class MongoDbCoreRepositoryExtensions return repository.ToMongoDbRepository().GetCollectionAsync(cancellationToken); } - [Obsolete("Use GetMongoQueryableAsync method.")] - public static IMongoQueryable GetMongoQueryable(this IReadOnlyBasicRepository repository) + [Obsolete("Use GetQueryableAsync method.")] + public static IQueryable GetMongoQueryable(this IReadOnlyBasicRepository repository) where TEntity : class, IEntity { return repository.ToMongoDbRepository().GetMongoQueryable(); } - public static Task> GetMongoQueryableAsync(this IReadOnlyBasicRepository repository, CancellationToken cancellationToken = default, AggregateOptions? aggregateOptions = null) + [Obsolete("Use GetQueryableAsync method.")] + public static Task> GetMongoQueryableAsync(this IReadOnlyBasicRepository repository, CancellationToken cancellationToken = default, AggregateOptions? aggregateOptions = null) where TEntity : class, IEntity { return repository.ToMongoDbRepository().GetMongoQueryableAsync(cancellationToken, aggregateOptions); } + public static Task> GetQueryableAsync(this IReadOnlyBasicRepository repository) + where TEntity : class, IEntity + { + return repository.ToMongoDbRepository().GetQueryableAsync(); + } + public static Task> GetAggregateAsync(this IReadOnlyBasicRepository repository, CancellationToken cancellationToken = default, AggregateOptions? aggregateOptions = null) where TEntity : class, IEntity { diff --git a/framework/src/Volo.Abp.MongoDB/Volo/Abp/MongoDB/AbpMongoDbDateTimeSerializer.cs b/framework/src/Volo.Abp.MongoDB/Volo/Abp/MongoDB/AbpMongoDbDateTimeSerializer.cs index c1d8b8f514..6ad2b0b359 100644 --- a/framework/src/Volo.Abp.MongoDB/Volo/Abp/MongoDB/AbpMongoDbDateTimeSerializer.cs +++ b/framework/src/Volo.Abp.MongoDB/Volo/Abp/MongoDB/AbpMongoDbDateTimeSerializer.cs @@ -5,7 +5,7 @@ using MongoDB.Bson.Serialization.Serializers; namespace Volo.Abp.MongoDB; -public class AbpMongoDbDateTimeSerializer : DateTimeSerializer +public class AbpMongoDbDateTimeSerializer : StructSerializerBase { protected DateTimeKind DateTimeKind { get; set; } protected bool DisableDateTimeNormalization { get; set; } diff --git a/framework/src/Volo.Abp.MongoDB/Volo/Abp/MongoDB/AbpMongoDbModule.cs b/framework/src/Volo.Abp.MongoDB/Volo/Abp/MongoDB/AbpMongoDbModule.cs index f61e9ddb45..91d2808010 100644 --- a/framework/src/Volo.Abp.MongoDB/Volo/Abp/MongoDB/AbpMongoDbModule.cs +++ b/framework/src/Volo.Abp.MongoDB/Volo/Abp/MongoDB/AbpMongoDbModule.cs @@ -1,5 +1,8 @@ using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.DependencyInjection.Extensions; +using MongoDB.Bson; +using MongoDB.Bson.Serialization; +using MongoDB.Bson.Serialization.Serializers; using Volo.Abp.Domain; using Volo.Abp.Domain.Repositories.MongoDB; using Volo.Abp.Modularity; @@ -19,6 +22,8 @@ public class AbpMongoDbModule : AbpModule public override void ConfigureServices(ServiceConfigurationContext context) { + BsonSerializer.TryRegisterSerializer(new GuidSerializer(GuidRepresentation.Standard)); + context.Services.TryAddTransient( typeof(IMongoDbContextProvider<>), typeof(UnitOfWorkMongoDbContextProvider<>) diff --git a/framework/src/Volo.Abp.MongoDB/Volo/Abp/MongoDB/DistributedEvents/MongoDbContextEventInbox.cs b/framework/src/Volo.Abp.MongoDB/Volo/Abp/MongoDB/DistributedEvents/MongoDbContextEventInbox.cs index 6a73af27f5..9d1b706d8b 100644 --- a/framework/src/Volo.Abp.MongoDB/Volo/Abp/MongoDB/DistributedEvents/MongoDbContextEventInbox.cs +++ b/framework/src/Volo.Abp.MongoDB/Volo/Abp/MongoDB/DistributedEvents/MongoDbContextEventInbox.cs @@ -68,7 +68,6 @@ public class MongoDbContextEventInbox : IMongoDbContextEventInb .WhereIf(transformedFilter != null, transformedFilter!) .OrderBy(x => x.CreationTime) .Take(maxCount) - .As>() .ToListAsync(cancellationToken: cancellationToken); return outgoingEventRecords diff --git a/framework/src/Volo.Abp.MongoDB/Volo/Abp/MongoDB/DistributedEvents/MongoDbContextEventOutbox.cs b/framework/src/Volo.Abp.MongoDB/Volo/Abp/MongoDB/DistributedEvents/MongoDbContextEventOutbox.cs index 57b59038b5..6dc8817f02 100644 --- a/framework/src/Volo.Abp.MongoDB/Volo/Abp/MongoDB/DistributedEvents/MongoDbContextEventOutbox.cs +++ b/framework/src/Volo.Abp.MongoDB/Volo/Abp/MongoDB/DistributedEvents/MongoDbContextEventOutbox.cs @@ -56,7 +56,6 @@ public class MongoDbContextEventOutbox : IMongoDbContextEventOu .WhereIf(transformedFilter != null, transformedFilter!) .OrderBy(x => x.CreationTime) .Take(maxCount) - .As>() .ToListAsync(cancellationToken: cancellationToken); return outgoingEventRecords diff --git a/framework/src/Volo.Abp.MongoDB/Volo/Abp/MongoDB/MongoDbAsyncQueryableProvider.cs b/framework/src/Volo.Abp.MongoDB/Volo/Abp/MongoDB/MongoDbAsyncQueryableProvider.cs index 287f3ced0e..b7e896a27a 100644 --- a/framework/src/Volo.Abp.MongoDB/Volo/Abp/MongoDB/MongoDbAsyncQueryableProvider.cs +++ b/framework/src/Volo.Abp.MongoDB/Volo/Abp/MongoDB/MongoDbAsyncQueryableProvider.cs @@ -6,9 +6,7 @@ using System.Threading; using System.Threading.Tasks; using Volo.Abp.DependencyInjection; using Volo.Abp.Linq; -using MongoDB.Driver; using MongoDB.Driver.Linq; -using Volo.Abp.DynamicProxy; namespace Volo.Abp.MongoDB; @@ -16,344 +14,339 @@ public class MongoDbAsyncQueryableProvider : IAsyncQueryableProvider, ISingleton { public bool CanExecute(IQueryable queryable) { - return ProxyHelper.UnProxy(queryable) is IMongoQueryable; - } - - protected virtual IMongoQueryable GetMongoQueryable(IQueryable queryable) - { - return ProxyHelper.UnProxy(queryable).As>(); + return queryable.Provider is IMongoQueryProvider; } public Task ContainsAsync(IQueryable queryable, T item, CancellationToken cancellationToken = default) { - return Task.FromResult(GetMongoQueryable(queryable).Contains(item)); + return Task.FromResult(queryable.Contains(item)); } public Task AnyAsync(IQueryable queryable, CancellationToken cancellationToken = default) { - return GetMongoQueryable(queryable).AnyAsync(cancellationToken); + return queryable.AnyAsync(cancellationToken); } public Task AnyAsync(IQueryable queryable, Expression> predicate, CancellationToken cancellationToken = default) { - return GetMongoQueryable(queryable).AnyAsync(predicate, cancellationToken); + return queryable.AnyAsync(predicate, cancellationToken); } public Task AllAsync(IQueryable queryable, Expression> predicate, CancellationToken cancellationToken = default) { - return Task.FromResult(GetMongoQueryable(queryable).All(predicate)); + return Task.FromResult(queryable.All(predicate)); } public Task CountAsync(IQueryable queryable, CancellationToken cancellationToken = default) { - return GetMongoQueryable(queryable).CountAsync(cancellationToken); + return queryable.CountAsync(cancellationToken); } public Task CountAsync(IQueryable queryable, Expression> predicate, CancellationToken cancellationToken = default) { - return GetMongoQueryable(queryable).CountAsync(predicate, cancellationToken); + return queryable.CountAsync(predicate, cancellationToken); } public Task LongCountAsync(IQueryable queryable, CancellationToken cancellationToken = default) { - return GetMongoQueryable(queryable).LongCountAsync(cancellationToken); + return queryable.LongCountAsync(cancellationToken); } public Task LongCountAsync(IQueryable queryable, Expression> predicate, CancellationToken cancellationToken = default) { - return GetMongoQueryable(queryable).LongCountAsync(predicate, cancellationToken); + return queryable.LongCountAsync(predicate, cancellationToken); } public Task FirstAsync(IQueryable queryable, CancellationToken cancellationToken = default) { - return GetMongoQueryable(queryable).FirstAsync(cancellationToken); + return queryable.FirstAsync(cancellationToken); } public Task FirstAsync(IQueryable queryable, Expression> predicate, CancellationToken cancellationToken = default) { - return GetMongoQueryable(queryable).FirstAsync(predicate, cancellationToken); + return queryable.FirstAsync(predicate, cancellationToken); } public Task FirstOrDefaultAsync(IQueryable queryable, CancellationToken cancellationToken = default) { - return GetMongoQueryable(queryable).FirstOrDefaultAsync(cancellationToken)!; + return queryable.FirstOrDefaultAsync(cancellationToken)!; } public Task FirstOrDefaultAsync(IQueryable queryable, Expression> predicate, CancellationToken cancellationToken = default) { - return GetMongoQueryable(queryable).FirstOrDefaultAsync(predicate, cancellationToken)!; + return queryable.FirstOrDefaultAsync(predicate, cancellationToken)!; } public Task LastAsync(IQueryable queryable, CancellationToken cancellationToken = default) { - return Task.FromResult(GetMongoQueryable(queryable).Last()); + return Task.FromResult(queryable.Last()); } public Task LastAsync(IQueryable queryable, Expression> predicate, CancellationToken cancellationToken = default) { - return Task.FromResult(GetMongoQueryable(queryable).Last(predicate)); + return Task.FromResult(queryable.Last(predicate)); } public Task LastOrDefaultAsync(IQueryable queryable, CancellationToken cancellationToken = default) { - return Task.FromResult(GetMongoQueryable(queryable).LastOrDefault()); + return Task.FromResult(queryable.LastOrDefault()); } public Task LastOrDefaultAsync(IQueryable queryable, Expression> predicate, CancellationToken cancellationToken = default) { - return Task.FromResult(GetMongoQueryable(queryable).LastOrDefault(predicate)); + return Task.FromResult(queryable.LastOrDefault(predicate)); } public Task SingleAsync(IQueryable queryable, CancellationToken cancellationToken = default) { - return GetMongoQueryable(queryable).SingleAsync(cancellationToken); + return queryable.SingleAsync(cancellationToken); } public Task SingleAsync(IQueryable queryable, Expression> predicate, CancellationToken cancellationToken = default) { - return GetMongoQueryable(queryable).SingleAsync(predicate, cancellationToken); + return queryable.SingleAsync(predicate, cancellationToken); } public Task SingleOrDefaultAsync(IQueryable queryable, CancellationToken cancellationToken = default) { - return GetMongoQueryable(queryable).SingleOrDefaultAsync(cancellationToken)!; + return queryable.SingleOrDefaultAsync(cancellationToken)!; } public Task SingleOrDefaultAsync(IQueryable queryable, Expression> predicate, CancellationToken cancellationToken = default) { - return GetMongoQueryable(queryable).SingleOrDefaultAsync(predicate, cancellationToken)!; + return queryable.SingleOrDefaultAsync(predicate, cancellationToken)!; } public Task MinAsync(IQueryable queryable, CancellationToken cancellationToken = default) { - return GetMongoQueryable(queryable).MinAsync(cancellationToken); + return queryable.MinAsync(cancellationToken); } public Task MinAsync(IQueryable queryable, Expression> selector, CancellationToken cancellationToken = default) { - return GetMongoQueryable(queryable).MinAsync(selector, cancellationToken); + return queryable.MinAsync(selector, cancellationToken); } public Task MaxAsync(IQueryable queryable, CancellationToken cancellationToken = default) { - return GetMongoQueryable(queryable).MaxAsync(cancellationToken); + return queryable.MaxAsync(cancellationToken); } public Task MaxAsync(IQueryable queryable, Expression> selector, CancellationToken cancellationToken = default) { - return GetMongoQueryable(queryable).MaxAsync(selector, cancellationToken); + return queryable.MaxAsync(selector, cancellationToken); } public Task SumAsync(IQueryable queryable, CancellationToken cancellationToken = default) { - return GetMongoQueryable(queryable).SumAsync(cancellationToken); + return queryable.SumAsync(cancellationToken); } public Task SumAsync(IQueryable queryable, CancellationToken cancellationToken = default) { - return GetMongoQueryable(queryable).SumAsync(cancellationToken); + return queryable.SumAsync(cancellationToken); } public Task SumAsync(IQueryable queryable, Expression> selector, CancellationToken cancellationToken = default) { - return GetMongoQueryable(queryable).SumAsync(selector, cancellationToken); + return queryable.SumAsync(selector, cancellationToken); } public Task SumAsync(IQueryable queryable, Expression> selector, CancellationToken cancellationToken = default) { - return GetMongoQueryable(queryable).SumAsync(selector, cancellationToken); + return queryable.SumAsync(selector, cancellationToken); } public Task SumAsync(IQueryable queryable, CancellationToken cancellationToken = default) { - return GetMongoQueryable(queryable).SumAsync(cancellationToken); + return queryable.SumAsync(cancellationToken); } public Task SumAsync(IQueryable queryable, CancellationToken cancellationToken = default) { - return GetMongoQueryable(queryable).SumAsync(cancellationToken); + return queryable.SumAsync(cancellationToken); } public Task SumAsync(IQueryable queryable, Expression> selector, CancellationToken cancellationToken = default) { - return GetMongoQueryable(queryable).SumAsync(selector, cancellationToken); + return queryable.SumAsync(selector, cancellationToken); } public Task SumAsync(IQueryable queryable, Expression> selector, CancellationToken cancellationToken = default) { - return GetMongoQueryable(queryable).SumAsync(selector, cancellationToken); + return queryable.SumAsync(selector, cancellationToken); } public Task SumAsync(IQueryable queryable, CancellationToken cancellationToken = default) { - return GetMongoQueryable(queryable).SumAsync(cancellationToken); + return queryable.SumAsync(cancellationToken); } public Task SumAsync(IQueryable queryable, CancellationToken cancellationToken = default) { - return GetMongoQueryable(queryable).SumAsync(cancellationToken); + return queryable.SumAsync(cancellationToken); } public Task SumAsync(IQueryable queryable, Expression> selector, CancellationToken cancellationToken = default) { - return GetMongoQueryable(queryable).SumAsync(selector, cancellationToken); + return queryable.SumAsync(selector, cancellationToken); } public Task SumAsync(IQueryable queryable, Expression> selector, CancellationToken cancellationToken = default) { - return GetMongoQueryable(queryable).SumAsync(selector, cancellationToken); + return queryable.SumAsync(selector, cancellationToken); } public Task SumAsync(IQueryable queryable, CancellationToken cancellationToken = default) { - return GetMongoQueryable(queryable).SumAsync(cancellationToken); + return queryable.SumAsync(cancellationToken); } public Task SumAsync(IQueryable queryable, CancellationToken cancellationToken = default) { - return GetMongoQueryable(queryable).SumAsync(cancellationToken); + return queryable.SumAsync(cancellationToken); } public Task SumAsync(IQueryable queryable, Expression> selector, CancellationToken cancellationToken = default) { - return GetMongoQueryable(queryable).SumAsync(selector, cancellationToken); + return queryable.SumAsync(selector, cancellationToken); } public Task SumAsync(IQueryable queryable, Expression> selector, CancellationToken cancellationToken = default) { - return GetMongoQueryable(queryable).SumAsync(selector, cancellationToken); + return queryable.SumAsync(selector, cancellationToken); } public Task SumAsync(IQueryable queryable, CancellationToken cancellationToken = default) { - return GetMongoQueryable(queryable).SumAsync(cancellationToken); + return queryable.SumAsync(cancellationToken); } public Task SumAsync(IQueryable queryable, CancellationToken cancellationToken = default) { - return GetMongoQueryable(queryable).SumAsync(cancellationToken); + return queryable.SumAsync(cancellationToken); } public Task SumAsync(IQueryable queryable, Expression> selector, CancellationToken cancellationToken = default) { - return GetMongoQueryable(queryable).SumAsync(selector, cancellationToken); + return queryable.SumAsync(selector, cancellationToken); } public Task SumAsync(IQueryable queryable, Expression> selector, CancellationToken cancellationToken = default) { - return GetMongoQueryable(queryable).SumAsync(selector, cancellationToken); + return queryable.SumAsync(selector, cancellationToken); } public Task AverageAsync(IQueryable queryable, CancellationToken cancellationToken = default) { - return GetMongoQueryable(queryable).AverageAsync(cancellationToken); + return queryable.AverageAsync(cancellationToken); } public Task AverageAsync(IQueryable queryable, CancellationToken cancellationToken = default) { - return GetMongoQueryable(queryable).AverageAsync(cancellationToken); + return queryable.AverageAsync(cancellationToken); } public Task AverageAsync(IQueryable queryable, Expression> selector, CancellationToken cancellationToken = default) { - return GetMongoQueryable(queryable).AverageAsync(selector, cancellationToken); + return queryable.AverageAsync(selector, cancellationToken); } public Task AverageAsync(IQueryable queryable, Expression> selector, CancellationToken cancellationToken = default) { - return GetMongoQueryable(queryable).AverageAsync(selector, cancellationToken); + return queryable.AverageAsync(selector, cancellationToken); } public Task AverageAsync(IQueryable queryable, CancellationToken cancellationToken = default) { - return GetMongoQueryable(queryable).AverageAsync(cancellationToken); + return queryable.AverageAsync(cancellationToken); } public Task AverageAsync(IQueryable queryable, CancellationToken cancellationToken = default) { - return GetMongoQueryable(queryable).AverageAsync(cancellationToken); + return queryable.AverageAsync(cancellationToken); } public Task AverageAsync(IQueryable queryable, Expression> selector, CancellationToken cancellationToken = default) { - return GetMongoQueryable(queryable).AverageAsync(selector, cancellationToken); + return queryable.AverageAsync(selector, cancellationToken); } public Task AverageAsync(IQueryable queryable, Expression> selector, CancellationToken cancellationToken = default) { - return GetMongoQueryable(queryable).AverageAsync(selector, cancellationToken); + return queryable.AverageAsync(selector, cancellationToken); } public Task AverageAsync(IQueryable queryable, CancellationToken cancellationToken = default) { - return GetMongoQueryable(queryable).AverageAsync(cancellationToken); + return queryable.AverageAsync(cancellationToken); } public Task AverageAsync(IQueryable queryable, CancellationToken cancellationToken = default) { - return GetMongoQueryable(queryable).AverageAsync(cancellationToken); + return queryable.AverageAsync(cancellationToken); } public Task AverageAsync(IQueryable queryable, Expression> selector, CancellationToken cancellationToken = default) { - return GetMongoQueryable(queryable).AverageAsync(selector, cancellationToken); + return queryable.AverageAsync(selector, cancellationToken); } public Task AverageAsync(IQueryable queryable, Expression> selector, CancellationToken cancellationToken = default) { - return GetMongoQueryable(queryable).AverageAsync(selector, cancellationToken); + return queryable.AverageAsync(selector, cancellationToken); } public Task AverageAsync(IQueryable queryable, CancellationToken cancellationToken = default) { - return GetMongoQueryable(queryable).AverageAsync(cancellationToken); + return queryable.AverageAsync(cancellationToken); } public Task AverageAsync(IQueryable queryable, CancellationToken cancellationToken = default) { - return GetMongoQueryable(queryable).AverageAsync(cancellationToken); + return queryable.AverageAsync(cancellationToken); } public Task AverageAsync(IQueryable queryable, Expression> selector, CancellationToken cancellationToken = default) { - return GetMongoQueryable(queryable).AverageAsync(selector, cancellationToken); + return queryable.AverageAsync(selector, cancellationToken); } public Task AverageAsync(IQueryable queryable, Expression> selector, CancellationToken cancellationToken = default) { - return GetMongoQueryable(queryable).AverageAsync(selector, cancellationToken); + return queryable.AverageAsync(selector, cancellationToken); } public Task AverageAsync(IQueryable queryable, CancellationToken cancellationToken = default) { - return GetMongoQueryable(queryable).AverageAsync(cancellationToken); + return queryable.AverageAsync(cancellationToken); } public Task AverageAsync(IQueryable queryable, CancellationToken cancellationToken = default) { - return GetMongoQueryable(queryable).AverageAsync(cancellationToken); + return queryable.AverageAsync(cancellationToken); } public Task AverageAsync(IQueryable queryable, Expression> selector, CancellationToken cancellationToken = default) { - return GetMongoQueryable(queryable).AverageAsync(selector, cancellationToken); + return queryable.AverageAsync(selector, cancellationToken); } public Task AverageAsync(IQueryable queryable, Expression> selector, CancellationToken cancellationToken = default) { - return GetMongoQueryable(queryable).AverageAsync(selector, cancellationToken); + return queryable.AverageAsync(selector, cancellationToken); } public Task> ToListAsync(IQueryable queryable, CancellationToken cancellationToken = default) { - return GetMongoQueryable(queryable).ToListAsync(cancellationToken); + return queryable.ToListAsync(cancellationToken); } public async Task ToArrayAsync(IQueryable queryable, CancellationToken cancellationToken = default) { - return (await GetMongoQueryable(queryable).ToListAsync(cancellationToken)).ToArray(); + return (await queryable.ToListAsync(cancellationToken)).ToArray(); } } diff --git a/framework/test/Volo.Abp.MongoDB.Tests/Volo.Abp.MongoDB.Tests.csproj b/framework/test/Volo.Abp.MongoDB.Tests/Volo.Abp.MongoDB.Tests.csproj index ae688f1640..e2328fdca3 100644 --- a/framework/test/Volo.Abp.MongoDB.Tests/Volo.Abp.MongoDB.Tests.csproj +++ b/framework/test/Volo.Abp.MongoDB.Tests/Volo.Abp.MongoDB.Tests.csproj @@ -15,10 +15,10 @@ - - - - + + + + diff --git a/framework/test/Volo.Abp.MongoDB.Tests/Volo/Abp/MongoDB/MongoDbFixture.cs b/framework/test/Volo.Abp.MongoDB.Tests/Volo/Abp/MongoDB/MongoDbFixture.cs index 9b70fe2681..ff6fe1face 100644 --- a/framework/test/Volo.Abp.MongoDB.Tests/Volo/Abp/MongoDB/MongoDbFixture.cs +++ b/framework/test/Volo.Abp.MongoDB.Tests/Volo/Abp/MongoDB/MongoDbFixture.cs @@ -1,5 +1,5 @@ using System; -using EphemeralMongo; +using MongoSandbox; namespace Volo.Abp.MongoDB; @@ -11,7 +11,8 @@ public class MongoDbFixture : IDisposable { MongoDbRunner = MongoRunner.Run(new MongoRunnerOptions { - UseSingleNodeReplicaSet = true + UseSingleNodeReplicaSet = true, + ReplicaSetSetupTimeout = TimeSpan.FromSeconds(30) }); } diff --git a/framework/test/Volo.Abp.MongoDB.Tests/Volo/Abp/MongoDB/Repositories/Repository_Basic_Tests.cs b/framework/test/Volo.Abp.MongoDB.Tests/Volo/Abp/MongoDB/Repositories/Repository_Basic_Tests.cs index 0d5122228d..e2ad9088cb 100644 --- a/framework/test/Volo.Abp.MongoDB.Tests/Volo/Abp/MongoDB/Repositories/Repository_Basic_Tests.cs +++ b/framework/test/Volo.Abp.MongoDB.Tests/Volo/Abp/MongoDB/Repositories/Repository_Basic_Tests.cs @@ -18,9 +18,9 @@ public class Repository_Basic_Tests : Repository_Basic_Tests>().ShouldNotBeNull(); - ((IMongoQueryable)(await PersonRepository.GetQueryableAsync()).Where(p => p.Name == "Douglas")).ShouldNotBeNull(); - (await PersonRepository.GetQueryableAsync()).Where(p => p.Name == "Douglas").As>().ShouldNotBeNull(); + (await PersonRepository.GetQueryableAsync()).ShouldNotBeNull(); + ((IQueryable)(await PersonRepository.GetQueryableAsync()).Where(p => p.Name == "Douglas")).ShouldNotBeNull(); + (await PersonRepository.GetQueryableAsync()).Where(p => p.Name == "Douglas").ShouldNotBeNull(); } [Fact] @@ -69,9 +69,9 @@ public class Repository_Basic_Tests : Repository_Basic_Tests c.Name == "ISTANBUL").ShouldBeNull(); - (await CityRepository.GetMongoQueryableAsync()).FirstOrDefault(c => c.Name == "istanbul").ShouldBeNull(); - (await CityRepository.GetMongoQueryableAsync()).FirstOrDefault(c => c.Name == "Istanbul").ShouldNotBeNull(); + (await CityRepository.GetQueryableAsync()).FirstOrDefault(c => c.Name == "ISTANBUL").ShouldBeNull(); + (await CityRepository.GetQueryableAsync()).FirstOrDefault(c => c.Name == "istanbul").ShouldBeNull(); + (await CityRepository.GetQueryableAsync()).FirstOrDefault(c => c.Name == "Istanbul").ShouldNotBeNull(); (await PersonRepository.GetQueryableAsync()).FirstOrDefault(p => p.Name == "douglas").ShouldNotBeNull(); (await PersonRepository.GetQueryableAsync()).FirstOrDefault(p => p.Name == "DOUGLAS").ShouldNotBeNull(); diff --git a/framework/test/Volo.Abp.MongoDB.Tests/Volo/Abp/TestApp/MongoDb/CityRepository.cs b/framework/test/Volo.Abp.MongoDB.Tests/Volo/Abp/TestApp/MongoDb/CityRepository.cs index f8355b5466..1f0c0aa24d 100644 --- a/framework/test/Volo.Abp.MongoDB.Tests/Volo/Abp/TestApp/MongoDb/CityRepository.cs +++ b/framework/test/Volo.Abp.MongoDB.Tests/Volo/Abp/TestApp/MongoDb/CityRepository.cs @@ -1,5 +1,6 @@ using System; using System.Collections.Generic; +using System.Linq; using System.Threading.Tasks; using MongoDB.Driver; using MongoDB.Driver.Linq; diff --git a/modules/audit-logging/src/Volo.Abp.AuditLogging.MongoDB/Volo/Abp/AuditLogging/MongoDB/MongoAuditLogRepository.cs b/modules/audit-logging/src/Volo.Abp.AuditLogging.MongoDB/Volo/Abp/AuditLogging/MongoDB/MongoAuditLogRepository.cs index b406e83d5c..92416174ae 100644 --- a/modules/audit-logging/src/Volo.Abp.AuditLogging.MongoDB/Volo/Abp/AuditLogging/MongoDB/MongoAuditLogRepository.cs +++ b/modules/audit-logging/src/Volo.Abp.AuditLogging.MongoDB/Volo/Abp/AuditLogging/MongoDB/MongoAuditLogRepository.cs @@ -64,8 +64,7 @@ public class MongoAuditLogRepository : MongoDbRepository>() - .PageBy>(skipCount, maxResultCount) + .PageBy(skipCount, maxResultCount) .ToListAsync(GetCancellationToken(cancellationToken)); } @@ -104,8 +103,7 @@ public class MongoAuditLogRepository : MongoDbRepository>() - .LongCountAsync(GetCancellationToken(cancellationToken)); + var count = await query.LongCountAsync(GetCancellationToken(cancellationToken)); return count; } @@ -128,7 +126,7 @@ public class MongoAuditLogRepository : MongoDbRepository auditLog.ExecutionTime >= startTime) .WhereIf(endTime.HasValue, auditLog => auditLog.ExecutionTime <= endTime) .WhereIf(hasException.HasValue && hasException.Value, auditLog => auditLog.Exceptions != null && auditLog.Exceptions != "") @@ -151,7 +149,7 @@ public class MongoAuditLogRepository : MongoDbRepository a.ExecutionTime < endDate.AddDays(1) && a.ExecutionTime > startDate) .OrderBy(t => t.ExecutionTime) .GroupBy(t => new { @@ -169,7 +167,7 @@ public class MongoAuditLogRepository : MongoDbRepository x.EntityChanges.Any(y => y.Id == entityChangeId)) .OrderBy(x => x.Id) .FirstAsync(GetCancellationToken(cancellationToken))).EntityChanges.FirstOrDefault(x => x.Id == entityChangeId); @@ -199,8 +197,7 @@ public class MongoAuditLogRepository : MongoDbRepository>() - .PageBy>(skipCount, maxResultCount) + .PageBy(skipCount, maxResultCount) .ToListAsync(GetCancellationToken(cancellationToken)); } @@ -215,7 +212,7 @@ public class MongoAuditLogRepository : MongoDbRepository>().LongCountAsync(GetCancellationToken(cancellationToken)); + var count = await query.LongCountAsync(GetCancellationToken(cancellationToken)); return count; } @@ -224,7 +221,7 @@ public class MongoAuditLogRepository : MongoDbRepository x.EntityChanges.Any(y => y.Id == entityChangeId)) .FirstAsync(GetCancellationToken(cancellationToken)); @@ -240,9 +237,8 @@ public class MongoAuditLogRepository : MongoDbRepository x.EntityChanges.Any(y => y.EntityId == entityId && y.EntityTypeFullName == entityTypeFullName)) - .As>() .OrderByDescending(x => x.ExecutionTime) .ToListAsync(GetCancellationToken(cancellationToken)); @@ -263,7 +259,7 @@ public class MongoAuditLogRepository : MongoDbRepository x.EntityChanges) .WhereIf(auditLogId.HasValue, e => e.Id == auditLogId) .WhereIf(startTime.HasValue, e => e.ChangeTime >= startTime) diff --git a/modules/audit-logging/test/Volo.Abp.AuditLogging.MongoDB.Tests/Volo.Abp.AuditLogging.MongoDB.Tests.csproj b/modules/audit-logging/test/Volo.Abp.AuditLogging.MongoDB.Tests/Volo.Abp.AuditLogging.MongoDB.Tests.csproj index 41718fda4e..a33c1c74f8 100644 --- a/modules/audit-logging/test/Volo.Abp.AuditLogging.MongoDB.Tests/Volo.Abp.AuditLogging.MongoDB.Tests.csproj +++ b/modules/audit-logging/test/Volo.Abp.AuditLogging.MongoDB.Tests/Volo.Abp.AuditLogging.MongoDB.Tests.csproj @@ -14,10 +14,10 @@ - - - - + + + + diff --git a/modules/audit-logging/test/Volo.Abp.AuditLogging.MongoDB.Tests/Volo/Abp/AuditLogging/MongoDB/MongoDbFixture.cs b/modules/audit-logging/test/Volo.Abp.AuditLogging.MongoDB.Tests/Volo/Abp/AuditLogging/MongoDB/MongoDbFixture.cs index a68f246c78..569bf3ad2d 100644 --- a/modules/audit-logging/test/Volo.Abp.AuditLogging.MongoDB.Tests/Volo/Abp/AuditLogging/MongoDB/MongoDbFixture.cs +++ b/modules/audit-logging/test/Volo.Abp.AuditLogging.MongoDB.Tests/Volo/Abp/AuditLogging/MongoDB/MongoDbFixture.cs @@ -1,5 +1,5 @@ using System; -using EphemeralMongo; +using MongoSandbox; namespace Volo.Abp.AuditLogging.MongoDB; diff --git a/modules/background-jobs/src/Volo.Abp.BackgroundJobs.MongoDB/Volo/Abp/BackgroundJobs/MongoDB/MongoBackgroundJobRepository.cs b/modules/background-jobs/src/Volo.Abp.BackgroundJobs.MongoDB/Volo/Abp/BackgroundJobs/MongoDB/MongoBackgroundJobRepository.cs index 5993fdf9ba..a3f46643fe 100644 --- a/modules/background-jobs/src/Volo.Abp.BackgroundJobs.MongoDB/Volo/Abp/BackgroundJobs/MongoDB/MongoBackgroundJobRepository.cs +++ b/modules/background-jobs/src/Volo.Abp.BackgroundJobs.MongoDB/Volo/Abp/BackgroundJobs/MongoDB/MongoBackgroundJobRepository.cs @@ -2,6 +2,7 @@ using System.Collections.Generic; using System.Threading; using System.Threading.Tasks; +using System.Linq; using MongoDB.Driver; using MongoDB.Driver.Linq; using Volo.Abp.Domain.Repositories.MongoDB; @@ -29,10 +30,10 @@ public class MongoBackgroundJobRepository : MongoDbRepository> GetWaitingListQuery(int maxResultCount, CancellationToken cancellationToken = default) + protected virtual async Task> GetWaitingListQuery(int maxResultCount, CancellationToken cancellationToken = default) { var now = Clock.Now; - return (await GetMongoQueryableAsync(cancellationToken)) + return (await GetQueryableAsync(cancellationToken)) .Where(t => !t.IsAbandoned && t.NextTryTime <= now) .OrderByDescending(t => t.Priority) .ThenBy(t => t.TryCount) diff --git a/modules/background-jobs/test/Volo.Abp.BackgroundJobs.MongoDB.Tests/Volo.Abp.BackgroundJobs.MongoDB.Tests.csproj b/modules/background-jobs/test/Volo.Abp.BackgroundJobs.MongoDB.Tests/Volo.Abp.BackgroundJobs.MongoDB.Tests.csproj index c6a4b35a66..a3f84bb18a 100644 --- a/modules/background-jobs/test/Volo.Abp.BackgroundJobs.MongoDB.Tests/Volo.Abp.BackgroundJobs.MongoDB.Tests.csproj +++ b/modules/background-jobs/test/Volo.Abp.BackgroundJobs.MongoDB.Tests/Volo.Abp.BackgroundJobs.MongoDB.Tests.csproj @@ -14,10 +14,10 @@ - - - - + + + + diff --git a/modules/background-jobs/test/Volo.Abp.BackgroundJobs.MongoDB.Tests/Volo/Abp/BackgroundJobs/MongoDB/MongoDbFixture.cs b/modules/background-jobs/test/Volo.Abp.BackgroundJobs.MongoDB.Tests/Volo/Abp/BackgroundJobs/MongoDB/MongoDbFixture.cs index 97bd35c6fa..b41e255cb8 100644 --- a/modules/background-jobs/test/Volo.Abp.BackgroundJobs.MongoDB.Tests/Volo/Abp/BackgroundJobs/MongoDB/MongoDbFixture.cs +++ b/modules/background-jobs/test/Volo.Abp.BackgroundJobs.MongoDB.Tests/Volo/Abp/BackgroundJobs/MongoDB/MongoDbFixture.cs @@ -1,5 +1,5 @@ using System; -using EphemeralMongo; +using MongoSandbox; namespace Volo.Abp.BackgroundJobs.MongoDB; diff --git a/modules/blob-storing-database/src/Volo.Abp.BlobStoring.Database.MongoDB/Volo/Abp/BlobStoring/Database/MongoDB/MongoDbDatabaseBlobRepository.cs b/modules/blob-storing-database/src/Volo.Abp.BlobStoring.Database.MongoDB/Volo/Abp/BlobStoring/Database/MongoDB/MongoDbDatabaseBlobRepository.cs index 4610043405..6b2663013d 100644 --- a/modules/blob-storing-database/src/Volo.Abp.BlobStoring.Database.MongoDB/Volo/Abp/BlobStoring/Database/MongoDB/MongoDbDatabaseBlobRepository.cs +++ b/modules/blob-storing-database/src/Volo.Abp.BlobStoring.Database.MongoDB/Volo/Abp/BlobStoring/Database/MongoDB/MongoDbDatabaseBlobRepository.cs @@ -17,7 +17,7 @@ public class MongoDbDatabaseBlobRepository : MongoDbRepository x.ContainerId == containerId && x.Name == name, cancellationToken @@ -28,7 +28,7 @@ public class MongoDbDatabaseBlobRepository : MongoDbRepository x.ContainerId == containerId && x.Name == name, cancellationToken diff --git a/modules/blob-storing-database/test/Volo.Abp.BlobStoring.Database.MongoDB.Tests/MongoDB/MongoDbFixture.cs b/modules/blob-storing-database/test/Volo.Abp.BlobStoring.Database.MongoDB.Tests/MongoDB/MongoDbFixture.cs index 8952236f43..7c086e0bb4 100644 --- a/modules/blob-storing-database/test/Volo.Abp.BlobStoring.Database.MongoDB.Tests/MongoDB/MongoDbFixture.cs +++ b/modules/blob-storing-database/test/Volo.Abp.BlobStoring.Database.MongoDB.Tests/MongoDB/MongoDbFixture.cs @@ -1,5 +1,5 @@ using System; -using EphemeralMongo; +using MongoSandbox; namespace Volo.Abp.BlobStoring.Database.MongoDB; diff --git a/modules/blob-storing-database/test/Volo.Abp.BlobStoring.Database.MongoDB.Tests/Volo.Abp.BlobStoring.Database.MongoDB.Tests.csproj b/modules/blob-storing-database/test/Volo.Abp.BlobStoring.Database.MongoDB.Tests/Volo.Abp.BlobStoring.Database.MongoDB.Tests.csproj index 1bd05f4357..61c0d81d02 100644 --- a/modules/blob-storing-database/test/Volo.Abp.BlobStoring.Database.MongoDB.Tests/Volo.Abp.BlobStoring.Database.MongoDB.Tests.csproj +++ b/modules/blob-storing-database/test/Volo.Abp.BlobStoring.Database.MongoDB.Tests/Volo.Abp.BlobStoring.Database.MongoDB.Tests.csproj @@ -7,10 +7,10 @@ - - - - + + + + diff --git a/modules/blogging/src/Volo.Blogging.MongoDB/Volo/Blogging/Blogs/MongoBlogRepository.cs b/modules/blogging/src/Volo.Blogging.MongoDB/Volo/Blogging/Blogs/MongoBlogRepository.cs index 42c8bb467a..c15ef4d0cb 100644 --- a/modules/blogging/src/Volo.Blogging.MongoDB/Volo/Blogging/Blogs/MongoBlogRepository.cs +++ b/modules/blogging/src/Volo.Blogging.MongoDB/Volo/Blogging/Blogs/MongoBlogRepository.cs @@ -16,7 +16,7 @@ namespace Volo.Blogging.Blogs public virtual async Task FindByShortNameAsync(string shortName, CancellationToken cancellationToken = default) { - return await (await GetMongoQueryableAsync(cancellationToken)).FirstOrDefaultAsync(p => p.ShortName == shortName, GetCancellationToken(cancellationToken)); + return await (await GetQueryableAsync(cancellationToken)).FirstOrDefaultAsync(p => p.ShortName == shortName, GetCancellationToken(cancellationToken)); } } } diff --git a/modules/blogging/src/Volo.Blogging.MongoDB/Volo/Blogging/Comments/MongoCommentRepository.cs b/modules/blogging/src/Volo.Blogging.MongoDB/Volo/Blogging/Comments/MongoCommentRepository.cs index 89e5b6b575..77c443e485 100644 --- a/modules/blogging/src/Volo.Blogging.MongoDB/Volo/Blogging/Comments/MongoCommentRepository.cs +++ b/modules/blogging/src/Volo.Blogging.MongoDB/Volo/Blogging/Comments/MongoCommentRepository.cs @@ -2,6 +2,7 @@ using System.Collections.Generic; using System.Threading; using System.Threading.Tasks; +using System.Linq; using MongoDB.Driver; using MongoDB.Driver.Linq; using Volo.Abp.Domain.Repositories.MongoDB; @@ -18,7 +19,7 @@ namespace Volo.Blogging.Comments public virtual async Task> GetListOfPostAsync(Guid postId, CancellationToken cancellationToken = default) { - return await (await GetMongoQueryableAsync(cancellationToken)) + return await (await GetQueryableAsync(cancellationToken)) .Where(a => a.PostId == postId) .OrderBy(a => a.CreationTime) .ToListAsync(GetCancellationToken(cancellationToken)); @@ -26,19 +27,19 @@ namespace Volo.Blogging.Comments public virtual async Task GetCommentCountOfPostAsync(Guid postId, CancellationToken cancellationToken = default) { - return await (await GetMongoQueryableAsync(cancellationToken)) + return await (await GetQueryableAsync(cancellationToken)) .CountAsync(a => a.PostId == postId, GetCancellationToken(cancellationToken)); } public virtual async Task> GetRepliesOfComment(Guid id, CancellationToken cancellationToken = default) { - return await (await GetMongoQueryableAsync(cancellationToken)) + return await (await GetQueryableAsync(cancellationToken)) .Where(a => a.RepliedCommentId == id).ToListAsync(GetCancellationToken(cancellationToken)); } public virtual async Task DeleteOfPost(Guid id, CancellationToken cancellationToken = default) { - var recordsToDelete = (await GetMongoQueryableAsync(cancellationToken)).Where(pt => pt.PostId == id); + var recordsToDelete = (await GetQueryableAsync(cancellationToken)).Where(pt => pt.PostId == id); foreach (var record in recordsToDelete) { diff --git a/modules/blogging/src/Volo.Blogging.MongoDB/Volo/Blogging/Posts/MongoPostRepository.cs b/modules/blogging/src/Volo.Blogging.MongoDB/Volo/Blogging/Posts/MongoPostRepository.cs index 3cdcccc5fd..b3083cbd5f 100644 --- a/modules/blogging/src/Volo.Blogging.MongoDB/Volo/Blogging/Posts/MongoPostRepository.cs +++ b/modules/blogging/src/Volo.Blogging.MongoDB/Volo/Blogging/Posts/MongoPostRepository.cs @@ -2,6 +2,7 @@ using System.Collections.Generic; using System.Threading; using System.Threading.Tasks; +using System.Linq; using MongoDB.Driver; using MongoDB.Driver.Linq; using Nito.AsyncEx; @@ -20,13 +21,13 @@ namespace Volo.Blogging.Posts public virtual async Task> GetPostsByBlogId(Guid id, CancellationToken cancellationToken = default) { - return await (await GetMongoQueryableAsync(cancellationToken)).Where(p => p.BlogId == id).OrderByDescending(p => p.CreationTime).ToListAsync(GetCancellationToken(cancellationToken)); + return await (await GetQueryableAsync(cancellationToken)).Where(p => p.BlogId == id).OrderByDescending(p => p.CreationTime).ToListAsync(GetCancellationToken(cancellationToken)); } public virtual async Task IsPostUrlInUseAsync(Guid blogId, string url, Guid? excludingPostId = null, CancellationToken cancellationToken = default) { - var query = (await GetMongoQueryableAsync(cancellationToken)).Where(p => blogId == p.BlogId && p.Url == url); + var query = (await GetQueryableAsync(cancellationToken)).Where(p => blogId == p.BlogId && p.Url == url); if (excludingPostId != null) { @@ -38,7 +39,7 @@ namespace Volo.Blogging.Posts public virtual async Task GetPostByUrl(Guid blogId, string url, CancellationToken cancellationToken = default) { - var post = await (await GetMongoQueryableAsync(cancellationToken)).FirstOrDefaultAsync(p => p.BlogId == blogId && p.Url == url, GetCancellationToken(cancellationToken)); + var post = await (await GetQueryableAsync(cancellationToken)).FirstOrDefaultAsync(p => p.BlogId == blogId && p.Url == url, GetCancellationToken(cancellationToken)); if (post == null) { @@ -50,7 +51,7 @@ namespace Volo.Blogging.Posts public virtual async Task> GetOrderedList(Guid blogId, bool @descending = false, CancellationToken cancellationToken = default) { - var query = (await GetMongoQueryableAsync(cancellationToken)).Where(x => x.BlogId == blogId); + var query = (await GetQueryableAsync(cancellationToken)).Where(x => x.BlogId == blogId); if (!descending) { @@ -62,7 +63,7 @@ namespace Volo.Blogging.Posts public virtual async Task> GetListByUserIdAsync(Guid userId, CancellationToken cancellationToken = default) { - var query = (await GetMongoQueryableAsync(cancellationToken)).Where(x => x.CreatorId == userId) + var query = (await GetQueryableAsync(cancellationToken)).Where(x => x.CreatorId == userId) .OrderByDescending(x => x.CreationTime); return await query.ToListAsync(GetCancellationToken(cancellationToken)); @@ -70,7 +71,7 @@ namespace Volo.Blogging.Posts public virtual async Task> GetLatestBlogPostsAsync(Guid blogId, int count, CancellationToken cancellationToken = default) { - var query = (await GetMongoQueryableAsync(cancellationToken)).Where(x => x.BlogId == blogId) + var query = (await GetQueryableAsync(cancellationToken)).Where(x => x.BlogId == blogId) .OrderByDescending(x => x.CreationTime) .Take(count); diff --git a/modules/blogging/src/Volo.Blogging.MongoDB/Volo/Blogging/Tagging/MongoTagRepository.cs b/modules/blogging/src/Volo.Blogging.MongoDB/Volo/Blogging/Tagging/MongoTagRepository.cs index bfa0c9fb4d..2e60faaccc 100644 --- a/modules/blogging/src/Volo.Blogging.MongoDB/Volo/Blogging/Tagging/MongoTagRepository.cs +++ b/modules/blogging/src/Volo.Blogging.MongoDB/Volo/Blogging/Tagging/MongoTagRepository.cs @@ -20,27 +20,27 @@ namespace Volo.Blogging.Tagging public virtual async Task> GetListAsync(Guid blogId, CancellationToken cancellationToken = default) { - return await (await GetMongoQueryableAsync(cancellationToken)).Where(t => t.BlogId == blogId).ToListAsync(GetCancellationToken(cancellationToken)); + return await (await GetQueryableAsync(cancellationToken)).Where(t => t.BlogId == blogId).ToListAsync(GetCancellationToken(cancellationToken)); } public virtual async Task GetByNameAsync(Guid blogId, string name, CancellationToken cancellationToken = default) { - return await (await GetMongoQueryableAsync(cancellationToken)).Where(t => t.BlogId == blogId && t.Name == name).FirstAsync(GetCancellationToken(cancellationToken)); + return await (await GetQueryableAsync(cancellationToken)).Where(t => t.BlogId == blogId && t.Name == name).FirstAsync(GetCancellationToken(cancellationToken)); } public virtual async Task FindByNameAsync(Guid blogId, string name, CancellationToken cancellationToken = default) { - return await (await GetMongoQueryableAsync(cancellationToken)).Where(t => t.BlogId == blogId && t.Name == name).FirstOrDefaultAsync(GetCancellationToken(cancellationToken)); + return await (await GetQueryableAsync(cancellationToken)).Where(t => t.BlogId == blogId && t.Name == name).FirstOrDefaultAsync(GetCancellationToken(cancellationToken)); } public virtual async Task> GetListAsync(IEnumerable ids, CancellationToken cancellationToken = default) { - return await (await GetMongoQueryableAsync(cancellationToken)).Where(t => ids.Contains(t.Id)).ToListAsync(GetCancellationToken(cancellationToken)); + return await (await GetQueryableAsync(cancellationToken)).Where(t => ids.Contains(t.Id)).ToListAsync(GetCancellationToken(cancellationToken)); } public virtual async Task DecreaseUsageCountOfTagsAsync(List ids, CancellationToken cancellationToken = default) { - var tags = await (await GetMongoQueryableAsync(cancellationToken)) + var tags = await (await GetQueryableAsync(cancellationToken)) .Where(t => ids.Contains(t.Id)) .ToListAsync(GetCancellationToken(cancellationToken)); diff --git a/modules/blogging/src/Volo.Blogging.MongoDB/Volo/Blogging/Users/MongoBlogUserRepository.cs b/modules/blogging/src/Volo.Blogging.MongoDB/Volo/Blogging/Users/MongoBlogUserRepository.cs index 3595620f54..b68e77c9fd 100644 --- a/modules/blogging/src/Volo.Blogging.MongoDB/Volo/Blogging/Users/MongoBlogUserRepository.cs +++ b/modules/blogging/src/Volo.Blogging.MongoDB/Volo/Blogging/Users/MongoBlogUserRepository.cs @@ -1,6 +1,7 @@ using System.Collections.Generic; using System.Threading; using System.Threading.Tasks; +using System.Linq; using Volo.Abp.MongoDB; using Volo.Abp.Users.MongoDB; using Volo.Blogging.MongoDB; @@ -17,7 +18,7 @@ namespace Volo.Blogging.Users public virtual async Task> GetUsersAsync(int maxCount, string filter, CancellationToken cancellationToken = default) { - var query = await GetMongoQueryableAsync(cancellationToken); + var query = await GetQueryableAsync(cancellationToken); if (!string.IsNullOrWhiteSpace(filter)) { diff --git a/modules/blogging/test/Volo.Blogging.MongoDB.Tests/Volo.Blogging.MongoDB.Tests.csproj b/modules/blogging/test/Volo.Blogging.MongoDB.Tests/Volo.Blogging.MongoDB.Tests.csproj index 88cd171a55..7dcac50e69 100644 --- a/modules/blogging/test/Volo.Blogging.MongoDB.Tests/Volo.Blogging.MongoDB.Tests.csproj +++ b/modules/blogging/test/Volo.Blogging.MongoDB.Tests/Volo.Blogging.MongoDB.Tests.csproj @@ -7,10 +7,10 @@ - - - - + + + + diff --git a/modules/blogging/test/Volo.Blogging.MongoDB.Tests/Volo/Blogging/MongoDB/MongoDbFixture.cs b/modules/blogging/test/Volo.Blogging.MongoDB.Tests/Volo/Blogging/MongoDB/MongoDbFixture.cs index ad1fce80e5..e1a4d00ce3 100644 --- a/modules/blogging/test/Volo.Blogging.MongoDB.Tests/Volo/Blogging/MongoDB/MongoDbFixture.cs +++ b/modules/blogging/test/Volo.Blogging.MongoDB.Tests/Volo/Blogging/MongoDB/MongoDbFixture.cs @@ -1,5 +1,5 @@ using System; -using EphemeralMongo; +using MongoSandbox; public class MongoDbFixture : IDisposable { diff --git a/modules/cms-kit/src/Volo.CmsKit.MongoDB/Volo/CmsKit/MongoDB/Blogs/MongoBlogFeatureRepository.cs b/modules/cms-kit/src/Volo.CmsKit.MongoDB/Volo/CmsKit/MongoDB/Blogs/MongoBlogFeatureRepository.cs index 334debe8c8..606c3e28ff 100644 --- a/modules/cms-kit/src/Volo.CmsKit.MongoDB/Volo/CmsKit/MongoDB/Blogs/MongoBlogFeatureRepository.cs +++ b/modules/cms-kit/src/Volo.CmsKit.MongoDB/Volo/CmsKit/MongoDB/Blogs/MongoBlogFeatureRepository.cs @@ -25,14 +25,14 @@ public class MongoBlogFeatureRepository : MongoDbRepository> GetListAsync(Guid blogId, CancellationToken cancellationToken = default) { - return await (await GetMongoQueryableAsync(cancellationToken)) + return await (await GetQueryableAsync(cancellationToken)) .Where(x => x.BlogId == blogId) .ToListAsync(GetCancellationToken(cancellationToken)); } public virtual async Task> GetListAsync(Guid blogId, List featureNames, CancellationToken cancellationToken = default) { - return await (await GetMongoQueryableAsync(cancellationToken)) + return await (await GetQueryableAsync(cancellationToken)) .Where(x => x.BlogId == blogId && featureNames.Contains(x.FeatureName)) .ToListAsync(GetCancellationToken(cancellationToken)); } diff --git a/modules/cms-kit/src/Volo.CmsKit.MongoDB/Volo/CmsKit/MongoDB/Blogs/MongoBlogPostRepository.cs b/modules/cms-kit/src/Volo.CmsKit.MongoDB/Volo/CmsKit/MongoDB/Blogs/MongoBlogPostRepository.cs index 0212e5975c..b47abe1115 100644 --- a/modules/cms-kit/src/Volo.CmsKit.MongoDB/Volo/CmsKit/MongoDB/Blogs/MongoBlogPostRepository.cs +++ b/modules/cms-kit/src/Volo.CmsKit.MongoDB/Volo/CmsKit/MongoDB/Blogs/MongoBlogPostRepository.cs @@ -44,7 +44,7 @@ public class MongoBlogPostRepository : MongoDbRepository(token)).FirstOrDefaultAsync(x => x.Id == blogPost.AuthorId, token); + blogPost.Author = await (await GetQueryableAsync(token)).FirstOrDefaultAsync(x => x.Id == blogPost.AuthorId, token); return blogPost; } @@ -64,13 +64,13 @@ public class MongoBlogPostRepository : MongoDbRepository>(tagFilteredEntityIds.Any(), x => tagFilteredEntityIds.Contains(x.Id)) - .WhereIf>(favoriteUserFilteredEntityIds.Any(), x => favoriteUserFilteredEntityIds.Contains(x.Id)) - .WhereIf>(!string.IsNullOrWhiteSpace(filter), x => x.Title.Contains(filter) || x.Slug.Contains(filter)) - .WhereIf>(blogId.HasValue, x => x.BlogId == blogId) - .WhereIf>(authorId.HasValue, x => x.AuthorId == authorId) - .WhereIf>(statusFilter.HasValue, x => x.Status == statusFilter) + return await (await GetQueryableAsync(cancellationToken)) + .WhereIf(tagFilteredEntityIds.Any(), x => tagFilteredEntityIds.Contains(x.Id)) + .WhereIf(favoriteUserFilteredEntityIds.Any(), x => favoriteUserFilteredEntityIds.Contains(x.Id)) + .WhereIf(!string.IsNullOrWhiteSpace(filter), x => x.Title.Contains(filter) || x.Slug.Contains(filter)) + .WhereIf(blogId.HasValue, x => x.BlogId == blogId) + .WhereIf(authorId.HasValue, x => x.AuthorId == authorId) + .WhereIf(statusFilter.HasValue, x => x.Status == statusFilter) .CountAsync(cancellationToken); } @@ -174,7 +174,7 @@ public class MongoBlogPostRepository : MongoDbRepository x.BlogId == blogId && x.Slug.ToLower() == slug, cancellationToken); } @@ -225,14 +225,14 @@ public class MongoBlogPostRepository : MongoDbRepository x.Status == BlogPostStatus.WaitingForReview, cancellationToken); } public async Task UpdateBlogAsync(Guid sourceBlogId, Guid? targetBlogId, CancellationToken cancellationToken = default) { cancellationToken = GetCancellationToken(cancellationToken); - var blogPosts = await (await GetMongoQueryableAsync(cancellationToken)).Where(x => x.BlogId == sourceBlogId).ToListAsync(cancellationToken); + var blogPosts = await (await GetQueryableAsync(cancellationToken)).Where(x => x.BlogId == sourceBlogId).ToListAsync(cancellationToken); if (targetBlogId.HasValue) { foreach (var blogPost in blogPosts) diff --git a/modules/cms-kit/src/Volo.CmsKit.MongoDB/Volo/CmsKit/MongoDB/Blogs/MongoBlogRepository.cs b/modules/cms-kit/src/Volo.CmsKit.MongoDB/Volo/CmsKit/MongoDB/Blogs/MongoBlogRepository.cs index 98567899e5..c25bc688b7 100644 --- a/modules/cms-kit/src/Volo.CmsKit.MongoDB/Volo/CmsKit/MongoDB/Blogs/MongoBlogRepository.cs +++ b/modules/cms-kit/src/Volo.CmsKit.MongoDB/Volo/CmsKit/MongoDB/Blogs/MongoBlogRepository.cs @@ -23,13 +23,13 @@ public class MongoBlogRepository : MongoDbRepository ExistsAsync(Guid id, CancellationToken cancellationToken = default) { var token = GetCancellationToken(cancellationToken); - return await (await GetMongoQueryableAsync(token)).AnyAsync(x => x.Id == id, token); + return await (await GetQueryableAsync(token)).AnyAsync(x => x.Id == id, token); } public virtual async Task SlugExistsAsync(string slug, CancellationToken cancellationToken = default) { var token = GetCancellationToken(cancellationToken); - return await (await GetMongoQueryableAsync(token)).AnyAsync(x => x.Slug == slug, token); + return await (await GetQueryableAsync(token)).AnyAsync(x => x.Slug == slug, token); } public virtual async Task> GetListAsync( @@ -44,8 +44,7 @@ public class MongoBlogRepository : MongoDbRepository>() - .PageBy>(skipCount, maxResultCount) + .PageBy(skipCount, maxResultCount) .ToListAsync(token); } @@ -63,7 +62,7 @@ public class MongoBlogRepository : MongoDbRepository x.Id).ToList(); - var blogPostCount = await (await GetMongoQueryableAsync(token)) + var blogPostCount = await (await GetQueryableAsync(token)) .Where(blogPost => blogIds.Contains(blogPost.Id)) .GroupBy(blogPost => blogPost.BlogId) .Select(x => new @@ -82,7 +81,7 @@ public class MongoBlogRepository : MongoDbRepository>().LongCountAsync(token); + return await query.LongCountAsync(token); } public virtual Task GetBySlugAsync([NotNull] string slug, CancellationToken cancellationToken = default) @@ -93,7 +92,7 @@ public class MongoBlogRepository : MongoDbRepository> GetListQueryAsync(string filter = null, CancellationToken cancellationToken = default) { - return (await GetMongoQueryableAsync(cancellationToken)) + return (await GetQueryableAsync(cancellationToken)) .WhereIf(!filter.IsNullOrWhiteSpace(), b => b.Name.Contains(filter)); } } diff --git a/modules/cms-kit/src/Volo.CmsKit.MongoDB/Volo/CmsKit/MongoDB/Comments/MongoCommentRepository.cs b/modules/cms-kit/src/Volo.CmsKit.MongoDB/Volo/CmsKit/MongoDB/Comments/MongoCommentRepository.cs index fab729fcd2..5b4566ecb8 100644 --- a/modules/cms-kit/src/Volo.CmsKit.MongoDB/Volo/CmsKit/MongoDB/Comments/MongoCommentRepository.cs +++ b/modules/cms-kit/src/Volo.CmsKit.MongoDB/Volo/CmsKit/MongoDB/Comments/MongoCommentRepository.cs @@ -61,19 +61,18 @@ public class MongoCommentRepository : MongoDbRepository>() - .PageBy>(skipCount, maxResultCount) + .PageBy(skipCount, maxResultCount) .ToListAsync(token); var commentIds = comments.Select(x => x.Id).ToList(); - var authorsQuery = from comment in (await GetMongoQueryableAsync(token)) + var authorsQuery = from comment in (await GetQueryableAsync(token)) join user in (await GetDbContextAsync(token)).CmsUsers on comment.CreatorId equals user.Id where commentIds.Contains(comment.Id) orderby comment.CreationTime select user; - var authors = await ApplyDataFilters, CmsUser>(authorsQuery).ToListAsync(token); + var authors = await ApplyDataFilters, CmsUser>(authorsQuery).ToListAsync(token); return comments .Select( @@ -104,8 +103,7 @@ public class MongoCommentRepository : MongoDbRepository>() - .LongCountAsync(GetCancellationToken(cancellationToken)); + return await query.LongCountAsync(GetCancellationToken(cancellationToken)); } public virtual async Task> GetListWithAuthorsAsync( @@ -117,15 +115,15 @@ public class MongoCommentRepository : MongoDbRepository, CmsUser>(authorsQuery).ToListAsync(GetCancellationToken(cancellationToken)); + var authors = await ApplyDataFilters, CmsUser>(authorsQuery).ToListAsync(GetCancellationToken(cancellationToken)); - var commentsQuery = (await GetMongoQueryableAsync(cancellationToken)) + var commentsQuery = (await GetQueryableAsync(cancellationToken)) .Where(c => c.EntityId == entityId && c.EntityType == entityType); commentsQuery = commentApproveState switch { @@ -152,7 +150,7 @@ public class MongoCommentRepository : MongoDbRepository x.RepliedCommentId == comment.Id) .ToListAsync(GetCancellationToken(cancellationToken)); @@ -172,7 +170,7 @@ public class MongoCommentRepository : MongoDbRepository ExistsAsync(string idempotencyToken, CancellationToken cancellationToken = default) { - return await (await GetMongoQueryableAsync(cancellationToken)) + return await (await GetQueryableAsync(cancellationToken)) .AnyAsync(x => x.IdempotencyToken == idempotencyToken, GetCancellationToken(cancellationToken)); } @@ -187,11 +185,11 @@ public class MongoCommentRepository : MongoDbRepository(cancellationToken)).FirstOrDefaultAsync(x => x.UserName == authorUsername, cancellationToken: cancellationToken); + var author = await (await GetQueryableAsync(cancellationToken)).FirstOrDefaultAsync(x => x.UserName == authorUsername, cancellationToken: cancellationToken); var authorId = author?.Id ?? Guid.Empty; diff --git a/modules/cms-kit/src/Volo.CmsKit.MongoDB/Volo/CmsKit/MongoDB/MarkedItems/MongoUserMarkedItemRepository.cs b/modules/cms-kit/src/Volo.CmsKit.MongoDB/Volo/CmsKit/MongoDB/MarkedItems/MongoUserMarkedItemRepository.cs index 91fbbf996e..ea81fe03ff 100644 --- a/modules/cms-kit/src/Volo.CmsKit.MongoDB/Volo/CmsKit/MongoDB/MarkedItems/MongoUserMarkedItemRepository.cs +++ b/modules/cms-kit/src/Volo.CmsKit.MongoDB/Volo/CmsKit/MongoDB/MarkedItems/MongoUserMarkedItemRepository.cs @@ -24,7 +24,7 @@ public class MongoUserMarkedItemRepository : MongoDbRepository x.CreatorId == userId && x.EntityType == entityType && @@ -39,7 +39,7 @@ public class MongoUserMarkedItemRepository : MongoDbRepository x.CreatorId == userId && x.EntityType == entityType) @@ -49,7 +49,7 @@ public class MongoUserMarkedItemRepository : MongoDbRepository> GetEntityIdsFilteredByUserAsync([NotNull] Guid userId, [NotNull] string entityType, [CanBeNull] Guid? tenantId = null, CancellationToken cancellationToken = default) { var dbContext = await GetDbContextAsync(); - var userMarkedItemQueryable = await GetMongoQueryableAsync(GetCancellationToken(cancellationToken)); + var userMarkedItemQueryable = await GetQueryableAsync(GetCancellationToken(cancellationToken)); var resultQueryable = userMarkedItemQueryable .Where(x => x.CreatorId == userId diff --git a/modules/cms-kit/src/Volo.CmsKit.MongoDB/Volo/CmsKit/MongoDB/Pages/MongoPageRepository.cs b/modules/cms-kit/src/Volo.CmsKit.MongoDB/Volo/CmsKit/MongoDB/Pages/MongoPageRepository.cs index 1b49ac48bb..7c2f9a3891 100644 --- a/modules/cms-kit/src/Volo.CmsKit.MongoDB/Volo/CmsKit/MongoDB/Pages/MongoPageRepository.cs +++ b/modules/cms-kit/src/Volo.CmsKit.MongoDB/Volo/CmsKit/MongoDB/Pages/MongoPageRepository.cs @@ -26,8 +26,8 @@ public class MongoPageRepository : MongoDbRepository>( + return await (await GetQueryableAsync(cancellation)) + .WhereIf( !filter.IsNullOrWhiteSpace(), u => u.Title.ToLower().Contains(filter.ToLower()) || u.Slug.Contains(filter) @@ -43,13 +43,12 @@ public class MongoPageRepository : MongoDbRepository>( + return await (await GetQueryableAsync(cancellation)) + .WhereIf( !filter.IsNullOrWhiteSpace(), u => u.Title.ToLower().Contains(filter) || u.Slug.Contains(filter)) .OrderBy(sorting.IsNullOrEmpty() ? nameof(Page.Title) : sorting) - .As>() - .PageBy>(skipCount, maxResultCount) + .PageBy(skipCount, maxResultCount) .ToListAsync(cancellation); } @@ -68,7 +67,7 @@ public class MongoPageRepository : MongoDbRepository ExistsAsync([NotNull] string slug, CancellationToken cancellationToken = default) { Check.NotNullOrEmpty(slug, nameof(slug)); - return await (await GetMongoQueryableAsync(cancellationToken)).AnyAsync(x => x.Slug == slug, + return await (await GetQueryableAsync(cancellationToken)).AnyAsync(x => x.Slug == slug, GetCancellationToken(cancellationToken)); } @@ -79,7 +78,7 @@ public class MongoPageRepository : MongoDbRepository FindTitleAsync(Guid pageId, CancellationToken cancellationToken = default) { - return await (await GetMongoQueryableAsync(cancellationToken)).Where(x => x.Id == pageId).Select(x => x.Title) + return await (await GetQueryableAsync(cancellationToken)).Where(x => x.Id == pageId).Select(x => x.Title) .FirstOrDefaultAsync(cancellationToken); } } diff --git a/modules/cms-kit/src/Volo.CmsKit.MongoDB/Volo/CmsKit/MongoDB/Ratings/MongoRatingRepository.cs b/modules/cms-kit/src/Volo.CmsKit.MongoDB/Volo/CmsKit/MongoDB/Ratings/MongoRatingRepository.cs index 3a18f31719..d93cad27be 100644 --- a/modules/cms-kit/src/Volo.CmsKit.MongoDB/Volo/CmsKit/MongoDB/Ratings/MongoRatingRepository.cs +++ b/modules/cms-kit/src/Volo.CmsKit.MongoDB/Volo/CmsKit/MongoDB/Ratings/MongoRatingRepository.cs @@ -25,7 +25,7 @@ public class MongoRatingRepository : MongoDbRepository r.EntityType == entityType && r.EntityId == entityId && r.CreatorId == userId, GetCancellationToken(cancellationToken)); @@ -39,7 +39,7 @@ public class MongoRatingRepository : MongoDbRepository x.CreatorId == userId && x.EntityType == entityType && @@ -47,7 +47,7 @@ public class MongoUserReactionRepository : MongoDbRepository x.CreatorId == userId && x.EntityType == entityType && @@ -63,7 +63,7 @@ public class MongoUserReactionRepository : MongoDbRepository x.EntityType == entityType && x.EntityId == entityId) diff --git a/modules/cms-kit/src/Volo.CmsKit.MongoDB/Volo/CmsKit/MongoDB/Tags/MongoEntityTagRepository.cs b/modules/cms-kit/src/Volo.CmsKit.MongoDB/Volo/CmsKit/MongoDB/Tags/MongoEntityTagRepository.cs index 2e8dc96d01..1ce2319a49 100644 --- a/modules/cms-kit/src/Volo.CmsKit.MongoDB/Volo/CmsKit/MongoDB/Tags/MongoEntityTagRepository.cs +++ b/modules/cms-kit/src/Volo.CmsKit.MongoDB/Volo/CmsKit/MongoDB/Tags/MongoEntityTagRepository.cs @@ -67,7 +67,7 @@ public class MongoEntityTagRepository : MongoDbRepository x.EntityType == entityType && x.Name == name, @@ -69,12 +69,12 @@ public class MongoTagRepository : MongoDbRepository(cancellationToken)) + var entityTagIds = await (await GetQueryableAsync(cancellationToken)) .Where(q => q.EntityId == entityId) .Select(q => q.TagId) .ToListAsync(cancellationToken: GetCancellationToken(cancellationToken)); - var query = (await GetMongoQueryableAsync(cancellationToken)) + var query = (await GetQueryableAsync(cancellationToken)) .Where(x => x.EntityType == entityType && entityTagIds.Contains(x.Id)); @@ -86,14 +86,14 @@ public class MongoTagRepository : MongoDbRepository> GetPopularTagsAsync(string entityType, int maxCount, CancellationToken cancellationToken = default) { - var tags = await (await GetMongoQueryableAsync(cancellationToken)) + var tags = await (await GetQueryableAsync(cancellationToken)) .Where(x => x.EntityType == entityType) .Select(x => new { x.Id, x.Name }) .ToListAsync(cancellationToken: GetCancellationToken(cancellationToken)); var tagIds = tags.Select(x => x.Id); - var entityTagCounts = await (await GetMongoQueryableAsync(cancellationToken)) + var entityTagCounts = await (await GetQueryableAsync(cancellationToken)) .Where(q => tagIds.Contains(q.TagId)) .GroupBy(q => q.TagId) .Select(q => new { TagId = q.Key, Count = q.Count() }) @@ -116,8 +116,7 @@ public class MongoTagRepository : MongoDbRepository>() - .PageBy>(skipCount, maxResultCount) + .PageBy(skipCount, maxResultCount) .ToListAsync(GetCancellationToken(cancellationToken)); } @@ -126,9 +125,9 @@ public class MongoTagRepository : MongoDbRepository> GetQueryableByFilterAsync(string filter, CancellationToken cancellationToken = default) + private async Task> GetQueryableByFilterAsync(string filter, CancellationToken cancellationToken = default) { - var mongoQueryable = await GetMongoQueryableAsync(cancellationToken: cancellationToken); + var mongoQueryable = await GetQueryableAsync(cancellationToken: cancellationToken); if (!filter.IsNullOrWhiteSpace()) { diff --git a/modules/cms-kit/test/Volo.CmsKit.MongoDB.Tests/MongoDB/MongoDbFixture.cs b/modules/cms-kit/test/Volo.CmsKit.MongoDB.Tests/MongoDB/MongoDbFixture.cs index 22f63a3780..53c9457a30 100644 --- a/modules/cms-kit/test/Volo.CmsKit.MongoDB.Tests/MongoDB/MongoDbFixture.cs +++ b/modules/cms-kit/test/Volo.CmsKit.MongoDB.Tests/MongoDB/MongoDbFixture.cs @@ -1,5 +1,5 @@ using System; -using EphemeralMongo; +using MongoSandbox; namespace Volo.CmsKit.MongoDB; diff --git a/modules/cms-kit/test/Volo.CmsKit.MongoDB.Tests/Volo.CmsKit.MongoDB.Tests.csproj b/modules/cms-kit/test/Volo.CmsKit.MongoDB.Tests/Volo.CmsKit.MongoDB.Tests.csproj index 17c6dfe717..9c8dc44660 100644 --- a/modules/cms-kit/test/Volo.CmsKit.MongoDB.Tests/Volo.CmsKit.MongoDB.Tests.csproj +++ b/modules/cms-kit/test/Volo.CmsKit.MongoDB.Tests/Volo.CmsKit.MongoDB.Tests.csproj @@ -7,10 +7,10 @@ - - - - + + + + diff --git a/modules/docs/src/Volo.Docs.MongoDB/Volo/Docs/Documents/MongoDocumentRepository.cs b/modules/docs/src/Volo.Docs.MongoDB/Volo/Docs/Documents/MongoDocumentRepository.cs index 7f55ef63b0..081e920cff 100644 --- a/modules/docs/src/Volo.Docs.MongoDB/Volo/Docs/Documents/MongoDocumentRepository.cs +++ b/modules/docs/src/Volo.Docs.MongoDB/Volo/Docs/Documents/MongoDocumentRepository.cs @@ -22,7 +22,7 @@ namespace Volo.Docs.Documents public virtual async Task> GetListWithoutDetailsByProjectId(Guid projectId, CancellationToken cancellationToken = default) { - return await (await GetMongoQueryableAsync(cancellationToken)) + return await (await GetQueryableAsync(cancellationToken)) .Where(d => d.ProjectId == projectId) .Select(x => new DocumentWithoutDetails { @@ -37,7 +37,7 @@ namespace Volo.Docs.Documents public virtual async Task> GetUniqueListDocumentInfoAsync(CancellationToken cancellationToken = default) { - return await (await GetMongoQueryableAsync(cancellationToken)) + return await (await GetQueryableAsync(cancellationToken)) .Select(x=> new DocumentInfo { ProjectId = x.ProjectId, Version = x.Version, @@ -51,13 +51,13 @@ namespace Volo.Docs.Documents public virtual async Task> GetListByProjectId(Guid projectId, CancellationToken cancellationToken = default) { - return await (await GetMongoQueryableAsync(cancellationToken)).Where(d => d.ProjectId == projectId).ToListAsync(GetCancellationToken(cancellationToken)); + return await (await GetQueryableAsync(cancellationToken)).Where(d => d.ProjectId == projectId).ToListAsync(GetCancellationToken(cancellationToken)); } public virtual async Task> GetUniqueDocumentsByProjectIdPagedAsync(Guid projectId, int skipCount, int maxResultCount, CancellationToken cancellationToken = default) { - return await (await GetMongoQueryableAsync(cancellationToken)) + return await (await GetQueryableAsync(cancellationToken)) .Where(d => d.ProjectId == projectId) .OrderBy(x => x.LastCachedTime) .GroupBy(x => new { x.Name, x.LanguageCode, x.Version }) @@ -69,7 +69,7 @@ namespace Volo.Docs.Documents public virtual async Task GetUniqueDocumentCountByProjectIdAsync(Guid projectId, CancellationToken cancellationToken = default) { - return await (await GetMongoQueryableAsync(cancellationToken)).Where(d => d.ProjectId == projectId) + return await (await GetQueryableAsync(cancellationToken)).Where(d => d.ProjectId == projectId) .GroupBy(x => new { x.Name, x.LanguageCode, x.Version }) .LongCountAsync(GetCancellationToken(cancellationToken)); } @@ -89,17 +89,18 @@ namespace Volo.Docs.Documents bool includeDetails = true, CancellationToken cancellationToken = default) { - return await (await GetMongoQueryableAsync(cancellationToken)).FirstOrDefaultAsync(x => x.ProjectId == projectId && - x.Name == name && - x.LanguageCode == languageCode && - x.Version == version, GetCancellationToken(cancellationToken)); + return await (await GetQueryableAsync(cancellationToken)).FirstOrDefaultAsync(x => + x.ProjectId == projectId && + x.Name == name && + x.LanguageCode == languageCode && + x.Version == version, GetCancellationToken(cancellationToken)); } - + public virtual async Task FindAsync(Guid projectId, List possibleNames, string languageCode, string version, bool includeDetails = true, CancellationToken cancellationToken = default) { - return await (await GetMongoQueryableAsync(cancellationToken)).FirstOrDefaultAsync(x => x.ProjectId == projectId && + return await (await GetQueryableAsync(cancellationToken)).FirstOrDefaultAsync(x => x.ProjectId == projectId && possibleNames.Contains(x.Name) && x.LanguageCode == languageCode && x.Version == version, GetCancellationToken(cancellationToken)); @@ -114,11 +115,10 @@ namespace Volo.Docs.Documents public virtual async Task> GetListAsync(Guid? projectId, string version, string name, CancellationToken cancellationToken = default) { - return await (await GetMongoQueryableAsync(cancellationToken)) + return await (await GetQueryableAsync(cancellationToken)) .WhereIf(version != null, x => x.Version == version) .WhereIf(name != null, x => x.Name == name) .WhereIf(projectId.HasValue, x => x.ProjectId == projectId) - .As>() .ToListAsync(GetCancellationToken(cancellationToken)); } @@ -142,26 +142,25 @@ namespace Volo.Docs.Documents int skipCount = 0, CancellationToken cancellationToken = default) { - return await (await ApplyFilterForGetAll( - await GetMongoQueryableAsync(cancellationToken), - projectId: projectId, - name: name, - version: version, - languageCode: languageCode, - fileName: fileName, - format: format, - creationTimeMin: creationTimeMin, - creationTimeMax: creationTimeMax, - lastUpdatedTimeMin: lastUpdatedTimeMin, - lastUpdatedTimeMax: lastUpdatedTimeMax, - lastSignificantUpdateTimeMin: lastSignificantUpdateTimeMin, - lastSignificantUpdateTimeMax: lastSignificantUpdateTimeMax, - lastCachedTimeMin: lastCachedTimeMin, lastCachedTimeMax: lastCachedTimeMax)) - .OrderBy(string.IsNullOrWhiteSpace(sorting) ? "name asc" : sorting).As>() - .PageBy>(skipCount, maxResultCount) - .ToListAsync(GetCancellationToken(cancellationToken)); + await GetQueryableAsync(cancellationToken), + projectId: projectId, + name: name, + version: version, + languageCode: languageCode, + fileName: fileName, + format: format, + creationTimeMin: creationTimeMin, + creationTimeMax: creationTimeMax, + lastUpdatedTimeMin: lastUpdatedTimeMin, + lastUpdatedTimeMax: lastUpdatedTimeMax, + lastSignificantUpdateTimeMin: lastSignificantUpdateTimeMin, + lastSignificantUpdateTimeMax: lastSignificantUpdateTimeMax, + lastCachedTimeMin: lastCachedTimeMin, lastCachedTimeMax: lastCachedTimeMax, cancellationToken: cancellationToken)) + .OrderBy(string.IsNullOrWhiteSpace(sorting) ? "name asc" : sorting) + .PageBy(skipCount, maxResultCount) + .ToListAsync(GetCancellationToken(cancellationToken)); } public virtual async Task GetAllCountAsync( @@ -184,36 +183,35 @@ namespace Volo.Docs.Documents int skipCount = 0, CancellationToken cancellationToken = default) { - - return await (await ApplyFilterForGetAll( - await GetMongoQueryableAsync(cancellationToken), - projectId: projectId, - name: name, - version: version, - languageCode: languageCode, - fileName: fileName, - format: format, - creationTimeMin: creationTimeMin, - creationTimeMax: creationTimeMax, - lastUpdatedTimeMin: lastUpdatedTimeMin, - lastUpdatedTimeMax: lastUpdatedTimeMax, - lastSignificantUpdateTimeMin: lastSignificantUpdateTimeMin, - lastSignificantUpdateTimeMax: lastSignificantUpdateTimeMax, - lastCachedTimeMin: lastCachedTimeMin, lastCachedTimeMax: lastCachedTimeMax)) - .OrderBy(string.IsNullOrWhiteSpace(sorting) ? "name asc" : sorting).As>() - .PageBy>(skipCount, maxResultCount) - .LongCountAsync(GetCancellationToken(cancellationToken)); + await GetQueryableAsync(cancellationToken), + projectId: projectId, + name: name, + version: version, + languageCode: languageCode, + fileName: fileName, + format: format, + creationTimeMin: creationTimeMin, + creationTimeMax: creationTimeMax, + lastUpdatedTimeMin: lastUpdatedTimeMin, + lastUpdatedTimeMax: lastUpdatedTimeMax, + lastSignificantUpdateTimeMin: lastSignificantUpdateTimeMin, + lastSignificantUpdateTimeMax: lastSignificantUpdateTimeMax, + lastCachedTimeMin: lastCachedTimeMin, lastCachedTimeMax: lastCachedTimeMax, + cancellationToken: cancellationToken)) + .OrderBy(string.IsNullOrWhiteSpace(sorting) ? "name asc" : sorting) + .PageBy(skipCount, maxResultCount) + .LongCountAsync(GetCancellationToken(cancellationToken)); } public virtual async Task GetAsync(Guid id, CancellationToken cancellationToken = default) { - return await (await GetMongoQueryableAsync(cancellationToken)).Where(x => x.Id == id).SingleAsync(GetCancellationToken(cancellationToken)); + return await (await GetQueryableAsync(cancellationToken)).Where(x => x.Id == id).SingleAsync(GetCancellationToken(cancellationToken)); } - - protected virtual async Task> ApplyFilterForGetAll( - IMongoQueryable query, + + protected virtual async Task> ApplyFilterForGetAll( + IQueryable query, Guid? projectId, string name, string version, @@ -254,7 +252,7 @@ namespace Volo.Docs.Documents { query = query.Where(d => d.FileName != null && d.FileName.Contains(fileName)); } - + if (format != null) { query = query.Where(d => d.Format != null && d.Format == format); diff --git a/modules/docs/src/Volo.Docs.MongoDB/Volo/Docs/Projects/MongoProjectRepository.cs b/modules/docs/src/Volo.Docs.MongoDB/Volo/Docs/Projects/MongoProjectRepository.cs index 3960b07eb3..af54bd6bc5 100644 --- a/modules/docs/src/Volo.Docs.MongoDB/Volo/Docs/Projects/MongoProjectRepository.cs +++ b/modules/docs/src/Volo.Docs.MongoDB/Volo/Docs/Projects/MongoProjectRepository.cs @@ -22,8 +22,7 @@ namespace Volo.Docs.Projects public virtual async Task> GetListAsync(string sorting, int maxResultCount, int skipCount, CancellationToken cancellationToken = default) { - var projects = await (await GetMongoQueryableAsync(cancellationToken)).OrderBy(sorting.IsNullOrEmpty() ? "Id desc" : sorting).As>() - .PageBy>(skipCount, maxResultCount) + var projects = await (await GetQueryableAsync(cancellationToken)).OrderBy(sorting.IsNullOrEmpty() ? "Id desc" : sorting).PageBy(skipCount, maxResultCount) .ToListAsync(GetCancellationToken(cancellationToken)); return projects; @@ -31,7 +30,7 @@ namespace Volo.Docs.Projects public virtual async Task> GetListWithoutDetailsAsync(CancellationToken cancellationToken = default) { - return await (await GetMongoQueryableAsync(cancellationToken)) + return await (await GetQueryableAsync(cancellationToken)) .Select(x=> new ProjectWithoutDetails { Id = x.Id, Name = x.Name, @@ -44,7 +43,7 @@ namespace Volo.Docs.Projects { var normalizeShortName = NormalizeShortName(shortName); - var project = await (await GetMongoQueryableAsync(cancellationToken)).FirstOrDefaultAsync(p => p.ShortName == normalizeShortName, GetCancellationToken(cancellationToken)); + var project = await (await GetQueryableAsync(cancellationToken)).FirstOrDefaultAsync(p => p.ShortName == normalizeShortName, GetCancellationToken(cancellationToken)); if (project == null) { @@ -58,7 +57,7 @@ namespace Volo.Docs.Projects { var normalizeShortName = NormalizeShortName(shortName); - return await (await GetMongoQueryableAsync(cancellationToken)).AnyAsync(x => x.ShortName == normalizeShortName, GetCancellationToken(cancellationToken)); + return await (await GetQueryableAsync(cancellationToken)).AnyAsync(x => x.ShortName == normalizeShortName, GetCancellationToken(cancellationToken)); } private string NormalizeShortName(string shortName) diff --git a/modules/docs/test/Volo.Docs.MongoDB.Tests/Volo.Docs.MongoDB.Tests.csproj b/modules/docs/test/Volo.Docs.MongoDB.Tests/Volo.Docs.MongoDB.Tests.csproj index 5c3f98c351..90df72d01d 100644 --- a/modules/docs/test/Volo.Docs.MongoDB.Tests/Volo.Docs.MongoDB.Tests.csproj +++ b/modules/docs/test/Volo.Docs.MongoDB.Tests/Volo.Docs.MongoDB.Tests.csproj @@ -7,10 +7,10 @@ - - - - + + + + diff --git a/modules/docs/test/Volo.Docs.MongoDB.Tests/Volo/Docs/MongoDB/MongoDbFixture.cs b/modules/docs/test/Volo.Docs.MongoDB.Tests/Volo/Docs/MongoDB/MongoDbFixture.cs index ad1fce80e5..e1a4d00ce3 100644 --- a/modules/docs/test/Volo.Docs.MongoDB.Tests/Volo/Docs/MongoDB/MongoDbFixture.cs +++ b/modules/docs/test/Volo.Docs.MongoDB.Tests/Volo/Docs/MongoDB/MongoDbFixture.cs @@ -1,5 +1,5 @@ using System; -using EphemeralMongo; +using MongoSandbox; public class MongoDbFixture : IDisposable { diff --git a/modules/feature-management/src/Volo.Abp.FeatureManagement.MongoDB/Volo/Abp/FeatureManagement/MongoDB/MongoFeatureDefinitionRecordRepository.cs b/modules/feature-management/src/Volo.Abp.FeatureManagement.MongoDB/Volo/Abp/FeatureManagement/MongoDB/MongoFeatureDefinitionRecordRepository.cs index cb7f48aeb4..e89a68a710 100644 --- a/modules/feature-management/src/Volo.Abp.FeatureManagement.MongoDB/Volo/Abp/FeatureManagement/MongoDB/MongoFeatureDefinitionRecordRepository.cs +++ b/modules/feature-management/src/Volo.Abp.FeatureManagement.MongoDB/Volo/Abp/FeatureManagement/MongoDB/MongoFeatureDefinitionRecordRepository.cs @@ -1,6 +1,7 @@ using System; using System.Threading; using System.Threading.Tasks; +using System.Linq; using MongoDB.Driver.Linq; using Volo.Abp.Domain.Repositories.MongoDB; using Volo.Abp.MongoDB; @@ -20,7 +21,7 @@ public class MongoFeatureDefinitionRecordRepository : public virtual async Task FindByNameAsync(string name, CancellationToken cancellationToken = default) { cancellationToken = GetCancellationToken(cancellationToken); - return await (await GetMongoQueryableAsync(cancellationToken)) + return await (await GetQueryableAsync(cancellationToken)) .OrderBy(x => x.Id) .FirstOrDefaultAsync( s => s.Name == name, 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 3b52fe2634..0eb4f07e2f 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 @@ -27,7 +27,7 @@ public class MongoFeatureValueRepository : string providerKey, CancellationToken cancellationToken = default) { - return await (await GetMongoQueryableAsync(cancellationToken)) + return await (await GetQueryableAsync(cancellationToken)) .OrderBy(x => x.Id) .FirstOrDefaultAsync(s => s.Name == name && s.ProviderName == providerName && s.ProviderKey == providerKey, GetCancellationToken(cancellationToken)); } @@ -38,7 +38,7 @@ public class MongoFeatureValueRepository : string providerKey, CancellationToken cancellationToken = default) { - return await (await GetMongoQueryableAsync(cancellationToken)) + return await (await GetQueryableAsync(cancellationToken)) .Where(s => s.Name == name && s.ProviderName == providerName && s.ProviderKey == providerKey).ToListAsync(GetCancellationToken(cancellationToken)); } @@ -47,7 +47,7 @@ public class MongoFeatureValueRepository : string providerKey, CancellationToken cancellationToken = default) { - return await (await GetMongoQueryableAsync(cancellationToken)) + return await (await GetQueryableAsync(cancellationToken)) .Where(s => s.ProviderName == providerName && s.ProviderKey == providerKey) .ToListAsync(GetCancellationToken(cancellationToken)); } diff --git a/modules/feature-management/test/Volo.Abp.FeatureManagement.MongoDB.Tests/Volo.Abp.FeatureManagement.MongoDB.Tests.csproj b/modules/feature-management/test/Volo.Abp.FeatureManagement.MongoDB.Tests/Volo.Abp.FeatureManagement.MongoDB.Tests.csproj index bfc01a429f..2f7f5ee7d0 100644 --- a/modules/feature-management/test/Volo.Abp.FeatureManagement.MongoDB.Tests/Volo.Abp.FeatureManagement.MongoDB.Tests.csproj +++ b/modules/feature-management/test/Volo.Abp.FeatureManagement.MongoDB.Tests/Volo.Abp.FeatureManagement.MongoDB.Tests.csproj @@ -14,10 +14,10 @@ - - - - + + + + diff --git a/modules/feature-management/test/Volo.Abp.FeatureManagement.MongoDB.Tests/Volo/Abp/FeatureManagement/MongoDB/MongoDbFixture.cs b/modules/feature-management/test/Volo.Abp.FeatureManagement.MongoDB.Tests/Volo/Abp/FeatureManagement/MongoDB/MongoDbFixture.cs index 8088afee7b..23a5403281 100644 --- a/modules/feature-management/test/Volo.Abp.FeatureManagement.MongoDB.Tests/Volo/Abp/FeatureManagement/MongoDB/MongoDbFixture.cs +++ b/modules/feature-management/test/Volo.Abp.FeatureManagement.MongoDB.Tests/Volo/Abp/FeatureManagement/MongoDB/MongoDbFixture.cs @@ -1,5 +1,5 @@ using System; -using EphemeralMongo; +using MongoSandbox; namespace Volo.Abp.FeatureManagement.MongoDB; diff --git a/modules/identity/src/Volo.Abp.Identity.MongoDB/Volo/Abp/Identity/MongoDB/MongoIdentityClaimTypeRepository.cs b/modules/identity/src/Volo.Abp.Identity.MongoDB/Volo/Abp/Identity/MongoDB/MongoIdentityClaimTypeRepository.cs index ac0b86dee9..6a24fd8ed9 100644 --- a/modules/identity/src/Volo.Abp.Identity.MongoDB/Volo/Abp/Identity/MongoDB/MongoIdentityClaimTypeRepository.cs +++ b/modules/identity/src/Volo.Abp.Identity.MongoDB/Volo/Abp/Identity/MongoDB/MongoIdentityClaimTypeRepository.cs @@ -24,13 +24,13 @@ public class MongoIdentityClaimTypeRepository : MongoDbRepository ct.Name == name) .AnyAsync(GetCancellationToken(cancellationToken)); } else { - return await (await GetMongoQueryableAsync(cancellationToken)) + return await (await GetQueryableAsync(cancellationToken)) .Where(ct => ct.Id != ignoredId && ct.Name == name) .AnyAsync(GetCancellationToken(cancellationToken)); } @@ -43,15 +43,14 @@ public class MongoIdentityClaimTypeRepository : MongoDbRepository>( + return await (await GetQueryableAsync(cancellationToken)) + .WhereIf( !filter.IsNullOrWhiteSpace(), u => u.Name.Contains(filter) ) .OrderBy(sorting.IsNullOrWhiteSpace() ? nameof(IdentityClaimType.CreationTime) + " desc" : sorting) - .As>() - .PageBy>(skipCount, maxResultCount) + .PageBy(skipCount, maxResultCount) .ToListAsync(GetCancellationToken(cancellationToken)); } @@ -59,19 +58,18 @@ public class MongoIdentityClaimTypeRepository : MongoDbRepository>( + return await (await GetQueryableAsync(cancellationToken)) + .WhereIf( !filter.IsNullOrWhiteSpace(), u => u.Name.Contains(filter) ) - .As>() .LongCountAsync(GetCancellationToken(cancellationToken)); } public virtual async Task> GetListByNamesAsync(IEnumerable names, CancellationToken cancellationToken = default) { - return await (await GetMongoQueryableAsync(cancellationToken)) + return await (await GetQueryableAsync(cancellationToken)) .Where(x => names.Contains(x.Name)) .ToListAsync(GetCancellationToken(cancellationToken)); } diff --git a/modules/identity/src/Volo.Abp.Identity.MongoDB/Volo/Abp/Identity/MongoDB/MongoIdentityLinkUserRepository.cs b/modules/identity/src/Volo.Abp.Identity.MongoDB/Volo/Abp/Identity/MongoDB/MongoIdentityLinkUserRepository.cs index 20116fdd0b..46cfc60eb3 100644 --- a/modules/identity/src/Volo.Abp.Identity.MongoDB/Volo/Abp/Identity/MongoDB/MongoIdentityLinkUserRepository.cs +++ b/modules/identity/src/Volo.Abp.Identity.MongoDB/Volo/Abp/Identity/MongoDB/MongoIdentityLinkUserRepository.cs @@ -18,7 +18,7 @@ public class MongoIdentityLinkUserRepository : MongoDbRepository FindAsync(IdentityLinkUserInfo sourceLinkUserInfo, IdentityLinkUserInfo targetLinkUserInfo, CancellationToken cancellationToken = default) { - return await (await GetMongoQueryableAsync(cancellationToken)) + return await (await GetQueryableAsync(cancellationToken)) .OrderBy(x => x.Id).FirstOrDefaultAsync(x => x.SourceUserId == sourceLinkUserInfo.UserId && x.SourceTenantId == sourceLinkUserInfo.TenantId && x.TargetUserId == targetLinkUserInfo.UserId && x.TargetTenantId == targetLinkUserInfo.TenantId || @@ -30,7 +30,7 @@ public class MongoIdentityLinkUserRepository : MongoDbRepository> GetListAsync(IdentityLinkUserInfo linkUserInfo, List excludes = null, CancellationToken cancellationToken = default) { - var query = (await GetMongoQueryableAsync(cancellationToken)).Where(x => + var query = (await GetQueryableAsync(cancellationToken)).Where(x => x.SourceUserId == linkUserInfo.UserId && x.SourceTenantId == linkUserInfo.TenantId || x.TargetUserId == linkUserInfo.UserId && x.TargetTenantId == linkUserInfo.TenantId); @@ -49,7 +49,7 @@ public class MongoIdentityLinkUserRepository : MongoDbRepository + var linkUsers = await (await GetQueryableAsync(cancellationToken)).Where(x => x.SourceUserId == linkUserInfo.UserId && x.SourceTenantId == linkUserInfo.TenantId || x.TargetUserId == linkUserInfo.UserId && x.TargetTenantId == linkUserInfo.TenantId) .ToListAsync(cancellationToken: GetCancellationToken(cancellationToken)); diff --git a/modules/identity/src/Volo.Abp.Identity.MongoDB/Volo/Abp/Identity/MongoDB/MongoIdentityRoleRepository.cs b/modules/identity/src/Volo.Abp.Identity.MongoDB/Volo/Abp/Identity/MongoDB/MongoIdentityRoleRepository.cs index 3a57f69902..f977572a04 100644 --- a/modules/identity/src/Volo.Abp.Identity.MongoDB/Volo/Abp/Identity/MongoDB/MongoIdentityRoleRepository.cs +++ b/modules/identity/src/Volo.Abp.Identity.MongoDB/Volo/Abp/Identity/MongoDB/MongoIdentityRoleRepository.cs @@ -23,7 +23,7 @@ public class MongoIdentityRoleRepository : MongoDbRepository x.Id) .FirstOrDefaultAsync(r => r.NormalizedName == normalizedRoleName, GetCancellationToken(cancellationToken)); } @@ -38,7 +38,7 @@ public class MongoIdentityRoleRepository : MongoDbRepository x.Id).ToList(); - var userCount = await (await GetMongoQueryableAsync(cancellationToken)) + var userCount = await (await GetQueryableAsync(cancellationToken)) .Where(user => user.Roles.Any(role => roleIds.Contains(role.RoleId))) .SelectMany(user => user.Roles) .GroupBy(userRole => userRole.RoleId) @@ -73,7 +73,7 @@ public class MongoIdentityRoleRepository : MongoDbRepository ids, CancellationToken cancellationToken = default) { - return await (await GetMongoQueryableAsync(cancellationToken)) + return await (await GetQueryableAsync(cancellationToken)) .Where(t => ids.Contains(t.Id)) .ToListAsync(GetCancellationToken(cancellationToken)); } @@ -82,7 +82,7 @@ public class MongoIdentityRoleRepository : MongoDbRepository r.IsDefault) .ToListAsync(GetCancellationToken(cancellationToken)); } @@ -91,17 +91,16 @@ public class MongoIdentityRoleRepository : MongoDbRepository x.Name.Contains(filter) || x.NormalizedName.Contains(filter)) - .As>() .LongCountAsync(GetCancellationToken(cancellationToken)); } public virtual async Task RemoveClaimFromAllRolesAsync(string claimType, bool autoSave = false, CancellationToken cancellationToken = default) { - var roles = await (await GetMongoQueryableAsync(cancellationToken)) + var roles = await (await GetQueryableAsync(cancellationToken)) .Where(r => r.Claims.Any(c => c.ClaimType == claimType)) .ToListAsync(GetCancellationToken(cancellationToken)); @@ -121,13 +120,12 @@ public class MongoIdentityRoleRepository : MongoDbRepository x.Name.Contains(filter) || x.NormalizedName.Contains(filter)) .OrderBy(sorting.IsNullOrWhiteSpace() ? nameof(IdentityRole.CreationTime) + " desc" : sorting) - .As>() - .PageBy>(skipCount, maxResultCount) + .PageBy(skipCount, maxResultCount) .ToListAsync(GetCancellationToken(cancellationToken)); } } diff --git a/modules/identity/src/Volo.Abp.Identity.MongoDB/Volo/Abp/Identity/MongoDB/MongoIdentitySecurityLogRepository.cs b/modules/identity/src/Volo.Abp.Identity.MongoDB/Volo/Abp/Identity/MongoDB/MongoIdentitySecurityLogRepository.cs index f173272009..388c059f1f 100644 --- a/modules/identity/src/Volo.Abp.Identity.MongoDB/Volo/Abp/Identity/MongoDB/MongoIdentitySecurityLogRepository.cs +++ b/modules/identity/src/Volo.Abp.Identity.MongoDB/Volo/Abp/Identity/MongoDB/MongoIdentitySecurityLogRepository.cs @@ -51,8 +51,7 @@ public class MongoIdentitySecurityLogRepository : ); return await query.OrderBy(sorting.IsNullOrWhiteSpace() ? $"{nameof(IdentitySecurityLog.CreationTime)} desc" : sorting) - .As>() - .PageBy>(skipCount, maxResultCount) + .PageBy(skipCount, maxResultCount) .ToListAsync(GetCancellationToken(cancellationToken)); } @@ -83,15 +82,14 @@ public class MongoIdentitySecurityLogRepository : cancellationToken ); - return await query.As>() - .LongCountAsync(GetCancellationToken(cancellationToken)); + return await query.LongCountAsync(GetCancellationToken(cancellationToken)); } public virtual async Task GetByUserIdAsync(Guid id, Guid userId, bool includeDetails = false, CancellationToken cancellationToken = default) { - return await (await GetMongoQueryableAsync(cancellationToken)).OrderBy(x => x.Id).FirstOrDefaultAsync(x => x.Id == id && x.UserId == userId, + return await (await GetQueryableAsync(cancellationToken)).OrderBy(x => x.Id).FirstOrDefaultAsync(x => x.Id == id && x.UserId == userId, GetCancellationToken(cancellationToken)); } @@ -108,7 +106,7 @@ public class MongoIdentitySecurityLogRepository : string clientIpAddress = null, CancellationToken cancellationToken = default) { - return (await GetMongoQueryableAsync(cancellationToken)) + return (await GetQueryableAsync(cancellationToken)) .WhereIf(startTime.HasValue, securityLog => securityLog.CreationTime >= startTime.Value) .WhereIf(endTime.HasValue, securityLog => securityLog.CreationTime < endTime.Value.AddDays(1).Date) .WhereIf(!applicationName.IsNullOrWhiteSpace(), securityLog => securityLog.ApplicationName == applicationName) diff --git a/modules/identity/src/Volo.Abp.Identity.MongoDB/Volo/Abp/Identity/MongoDB/MongoIdentitySessionRepository.cs b/modules/identity/src/Volo.Abp.Identity.MongoDB/Volo/Abp/Identity/MongoDB/MongoIdentitySessionRepository.cs index a1a8f94c49..eb3f99e688 100644 --- a/modules/identity/src/Volo.Abp.Identity.MongoDB/Volo/Abp/Identity/MongoDB/MongoIdentitySessionRepository.cs +++ b/modules/identity/src/Volo.Abp.Identity.MongoDB/Volo/Abp/Identity/MongoDB/MongoIdentitySessionRepository.cs @@ -23,8 +23,7 @@ public class MongoIdentitySessionRepository : MongoDbRepository FindAsync(string sessionId, CancellationToken cancellationToken = default) { - return await (await GetMongoQueryableAsync(GetCancellationToken(cancellationToken))) - .As>() + return await (await GetQueryableAsync(GetCancellationToken(cancellationToken))) .FirstOrDefaultAsync(x => x.SessionId == sessionId, GetCancellationToken(cancellationToken)); } @@ -41,15 +40,13 @@ public class MongoIdentitySessionRepository : MongoDbRepository ExistAsync(Guid id, CancellationToken cancellationToken = default) { - return await (await GetMongoQueryableAsync(GetCancellationToken(cancellationToken))) - .As>() + return await (await GetQueryableAsync(GetCancellationToken(cancellationToken))) .AnyAsync(x => x.Id == id, GetCancellationToken(cancellationToken)); } public virtual async Task ExistAsync(string sessionId, CancellationToken cancellationToken = default) { - return await (await GetMongoQueryableAsync(GetCancellationToken(cancellationToken))) - .As>() + return await (await GetQueryableAsync(GetCancellationToken(cancellationToken))) .AnyAsync(x => x.SessionId == sessionId, GetCancellationToken(cancellationToken)); } @@ -62,13 +59,12 @@ public class MongoIdentitySessionRepository : MongoDbRepository x.UserId == userId) .WhereIf(!device.IsNullOrWhiteSpace(), x => x.Device == device) .WhereIf(!clientId.IsNullOrWhiteSpace(), x => x.ClientId == clientId) .OrderBy(sorting.IsNullOrWhiteSpace() ? $"{nameof(IdentitySession.LastAccessed)} desc" : sorting) .PageBy(skipCount, maxResultCount) - .As>() .ToListAsync(GetCancellationToken(cancellationToken)); } @@ -78,11 +74,10 @@ public class MongoIdentitySessionRepository : MongoDbRepository x.UserId == userId) .WhereIf(!device.IsNullOrWhiteSpace(), x => x.Device == device) .WhereIf(!clientId.IsNullOrWhiteSpace(), x => x.ClientId == clientId) - .As>() .LongCountAsync(GetCancellationToken(cancellationToken)); } diff --git a/modules/identity/src/Volo.Abp.Identity.MongoDB/Volo/Abp/Identity/MongoDB/MongoIdentityUserDelegationRepository.cs b/modules/identity/src/Volo.Abp.Identity.MongoDB/Volo/Abp/Identity/MongoDB/MongoIdentityUserDelegationRepository.cs index 56cc48121e..1855069b4a 100644 --- a/modules/identity/src/Volo.Abp.Identity.MongoDB/Volo/Abp/Identity/MongoDB/MongoIdentityUserDelegationRepository.cs +++ b/modules/identity/src/Volo.Abp.Identity.MongoDB/Volo/Abp/Identity/MongoDB/MongoIdentityUserDelegationRepository.cs @@ -24,25 +24,23 @@ public class MongoIdentityUserDelegationRepository : MongoDbRepository> GetListAsync(Guid? sourceUserId, Guid? targetUserId, CancellationToken cancellationToken = default) { - return await (await GetMongoQueryableAsync(cancellationToken)) + return await (await GetQueryableAsync(cancellationToken)) .WhereIf(sourceUserId.HasValue, x => x.SourceUserId == sourceUserId) .WhereIf(targetUserId.HasValue, x => x.TargetUserId == targetUserId) - .As>() .ToListAsync(cancellationToken: cancellationToken); } public virtual async Task> GetActiveDelegationsAsync(Guid targetUserId, CancellationToken cancellationToken = default) { - return await (await GetMongoQueryableAsync(cancellationToken)) + return await (await GetQueryableAsync(cancellationToken)) .Where(x => x.TargetUserId == targetUserId) .Where(x => x.StartTime <= Clock.Now && x.EndTime >= Clock.Now) - .As>() .ToListAsync(cancellationToken: cancellationToken); } public virtual async Task FindActiveDelegationByIdAsync(Guid id, CancellationToken cancellationToken = default) { - return await (await GetMongoQueryableAsync(cancellationToken)) + return await (await GetQueryableAsync(cancellationToken)) .FirstOrDefaultAsync(x => x.Id == id && x.StartTime <= Clock.Now && 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 58486893ec..c93a41e21d 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 @@ -25,7 +25,7 @@ public class MongoIdentityUserRepository : MongoDbRepository x.Id) .FirstOrDefaultAsync( u => u.NormalizedUserName == normalizedUserName, @@ -43,13 +43,13 @@ public class MongoIdentityUserRepository : MongoDbRepository r.OrganizationUnitId) .ToArray(); - var organizationUnits = await (await GetMongoQueryableAsync(cancellationToken)) + var organizationUnits = await (await GetQueryableAsync(cancellationToken)) .Where(ou => organizationUnitIds.Contains(ou.Id)) .ToListAsync(cancellationToken: cancellationToken); var orgUnitRoleIds = organizationUnits.SelectMany(x => x.Roles.Select(r => r.RoleId)).ToArray(); var roleIds = user.Roles.Select(r => r.RoleId).ToArray(); var allRoleIds = orgUnitRoleIds.Union(roleIds); - return await (await GetMongoQueryableAsync(cancellationToken)).Where(r => allRoleIds.Contains(r.Id)).Select(r => r.Name).ToListAsync(cancellationToken); + return await (await GetQueryableAsync(cancellationToken)).Where(r => allRoleIds.Contains(r.Id)).Select(r => r.Name).ToListAsync(cancellationToken); } public virtual async Task> GetRoleNamesInOrganizationUnitAsync( @@ -63,13 +63,13 @@ public class MongoIdentityUserRepository : MongoDbRepository r.OrganizationUnitId) .ToArray(); - var organizationUnits = await (await GetMongoQueryableAsync(cancellationToken)) + var organizationUnits = await (await GetQueryableAsync(cancellationToken)) .Where(ou => organizationUnitIds.Contains(ou.Id)) .ToListAsync(cancellationToken: cancellationToken); var roleIds = organizationUnits.SelectMany(x => x.Roles.Select(r => r.RoleId)).ToArray(); - var queryable = await GetMongoQueryableAsync(cancellationToken); + var queryable = await GetQueryableAsync(cancellationToken); return await queryable .Where(r => roleIds.Contains(r.Id)) @@ -83,7 +83,7 @@ public class MongoIdentityUserRepository : MongoDbRepository u.Logins.Any(login => login.LoginProvider == loginProvider && login.ProviderKey == providerKey)) .OrderBy(x => x.Id) .FirstOrDefaultAsync(GetCancellationToken(cancellationToken)); @@ -94,7 +94,7 @@ public class MongoIdentityUserRepository : MongoDbRepository x.Id).FirstOrDefaultAsync(u => u.NormalizedEmail == normalizedEmail, GetCancellationToken(cancellationToken)); } @@ -103,14 +103,14 @@ public class MongoIdentityUserRepository : MongoDbRepository u.Claims.Any(c => c.ClaimType == claim.Type && c.ClaimValue == claim.Value)) .ToListAsync(GetCancellationToken(cancellationToken)); } public virtual async Task RemoveClaimFromAllUsersAsync(string claimType, bool autoSave, CancellationToken cancellationToken = default) { - var users = await (await GetMongoQueryableAsync(cancellationToken)) + var users = await (await GetQueryableAsync(cancellationToken)) .Where(u => u.Claims.Any(c => c.ClaimType == claimType)) .ToListAsync(GetCancellationToken(cancellationToken)); @@ -129,7 +129,7 @@ public class MongoIdentityUserRepository : MongoDbRepository(cancellationToken); + var queryable = await GetQueryableAsync(cancellationToken); var role = await queryable .Where(x => x.NormalizedName == normalizedRoleName) @@ -141,7 +141,7 @@ public class MongoIdentityUserRepository : MongoDbRepository(); } - return await (await GetMongoQueryableAsync(cancellationToken)) + return await (await GetQueryableAsync(cancellationToken)) .Where(u => u.Roles.Any(r => r.RoleId == role.Id)) .ToListAsync(cancellationToken); } @@ -150,7 +150,7 @@ public class MongoIdentityUserRepository : MongoDbRepository u.Roles.Any(r => r.RoleId == roleId)) .Select(x => x.Id) .ToListAsync(cancellationToken); @@ -201,8 +201,7 @@ public class MongoIdentityUserRepository : MongoDbRepository>() - .PageBy>(skipCount, maxResultCount) + .PageBy(skipCount, maxResultCount) .ToListAsync(GetCancellationToken(cancellationToken)); } @@ -217,13 +216,13 @@ public class MongoIdentityUserRepository : MongoDbRepository r.OrganizationUnitId) .ToArray(); - var organizationUnits = await (await GetMongoQueryableAsync(cancellationToken)) + var organizationUnits = await (await GetQueryableAsync(cancellationToken)) .Where(ou => organizationUnitIds.Contains(ou.Id)) .ToListAsync(cancellationToken: cancellationToken); var orgUnitRoleIds = organizationUnits.SelectMany(x => x.Roles.Select(r => r.RoleId)).ToArray(); var roleIds = user.Roles.Select(r => r.RoleId).ToArray(); var allRoleIds = orgUnitRoleIds.Union(roleIds); - return await (await GetMongoQueryableAsync(cancellationToken)).Where(r => allRoleIds.Contains(r.Id)).ToListAsync(cancellationToken); + return await (await GetQueryableAsync(cancellationToken)).Where(r => allRoleIds.Contains(r.Id)).ToListAsync(cancellationToken); } public virtual async Task> GetOrganizationUnitsAsync( @@ -235,7 +234,7 @@ public class MongoIdentityUserRepository : MongoDbRepository r.OrganizationUnitId); - return await (await GetMongoQueryableAsync(cancellationToken)) + return await (await GetQueryableAsync(cancellationToken)) .Where(ou => organizationUnitIds.Contains(ou.Id)) .ToListAsync(cancellationToken); } @@ -286,7 +285,7 @@ public class MongoIdentityUserRepository : MongoDbRepository u.OrganizationUnits.Any(uou => uou.OrganizationUnitId == organizationUnitId)) .ToListAsync(GetCancellationToken(cancellationToken)); return result; @@ -296,7 +295,7 @@ public class MongoIdentityUserRepository : MongoDbRepository organizationUnitIds, CancellationToken cancellationToken = default) { - var result = await (await GetMongoQueryableAsync(cancellationToken)) + var result = await (await GetQueryableAsync(cancellationToken)) .Where(u => u.OrganizationUnits.Any(uou => organizationUnitIds.Contains(uou.OrganizationUnitId))) .ToListAsync(GetCancellationToken(cancellationToken)); return result; @@ -308,12 +307,12 @@ public class MongoIdentityUserRepository : MongoDbRepository(cancellationToken)) + var organizationUnitIds = await (await GetQueryableAsync(cancellationToken)) .Where(ou => ou.Code.StartsWith(code)) .Select(ou => ou.Id) .ToListAsync(cancellationToken); - return await (await GetMongoQueryableAsync(cancellationToken)) + return await (await GetQueryableAsync(cancellationToken)) .Where(u => u.OrganizationUnits.Any(uou => organizationUnitIds.Contains(uou.OrganizationUnitId))) .ToListAsync(cancellationToken); } @@ -324,7 +323,7 @@ public class MongoIdentityUserRepository : MongoDbRepository u.TenantId == tenantId && u.UserName == userName, GetCancellationToken(cancellationToken) @@ -333,14 +332,14 @@ public class MongoIdentityUserRepository : MongoDbRepository> GetListByIdsAsync(IEnumerable ids, bool includeDetails = false, CancellationToken cancellationToken = default) { - return await (await GetMongoQueryableAsync(cancellationToken)) + return await (await GetQueryableAsync(cancellationToken)) .Where(x => ids.Contains(x.Id)) .ToListAsync(GetCancellationToken(cancellationToken)); } public virtual async Task UpdateRoleAsync(Guid sourceRoleId, Guid? targetRoleId, CancellationToken cancellationToken = default) { - var users = await (await GetMongoQueryableAsync(cancellationToken)) + var users = await (await GetQueryableAsync(cancellationToken)) .Where(x => x.Roles.Any(r => r.RoleId == sourceRoleId)) .ToListAsync(GetCancellationToken(cancellationToken)); @@ -358,7 +357,7 @@ public class MongoIdentityUserRepository : MongoDbRepository x.OrganizationUnits.Any(r => r.OrganizationUnitId == sourceOrganizationId)) .ToListAsync(GetCancellationToken(cancellationToken)); @@ -390,7 +389,7 @@ public class MongoIdentityUserRepository : MongoDbRepository x.Value); var roleIds = userAndRoleIds.SelectMany(x => x.Value); - var organizationUnitAndRoleIds = await (await GetMongoQueryableAsync(cancellationToken)).Where(ou => organizationUnitIds.Contains(ou.Id)) + var organizationUnitAndRoleIds = await (await GetQueryableAsync(cancellationToken)).Where(ou => organizationUnitIds.Contains(ou.Id)) .Select(userOrganizationUnit => new { userOrganizationUnit.Id, @@ -399,7 +398,7 @@ public class MongoIdentityUserRepository : MongoDbRepository x.Roles.Select(r => r.RoleId)).ToList(); var allRoleIds = roleIds.Union(allOrganizationUnitRoleIds); - var roles = await (await GetMongoQueryableAsync(cancellationToken)).Where(r => allRoleIds.Contains(r.Id)).Select(r => new{ r.Id, r.Name }).ToListAsync(cancellationToken); + var roles = await (await GetQueryableAsync(cancellationToken)).Where(r => allRoleIds.Contains(r.Id)).Select(r => new{ r.Id, r.Name }).ToListAsync(cancellationToken); var userRoles = userAndRoleIds.ToDictionary(x => x.Key, x => roles.Where(r => x.Value.Contains(r.Id)).Select(r => r.Name).ToArray()); var result = userRoles.Select(x => new IdentityUserIdWithRoleNames { Id = x.Key, RoleNames = x.Value }).ToList(); @@ -422,7 +421,7 @@ public class MongoIdentityUserRepository : MongoDbRepository> GetFilteredQueryableAsync( + protected virtual async Task> GetFilteredQueryableAsync( string filter = null, Guid? roleId = null, Guid? organizationUnitId = null, @@ -442,11 +441,11 @@ public class MongoIdentityUserRepository : MongoDbRepository(cancellationToken)) + var organizationUnitIds = (await GetQueryableAsync(cancellationToken)) .Where(ou => ou.Roles.Any(r => r.RoleId == roleId.Value)) .Select(userOrganizationUnit => userOrganizationUnit.Id) .ToArray(); @@ -455,7 +454,7 @@ public class MongoIdentityUserRepository : MongoDbRepository>( + .WhereIf( !filter.IsNullOrWhiteSpace(), u => u.NormalizedUserName.Contains(upperFilter) || @@ -464,20 +463,20 @@ public class MongoIdentityUserRepository : MongoDbRepository>(organizationUnitId.HasValue, identityUser => identityUser.OrganizationUnits.Any(x => x.OrganizationUnitId == organizationUnitId.Value)) - .WhereIf>(!string.IsNullOrWhiteSpace(userName), x => x.UserName == userName) - .WhereIf>(!string.IsNullOrWhiteSpace(phoneNumber), x => x.PhoneNumber == phoneNumber) - .WhereIf>(!string.IsNullOrWhiteSpace(emailAddress), x => x.Email == emailAddress) - .WhereIf>(!string.IsNullOrWhiteSpace(name), x => x.Name == name) - .WhereIf>(!string.IsNullOrWhiteSpace(surname), x => x.Surname == surname) - .WhereIf>(isLockedOut.HasValue && isLockedOut.Value, x => x.LockoutEnabled && x.LockoutEnd != null && x.LockoutEnd > DateTimeOffset.UtcNow) - .WhereIf>(isLockedOut.HasValue && !isLockedOut.Value, x => !(x.LockoutEnabled && x.LockoutEnd != null && x.LockoutEnd > DateTimeOffset.UtcNow)) - .WhereIf>(notActive.HasValue, x => x.IsActive == !notActive.Value) - .WhereIf>(emailConfirmed.HasValue, x => x.EmailConfirmed == emailConfirmed.Value) - .WhereIf>(isExternal.HasValue, x => x.IsExternal == isExternal.Value) - .WhereIf>(maxCreationTime != null, p => p.CreationTime <= maxCreationTime) - .WhereIf>(minCreationTime != null, p => p.CreationTime >= minCreationTime) - .WhereIf>(maxModifitionTime != null, p => p.LastModificationTime <= maxModifitionTime) - .WhereIf>(minModifitionTime != null, p => p.LastModificationTime >= minModifitionTime); + .WhereIf(organizationUnitId.HasValue, identityUser => identityUser.OrganizationUnits.Any(x => x.OrganizationUnitId == organizationUnitId.Value)) + .WhereIf(!string.IsNullOrWhiteSpace(userName), x => x.UserName == userName) + .WhereIf(!string.IsNullOrWhiteSpace(phoneNumber), x => x.PhoneNumber == phoneNumber) + .WhereIf(!string.IsNullOrWhiteSpace(emailAddress), x => x.Email == emailAddress) + .WhereIf(!string.IsNullOrWhiteSpace(name), x => x.Name == name) + .WhereIf(!string.IsNullOrWhiteSpace(surname), x => x.Surname == surname) + .WhereIf(isLockedOut.HasValue && isLockedOut.Value, x => x.LockoutEnabled && x.LockoutEnd != null && x.LockoutEnd > DateTimeOffset.UtcNow) + .WhereIf(isLockedOut.HasValue && !isLockedOut.Value, x => !(x.LockoutEnabled && x.LockoutEnd != null && x.LockoutEnd > DateTimeOffset.UtcNow)) + .WhereIf(notActive.HasValue, x => x.IsActive == !notActive.Value) + .WhereIf(emailConfirmed.HasValue, x => x.EmailConfirmed == emailConfirmed.Value) + .WhereIf(isExternal.HasValue, x => x.IsExternal == isExternal.Value) + .WhereIf(maxCreationTime != null, p => p.CreationTime <= maxCreationTime) + .WhereIf(minCreationTime != null, p => p.CreationTime >= minCreationTime) + .WhereIf(maxModifitionTime != null, p => p.LastModificationTime <= maxModifitionTime) + .WhereIf(minModifitionTime != null, p => p.LastModificationTime >= minModifitionTime); } } diff --git a/modules/identity/src/Volo.Abp.Identity.MongoDB/Volo/Abp/Identity/MongoDB/MongoOrganizationUnitRepository.cs b/modules/identity/src/Volo.Abp.Identity.MongoDB/Volo/Abp/Identity/MongoDB/MongoOrganizationUnitRepository.cs index 78838c9c6c..14514e0ab4 100644 --- a/modules/identity/src/Volo.Abp.Identity.MongoDB/Volo/Abp/Identity/MongoDB/MongoOrganizationUnitRepository.cs +++ b/modules/identity/src/Volo.Abp.Identity.MongoDB/Volo/Abp/Identity/MongoDB/MongoOrganizationUnitRepository.cs @@ -27,7 +27,7 @@ public class MongoOrganizationUnitRepository bool includeDetails = false, CancellationToken cancellationToken = default) { - return await (await GetMongoQueryableAsync(cancellationToken)) + return await (await GetQueryableAsync(cancellationToken)) .Where(ou => ou.ParentId == parentId) .ToListAsync(GetCancellationToken(cancellationToken)); } @@ -38,7 +38,7 @@ public class MongoOrganizationUnitRepository bool includeDetails = false, CancellationToken cancellationToken = default) { - return await (await GetMongoQueryableAsync(cancellationToken)) + return await (await GetQueryableAsync(cancellationToken)) .Where(ou => ou.Code.StartsWith(code) && ou.Id != parentId) .ToListAsync(GetCancellationToken(cancellationToken)); } @@ -48,7 +48,7 @@ public class MongoOrganizationUnitRepository bool includeDetails = false, CancellationToken cancellationToken = default) { - return await (await GetMongoQueryableAsync(cancellationToken)) + return await (await GetQueryableAsync(cancellationToken)) .Where(t => ids.Contains(t.Id)) .ToListAsync(GetCancellationToken(cancellationToken)); } @@ -58,7 +58,7 @@ public class MongoOrganizationUnitRepository bool includeDetails = false, CancellationToken cancellationToken = default) { - return await (await GetMongoQueryableAsync(cancellationToken)) + return await (await GetQueryableAsync(cancellationToken)) .Where(x => x.Roles.Any(r => r.RoleId == roleId)) .ToListAsync(GetCancellationToken(cancellationToken)); } @@ -68,7 +68,7 @@ public class MongoOrganizationUnitRepository bool includeDetails = false, CancellationToken cancellationToken = default) { - return await (await GetMongoQueryableAsync(cancellationToken)) + return await (await GetQueryableAsync(cancellationToken)) .Where(x => displayNames.Contains(x.DisplayName)) .ToListAsync(GetCancellationToken(cancellationToken)); } @@ -80,10 +80,9 @@ public class MongoOrganizationUnitRepository bool includeDetails = false, CancellationToken cancellationToken = default) { - return await (await GetMongoQueryableAsync(cancellationToken)) + return await (await GetQueryableAsync(cancellationToken)) .OrderBy(sorting.IsNullOrEmpty() ? nameof(OrganizationUnit.CreationTime) + " desc" : sorting) - .As>() - .PageBy>(skipCount, maxResultCount) + .PageBy(skipCount, maxResultCount) .ToListAsync(GetCancellationToken(cancellationToken)); } @@ -92,7 +91,7 @@ public class MongoOrganizationUnitRepository bool includeDetails = true, CancellationToken cancellationToken = default) { - return await (await GetMongoQueryableAsync(cancellationToken)) + return await (await GetQueryableAsync(cancellationToken)) .OrderBy(x => x.Id) .FirstOrDefaultAsync( ou => ou.DisplayName == displayName, @@ -110,11 +109,10 @@ public class MongoOrganizationUnitRepository { var roleIds = organizationUnit.Roles.Select(r => r.RoleId).ToArray(); - return await (await GetMongoQueryableAsync(cancellationToken)) + return await (await GetQueryableAsync(cancellationToken)) .Where(r => roleIds.Contains(r.Id)) .OrderBy(sorting.IsNullOrEmpty() ? nameof(IdentityRole.Name) : sorting) - .As>() - .PageBy>(skipCount, maxResultCount) + .PageBy(skipCount, maxResultCount) .ToListAsync(GetCancellationToken(cancellationToken)); } @@ -126,17 +124,16 @@ public class MongoOrganizationUnitRepository bool includeDetails = false, CancellationToken cancellationToken = default) { - var organizationUnits = await (await GetMongoQueryableAsync(cancellationToken)) + var organizationUnits = await (await GetQueryableAsync(cancellationToken)) .Where(ou => organizationUnitIds.Contains(ou.Id)) .ToListAsync(GetCancellationToken(cancellationToken)); var roleIds = organizationUnits.SelectMany(ou => ou.Roles.Select(r => r.RoleId)).ToArray(); - return await (await GetMongoQueryableAsync(cancellationToken)) + return await (await GetQueryableAsync(cancellationToken)) .Where(r => roleIds.Contains(r.Id)) .OrderBy(sorting.IsNullOrEmpty() ? nameof(IdentityRole.Name) : sorting) - .As>() - .PageBy>(skipCount, maxResultCount) + .PageBy(skipCount, maxResultCount) .ToListAsync(GetCancellationToken(cancellationToken)); } @@ -146,7 +143,7 @@ public class MongoOrganizationUnitRepository { var roleIds = organizationUnit.Roles.Select(r => r.RoleId).ToArray(); - return await (await GetMongoQueryableAsync(cancellationToken)).Where(r => roleIds.Contains(r.Id)).CountAsync(GetCancellationToken(cancellationToken)); + return await (await GetQueryableAsync(cancellationToken)).Where(r => roleIds.Contains(r.Id)).CountAsync(GetCancellationToken(cancellationToken)); } public virtual async Task> GetUnaddedRolesAsync( @@ -160,12 +157,11 @@ public class MongoOrganizationUnitRepository { var roleIds = organizationUnit.Roles.Select(r => r.RoleId).ToArray(); - return await (await GetMongoQueryableAsync(cancellationToken)) + return await (await GetQueryableAsync(cancellationToken)) .Where(r => !roleIds.Contains(r.Id)) .WhereIf(!filter.IsNullOrWhiteSpace(), r => r.Name.Contains(filter)) .OrderBy(sorting.IsNullOrEmpty() ? nameof(IdentityRole.Name) : sorting) - .As>() - .PageBy>(skipCount, maxResultCount) + .PageBy(skipCount, maxResultCount) .ToListAsync(GetCancellationToken(cancellationToken)); } @@ -176,10 +172,9 @@ public class MongoOrganizationUnitRepository { var roleIds = organizationUnit.Roles.Select(r => r.RoleId).ToArray(); - return await (await GetMongoQueryableAsync(cancellationToken)) + return await (await GetQueryableAsync(cancellationToken)) .Where(r => !roleIds.Contains(r.Id)) .WhereIf(!filter.IsNullOrWhiteSpace(), r => r.Name.Contains(filter)) - .As>() .CountAsync(GetCancellationToken(cancellationToken)); } @@ -196,15 +191,14 @@ public class MongoOrganizationUnitRepository var query = await CreateGetMembersFilteredQueryAsync(organizationUnit, filter, cancellationToken); return await query .OrderBy(sorting.IsNullOrEmpty() ? nameof(IdentityUser.UserName) : sorting) - .As>() - .PageBy>(skipCount, maxResultCount) + .PageBy(skipCount, maxResultCount) .ToListAsync(cancellationToken); } public virtual async Task> GetMemberIdsAsync(Guid id, CancellationToken cancellationToken = default) { cancellationToken = GetCancellationToken(cancellationToken); - return await (await GetMongoQueryableAsync(cancellationToken)) + return await (await GetQueryableAsync(cancellationToken)) .Where(u => u.OrganizationUnits.Any(uou => uou.OrganizationUnitId == id)).Select(x => x.Id) .ToListAsync(cancellationToken); } @@ -229,9 +223,9 @@ public class MongoOrganizationUnitRepository CancellationToken cancellationToken = default) { return await - (await GetMongoQueryableAsync(cancellationToken)) + (await GetQueryableAsync(cancellationToken)) .Where(u => !u.OrganizationUnits.Any(uou => uou.OrganizationUnitId == organizationUnit.Id)) - .WhereIf>( + .WhereIf( !filter.IsNullOrWhiteSpace(), u => u.UserName.Contains(filter) || @@ -239,24 +233,22 @@ public class MongoOrganizationUnitRepository (u.PhoneNumber != null && u.PhoneNumber.Contains(filter)) ) .OrderBy(sorting.IsNullOrEmpty() ? nameof(IdentityUser.UserName) : sorting) - .As>() - .PageBy>(skipCount, maxResultCount) + .PageBy(skipCount, maxResultCount) .ToListAsync(GetCancellationToken(cancellationToken)); } public virtual async Task GetUnaddedUsersCountAsync(OrganizationUnit organizationUnit, string filter = null, CancellationToken cancellationToken = default) { - return await (await GetMongoQueryableAsync(cancellationToken)) + return await (await GetQueryableAsync(cancellationToken)) .Where(u => !u.OrganizationUnits.Any(uou => uou.OrganizationUnitId == organizationUnit.Id)) - .WhereIf>( + .WhereIf( !filter.IsNullOrWhiteSpace(), u => u.UserName.Contains(filter) || u.Email.Contains(filter) || (u.PhoneNumber != null && u.PhoneNumber.Contains(filter)) ) - .As>() .CountAsync(GetCancellationToken(cancellationToken)); } @@ -269,11 +261,10 @@ public class MongoOrganizationUnitRepository public virtual async Task RemoveAllMembersAsync(OrganizationUnit organizationUnit, CancellationToken cancellationToken = default) { cancellationToken = GetCancellationToken(cancellationToken); - var userQueryable = await GetMongoQueryableAsync(cancellationToken); + var userQueryable = await GetQueryableAsync(cancellationToken); var dbContext = await GetDbContextAsync(cancellationToken); var users = await userQueryable .Where(u => u.OrganizationUnits.Any(uou => uou.OrganizationUnitId == organizationUnit.Id)) - .As>() .ToListAsync(cancellationToken); foreach (var user in users) @@ -283,14 +274,14 @@ public class MongoOrganizationUnitRepository } } - protected virtual async Task> CreateGetMembersFilteredQueryAsync( + protected virtual async Task> CreateGetMembersFilteredQueryAsync( OrganizationUnit organizationUnit, string filter = null, CancellationToken cancellationToken = default) { - return (await GetMongoQueryableAsync(cancellationToken)) + return (await GetQueryableAsync(cancellationToken)) .Where(u => u.OrganizationUnits.Any(uou => uou.OrganizationUnitId == organizationUnit.Id)) - .WhereIf>( + .WhereIf( !filter.IsNullOrWhiteSpace(), u => u.UserName.Contains(filter) || diff --git a/modules/identity/test/Volo.Abp.Identity.MongoDB.Tests/Volo.Abp.Identity.MongoDB.Tests.csproj b/modules/identity/test/Volo.Abp.Identity.MongoDB.Tests/Volo.Abp.Identity.MongoDB.Tests.csproj index cc463e1cc8..311ee9fa69 100644 --- a/modules/identity/test/Volo.Abp.Identity.MongoDB.Tests/Volo.Abp.Identity.MongoDB.Tests.csproj +++ b/modules/identity/test/Volo.Abp.Identity.MongoDB.Tests/Volo.Abp.Identity.MongoDB.Tests.csproj @@ -20,10 +20,10 @@ - - - - + + + + diff --git a/modules/identity/test/Volo.Abp.Identity.MongoDB.Tests/Volo/Abp/Identity/MongoDB/MongoDbFixture.cs b/modules/identity/test/Volo.Abp.Identity.MongoDB.Tests/Volo/Abp/Identity/MongoDB/MongoDbFixture.cs index 732500214c..90b0f60b14 100644 --- a/modules/identity/test/Volo.Abp.Identity.MongoDB.Tests/Volo/Abp/Identity/MongoDB/MongoDbFixture.cs +++ b/modules/identity/test/Volo.Abp.Identity.MongoDB.Tests/Volo/Abp/Identity/MongoDB/MongoDbFixture.cs @@ -1,5 +1,5 @@ using System; -using EphemeralMongo; +using MongoSandbox; namespace Volo.Abp.Identity.MongoDB; diff --git a/modules/identityserver/src/Volo.Abp.IdentityServer.MongoDB/Volo/Abp/IdentityServer/MongoDB/MongoApiResourceRepository.cs b/modules/identityserver/src/Volo.Abp.IdentityServer.MongoDB/Volo/Abp/IdentityServer/MongoDB/MongoApiResourceRepository.cs index 24dc519a40..42379b44f9 100644 --- a/modules/identityserver/src/Volo.Abp.IdentityServer.MongoDB/Volo/Abp/IdentityServer/MongoDB/MongoApiResourceRepository.cs +++ b/modules/identityserver/src/Volo.Abp.IdentityServer.MongoDB/Volo/Abp/IdentityServer/MongoDB/MongoApiResourceRepository.cs @@ -20,7 +20,7 @@ public class MongoApiResourceRepository : MongoDbRepository FindByNameAsync(string apiResourceName, bool includeDetails = true, CancellationToken cancellationToken = default) { - return await (await GetMongoQueryableAsync(cancellationToken)) + return await (await GetQueryableAsync(cancellationToken)) .OrderBy(ar => ar.Id) .FirstOrDefaultAsync(ar => ar.Name == apiResourceName, GetCancellationToken(cancellationToken)); } @@ -28,7 +28,7 @@ public class MongoApiResourceRepository : MongoDbRepository> FindByNameAsync(string[] apiResourceNames, bool includeDetails = true, CancellationToken cancellationToken = default) { - return await (await GetMongoQueryableAsync(cancellationToken)) + return await (await GetQueryableAsync(cancellationToken)) .Where(ar => apiResourceNames.Contains(ar.Name)) .ToListAsync(GetCancellationToken(cancellationToken)); } @@ -36,7 +36,7 @@ public class MongoApiResourceRepository : MongoDbRepository> GetListByScopesAsync(string[] scopeNames, bool includeDetails = false, CancellationToken cancellationToken = default) { - return await (await GetMongoQueryableAsync(cancellationToken)) + return await (await GetQueryableAsync(cancellationToken)) .Where(ar => ar.Scopes.Any(x => scopeNames.Contains(x.Scope))) .ToListAsync(GetCancellationToken(cancellationToken)); } @@ -44,21 +44,20 @@ public class MongoApiResourceRepository : MongoDbRepository> GetListAsync(string sorting, int skipCount, int maxResultCount, string filter, bool includeDetails = false, CancellationToken cancellationToken = default) { - return await (await GetMongoQueryableAsync(cancellationToken)) + return await (await GetQueryableAsync(cancellationToken)) .WhereIf(!filter.IsNullOrWhiteSpace(), x => x.Name.Contains(filter) || x.Description.Contains(filter) || x.DisplayName.Contains(filter)) .OrderBy(sorting.IsNullOrWhiteSpace() ? nameof(ApiResource.Name) : sorting) - .As>() - .PageBy>(skipCount, maxResultCount) + .PageBy(skipCount, maxResultCount) .ToListAsync(GetCancellationToken(cancellationToken)); } public virtual async Task GetCountAsync(string filter = null, CancellationToken cancellationToken = default) { - return await (await GetMongoQueryableAsync(cancellationToken)) - .WhereIf>(!filter.IsNullOrWhiteSpace(), + return await (await GetQueryableAsync(cancellationToken)) + .WhereIf(!filter.IsNullOrWhiteSpace(), x => x.Name.Contains(filter) || x.Description.Contains(filter) || x.DisplayName.Contains(filter)) @@ -67,7 +66,7 @@ public class MongoApiResourceRepository : MongoDbRepository CheckNameExistAsync(string name, Guid? expectedId = null, CancellationToken cancellationToken = default) { - return await (await GetMongoQueryableAsync(cancellationToken)) + return await (await GetQueryableAsync(cancellationToken)) .AnyAsync(ar => ar.Id != expectedId && ar.Name == name, GetCancellationToken(cancellationToken)); } } diff --git a/modules/identityserver/src/Volo.Abp.IdentityServer.MongoDB/Volo/Abp/IdentityServer/MongoDB/MongoApiScopeRepository.cs b/modules/identityserver/src/Volo.Abp.IdentityServer.MongoDB/Volo/Abp/IdentityServer/MongoDB/MongoApiScopeRepository.cs index 01c1ecad07..760bd0522c 100644 --- a/modules/identityserver/src/Volo.Abp.IdentityServer.MongoDB/Volo/Abp/IdentityServer/MongoDB/MongoApiScopeRepository.cs +++ b/modules/identityserver/src/Volo.Abp.IdentityServer.MongoDB/Volo/Abp/IdentityServer/MongoDB/MongoApiScopeRepository.cs @@ -22,7 +22,7 @@ public class MongoApiScopeRepository : MongoDbRepository FindByNameAsync(string scopeName, bool includeDetails = true, CancellationToken cancellationToken = default) { - return await (await GetMongoQueryableAsync(cancellationToken)) + return await (await GetQueryableAsync(cancellationToken)) .OrderBy(x => x.Id) .FirstOrDefaultAsync(x => x.Name == scopeName, GetCancellationToken(cancellationToken)); } @@ -30,7 +30,7 @@ public class MongoApiScopeRepository : MongoDbRepository> GetListByNameAsync(string[] scopeNames, bool includeDetails = false, CancellationToken cancellationToken = default) { - return await (await GetMongoQueryableAsync(cancellationToken)) + return await (await GetQueryableAsync(cancellationToken)) .Where(scope => scopeNames.Contains(scope.Name)) .OrderBy(scope => scope.Id) .ToListAsync(GetCancellationToken(cancellationToken)); @@ -39,21 +39,20 @@ public class MongoApiScopeRepository : MongoDbRepository> GetListAsync(string sorting, int skipCount, int maxResultCount, string filter = null, bool includeDetails = false, CancellationToken cancellationToken = default) { - return await (await GetMongoQueryableAsync(cancellationToken)) + return await (await GetQueryableAsync(cancellationToken)) .WhereIf(!filter.IsNullOrWhiteSpace(), x => x.Name.Contains(filter) || x.Description.Contains(filter) || x.DisplayName.Contains(filter)) .OrderBy(sorting.IsNullOrWhiteSpace() ? nameof(ApiScope.Name) : sorting) - .As>() - .PageBy>(skipCount, maxResultCount) + .PageBy(skipCount, maxResultCount) .ToListAsync(GetCancellationToken(cancellationToken)); } public virtual async Task GetCountAsync(string filter = null, CancellationToken cancellationToken = default) { - return await (await GetMongoQueryableAsync(cancellationToken)) - .WhereIf>(!filter.IsNullOrWhiteSpace(), + return await (await GetQueryableAsync(cancellationToken)) + .WhereIf(!filter.IsNullOrWhiteSpace(), x => x.Name.Contains(filter) || x.Description.Contains(filter) || x.DisplayName.Contains(filter)) @@ -62,7 +61,7 @@ public class MongoApiScopeRepository : MongoDbRepository CheckNameExistAsync(string name, Guid? expectedId = null, CancellationToken cancellationToken = default) { - return await (await GetMongoQueryableAsync(cancellationToken)) + return await (await GetQueryableAsync(cancellationToken)) .AnyAsync(x => x.Id != expectedId && x.Name == name, GetCancellationToken(cancellationToken)); } } diff --git a/modules/identityserver/src/Volo.Abp.IdentityServer.MongoDB/Volo/Abp/IdentityServer/MongoDB/MongoClientRepository.cs b/modules/identityserver/src/Volo.Abp.IdentityServer.MongoDB/Volo/Abp/IdentityServer/MongoDB/MongoClientRepository.cs index c7f81f51e2..d266ac7c52 100644 --- a/modules/identityserver/src/Volo.Abp.IdentityServer.MongoDB/Volo/Abp/IdentityServer/MongoDB/MongoClientRepository.cs +++ b/modules/identityserver/src/Volo.Abp.IdentityServer.MongoDB/Volo/Abp/IdentityServer/MongoDB/MongoClientRepository.cs @@ -26,7 +26,7 @@ public class MongoClientRepository : MongoDbRepository x.Id) .FirstOrDefaultAsync(x => x.ClientId == clientId, GetCancellationToken(cancellationToken)); } @@ -39,18 +39,17 @@ public class MongoClientRepository : MongoDbRepository x.ClientId.Contains(filter)) .OrderBy(sorting.IsNullOrWhiteSpace() ? nameof(Client.ClientName) : sorting) - .As>() - .PageBy>(skipCount, maxResultCount) + .PageBy(skipCount, maxResultCount) .ToListAsync(GetCancellationToken(cancellationToken)); } public virtual async Task GetCountAsync(string filter = null, CancellationToken cancellationToken = default) { - return await (await GetMongoQueryableAsync(cancellationToken)) - .WhereIf>(!filter.IsNullOrWhiteSpace(), + return await (await GetQueryableAsync(cancellationToken)) + .WhereIf(!filter.IsNullOrWhiteSpace(), x => x.ClientId.Contains(filter)) .LongCountAsync(GetCancellationToken(cancellationToken)); } @@ -58,7 +57,7 @@ public class MongoClientRepository : MongoDbRepository> GetAllDistinctAllowedCorsOriginsAsync( CancellationToken cancellationToken = default) { - return await (await GetMongoQueryableAsync(cancellationToken)) + return await (await GetQueryableAsync(cancellationToken)) .SelectMany(x => x.AllowedCorsOrigins) .Select(y => y.Origin) .Distinct() @@ -67,7 +66,7 @@ public class MongoClientRepository : MongoDbRepository CheckClientIdExistAsync(string clientId, Guid? expectedId = null, CancellationToken cancellationToken = default) { - return await (await GetMongoQueryableAsync(cancellationToken)) + return await (await GetQueryableAsync(cancellationToken)) .AnyAsync(c => c.Id != expectedId && c.ClientId == clientId, GetCancellationToken(cancellationToken)); } } diff --git a/modules/identityserver/src/Volo.Abp.IdentityServer.MongoDB/Volo/Abp/IdentityServer/MongoDB/MongoDeviceFlowCodesRepository.cs b/modules/identityserver/src/Volo.Abp.IdentityServer.MongoDB/Volo/Abp/IdentityServer/MongoDB/MongoDeviceFlowCodesRepository.cs index 921225a5ae..65d74b975a 100644 --- a/modules/identityserver/src/Volo.Abp.IdentityServer.MongoDB/Volo/Abp/IdentityServer/MongoDB/MongoDeviceFlowCodesRepository.cs +++ b/modules/identityserver/src/Volo.Abp.IdentityServer.MongoDB/Volo/Abp/IdentityServer/MongoDB/MongoDeviceFlowCodesRepository.cs @@ -2,6 +2,7 @@ using System.Collections.Generic; using System.Threading; using System.Threading.Tasks; +using System.Linq; using MongoDB.Driver; using MongoDB.Driver.Linq; using Volo.Abp.Domain.Repositories.MongoDB; @@ -23,7 +24,7 @@ public class MongoDeviceFlowCodesRepository : string userCode, CancellationToken cancellationToken = default) { - return await (await GetMongoQueryableAsync(cancellationToken)) + return await (await GetQueryableAsync(cancellationToken)) .Where(d => d.UserCode == userCode) .OrderBy(x => x.Id) .FirstOrDefaultAsync(GetCancellationToken(cancellationToken)); @@ -31,7 +32,7 @@ public class MongoDeviceFlowCodesRepository : public virtual async Task FindByDeviceCodeAsync(string deviceCode, CancellationToken cancellationToken = default) { - return await (await GetMongoQueryableAsync(cancellationToken)) + return await (await GetQueryableAsync(cancellationToken)) .Where(d => d.DeviceCode == deviceCode) .OrderBy(x => x.Id) .FirstOrDefaultAsync(GetCancellationToken(cancellationToken)); @@ -42,7 +43,7 @@ public class MongoDeviceFlowCodesRepository : int maxResultCount, CancellationToken cancellationToken = default) { - return await (await GetMongoQueryableAsync(cancellationToken)) + return await (await GetQueryableAsync(cancellationToken)) .Where(x => x.Expiration != null && x.Expiration < maxExpirationDate) .OrderBy(x => x.ClientId) .Take(maxResultCount) diff --git a/modules/identityserver/src/Volo.Abp.IdentityServer.MongoDB/Volo/Abp/IdentityServer/MongoDB/MongoIdentityResourceRepository.cs b/modules/identityserver/src/Volo.Abp.IdentityServer.MongoDB/Volo/Abp/IdentityServer/MongoDB/MongoIdentityResourceRepository.cs index faf3d66d96..9a3ee0f815 100644 --- a/modules/identityserver/src/Volo.Abp.IdentityServer.MongoDB/Volo/Abp/IdentityServer/MongoDB/MongoIdentityResourceRepository.cs +++ b/modules/identityserver/src/Volo.Abp.IdentityServer.MongoDB/Volo/Abp/IdentityServer/MongoDB/MongoIdentityResourceRepository.cs @@ -20,20 +20,19 @@ public class MongoIdentityResourceRepository : MongoDbRepository> GetListAsync(string sorting, int skipCount, int maxResultCount, string filter, bool includeDetails = false, CancellationToken cancellationToken = default) { - return await (await GetMongoQueryableAsync(cancellationToken)) + return await (await GetQueryableAsync(cancellationToken)) .WhereIf(!filter.IsNullOrWhiteSpace(), x => x.Name.Contains(filter) || x.Description.Contains(filter) || x.DisplayName.Contains(filter)) .OrderBy(sorting.IsNullOrWhiteSpace() ? nameof(IdentityResource.Name) : sorting) - .As>() - .PageBy>(skipCount, maxResultCount) + .PageBy(skipCount, maxResultCount) .ToListAsync(GetCancellationToken(cancellationToken)); } public virtual async Task GetCountAsync(string filter = null, CancellationToken cancellationToken = default) { - return await (await GetMongoQueryableAsync(cancellationToken)) - .WhereIf>(!filter.IsNullOrWhiteSpace(), + return await (await GetQueryableAsync(cancellationToken)) + .WhereIf(!filter.IsNullOrWhiteSpace(), x => x.Name.Contains(filter) || x.Description.Contains(filter) || x.DisplayName.Contains(filter)) @@ -45,7 +44,7 @@ public class MongoIdentityResourceRepository : MongoDbRepository x.Name == name) .OrderBy(x => x.Id) .FirstOrDefaultAsync(GetCancellationToken(cancellationToken)); @@ -54,14 +53,14 @@ public class MongoIdentityResourceRepository : MongoDbRepository> GetListByScopeNameAsync(string[] scopeNames, bool includeDetails = false, CancellationToken cancellationToken = default) { - return await (await GetMongoQueryableAsync(cancellationToken)) + return await (await GetQueryableAsync(cancellationToken)) .Where(ar => scopeNames.Contains(ar.Name)) .ToListAsync(GetCancellationToken(cancellationToken)); } public virtual async Task CheckNameExistAsync(string name, Guid? expectedId = null, CancellationToken cancellationToken = default) { - return await (await GetMongoQueryableAsync(cancellationToken)) + return await (await GetQueryableAsync(cancellationToken)) .AnyAsync(ir => ir.Id != expectedId && ir.Name == name, GetCancellationToken(cancellationToken)); } } diff --git a/modules/identityserver/src/Volo.Abp.IdentityServer.MongoDB/Volo/Abp/IdentityServer/MongoDB/MongoPersistentGrantRepository.cs b/modules/identityserver/src/Volo.Abp.IdentityServer.MongoDB/Volo/Abp/IdentityServer/MongoDB/MongoPersistentGrantRepository.cs index e3f3cc8368..4ac0844bbe 100644 --- a/modules/identityserver/src/Volo.Abp.IdentityServer.MongoDB/Volo/Abp/IdentityServer/MongoDB/MongoPersistentGrantRepository.cs +++ b/modules/identityserver/src/Volo.Abp.IdentityServer.MongoDB/Volo/Abp/IdentityServer/MongoDB/MongoPersistentGrantRepository.cs @@ -27,7 +27,7 @@ public class MongoPersistentGrantRepository : MongoDbRepository FindByKeyAsync(string key, CancellationToken cancellationToken = default) { - return await (await GetMongoQueryableAsync(cancellationToken)) + return await (await GetQueryableAsync(cancellationToken)) .Where(x => x.Key == key) .OrderBy(x => x.Id) .FirstOrDefaultAsync(GetCancellationToken(cancellationToken)); @@ -35,7 +35,7 @@ public class MongoPersistentGrantRepository : MongoDbRepository> GetListBySubjectIdAsync(string subjectId, CancellationToken cancellationToken = default) { - return await (await GetMongoQueryableAsync(cancellationToken)) + return await (await GetQueryableAsync(cancellationToken)) .Where(x => x.SubjectId == subjectId) .ToListAsync(GetCancellationToken(cancellationToken)); } @@ -43,7 +43,7 @@ public class MongoPersistentGrantRepository : MongoDbRepository> GetListByExpirationAsync(DateTime maxExpirationDate, int maxResultCount, CancellationToken cancellationToken = default) { - return await (await GetMongoQueryableAsync(cancellationToken)) + return await (await GetQueryableAsync(cancellationToken)) .Where(x => x.Expiration != null && x.Expiration < maxExpirationDate) .OrderBy(x => x.ClientId) .Take(maxResultCount) @@ -87,18 +87,17 @@ public class MongoPersistentGrantRepository : MongoDbRepository> FilterAsync( + private async Task> FilterAsync( string subjectId, string sessionId, string clientId, string type, CancellationToken cancellationToken = default) { - return (await GetMongoQueryableAsync(cancellationToken)) - .WhereIf>(!subjectId.IsNullOrWhiteSpace(), x => x.SubjectId == subjectId) - .WhereIf>(!sessionId.IsNullOrWhiteSpace(), x => x.SessionId == sessionId) - .WhereIf>(!clientId.IsNullOrWhiteSpace(), x => x.ClientId == clientId) - .WhereIf>(!type.IsNullOrWhiteSpace(), x => x.Type == type) - .As>(); + return (await GetQueryableAsync(cancellationToken)) + .WhereIf(!subjectId.IsNullOrWhiteSpace(), x => x.SubjectId == subjectId) + .WhereIf(!sessionId.IsNullOrWhiteSpace(), x => x.SessionId == sessionId) + .WhereIf(!clientId.IsNullOrWhiteSpace(), x => x.ClientId == clientId) + .WhereIf(!type.IsNullOrWhiteSpace(), x => x.Type == type); } } diff --git a/modules/identityserver/test/Volo.Abp.IdentityServer.MongoDB.Tests/Volo.Abp.IdentityServer.MongoDB.Tests.csproj b/modules/identityserver/test/Volo.Abp.IdentityServer.MongoDB.Tests/Volo.Abp.IdentityServer.MongoDB.Tests.csproj index d2d7bf8a0e..07377805af 100644 --- a/modules/identityserver/test/Volo.Abp.IdentityServer.MongoDB.Tests/Volo.Abp.IdentityServer.MongoDB.Tests.csproj +++ b/modules/identityserver/test/Volo.Abp.IdentityServer.MongoDB.Tests/Volo.Abp.IdentityServer.MongoDB.Tests.csproj @@ -20,10 +20,10 @@ - - - - + + + + diff --git a/modules/identityserver/test/Volo.Abp.IdentityServer.MongoDB.Tests/Volo/Abp/IdentityServer/MongoDbFixture.cs b/modules/identityserver/test/Volo.Abp.IdentityServer.MongoDB.Tests/Volo/Abp/IdentityServer/MongoDbFixture.cs index 2f6d52d255..6611beb635 100644 --- a/modules/identityserver/test/Volo.Abp.IdentityServer.MongoDB.Tests/Volo/Abp/IdentityServer/MongoDbFixture.cs +++ b/modules/identityserver/test/Volo.Abp.IdentityServer.MongoDB.Tests/Volo/Abp/IdentityServer/MongoDbFixture.cs @@ -1,5 +1,5 @@ using System; -using EphemeralMongo; +using MongoSandbox; namespace Volo.Abp.IdentityServer; diff --git a/modules/openiddict/src/Volo.Abp.OpenIddict.MongoDB/Volo/Abp/OpenIddict/Applications/MongoOpenIddictApplicationRepository.cs b/modules/openiddict/src/Volo.Abp.OpenIddict.MongoDB/Volo/Abp/OpenIddict/Applications/MongoOpenIddictApplicationRepository.cs index ad9064e8cf..867bbe71c5 100644 --- a/modules/openiddict/src/Volo.Abp.OpenIddict.MongoDB/Volo/Abp/OpenIddict/Applications/MongoOpenIddictApplicationRepository.cs +++ b/modules/openiddict/src/Volo.Abp.OpenIddict.MongoDB/Volo/Abp/OpenIddict/Applications/MongoOpenIddictApplicationRepository.cs @@ -21,50 +21,47 @@ public class MongoOpenIddictApplicationRepository : MongoDbRepository> GetListAsync(string sorting, int skipCount, int maxResultCount, string filter = null, CancellationToken cancellationToken = default) { - return await ((await GetMongoQueryableAsync(cancellationToken))) + return await ((await GetQueryableAsync(cancellationToken))) .WhereIf(!filter.IsNullOrWhiteSpace(), x => x.ClientId.Contains(filter)) .OrderBy(sorting.IsNullOrWhiteSpace() ? nameof(OpenIddictApplication.CreationTime) + " desc" : sorting) .PageBy(skipCount, maxResultCount) - .As>() .ToListAsync(GetCancellationToken(cancellationToken)); } public virtual async Task GetCountAsync(string filter = null, CancellationToken cancellationToken = default) { - return await ((await GetMongoQueryableAsync(cancellationToken))) + return await ((await GetQueryableAsync(cancellationToken))) .WhereIf(!filter.IsNullOrWhiteSpace(), x => x.ClientId.Contains(filter)) - .As>() .LongCountAsync(GetCancellationToken(cancellationToken)); } public virtual async Task FindByClientIdAsync(string clientId, CancellationToken cancellationToken = default) { - return await (await GetMongoQueryableAsync(cancellationToken)) + return await (await GetQueryableAsync(cancellationToken)) .FirstOrDefaultAsync(x => x.ClientId == clientId, cancellationToken); } public virtual async Task> FindByPostLogoutRedirectUriAsync(string address, CancellationToken cancellationToken = default) { - return await (await GetMongoQueryableAsync(cancellationToken)).Where(x => x.PostLogoutRedirectUris.Contains(address)).ToListAsync(GetCancellationToken(cancellationToken)); + return await (await GetQueryableAsync(cancellationToken)).Where(x => x.PostLogoutRedirectUris.Contains(address)).ToListAsync(GetCancellationToken(cancellationToken)); } public virtual async Task> FindByRedirectUriAsync(string address, CancellationToken cancellationToken = default) { - return await (await GetMongoQueryableAsync(cancellationToken)).Where(x => x.RedirectUris.Contains(address)).ToListAsync(GetCancellationToken(cancellationToken)); + return await (await GetQueryableAsync(cancellationToken)).Where(x => x.RedirectUris.Contains(address)).ToListAsync(GetCancellationToken(cancellationToken)); } public virtual async Task GetAsync(Func, TState, IQueryable> query, TState state, CancellationToken cancellationToken = default) { - return await query(await GetMongoQueryableAsync(cancellationToken), state).As>().FirstOrDefaultAsync(GetCancellationToken(cancellationToken)); + return await query(await GetQueryableAsync(cancellationToken), state).FirstOrDefaultAsync(GetCancellationToken(cancellationToken)); } public virtual async Task> ListAsync(int? count, int? offset, CancellationToken cancellationToken = default) { - return await (await GetMongoQueryableAsync(cancellationToken)) + return await (await GetQueryableAsync(cancellationToken)) .OrderBy(x => x.Id) .SkipIf>(offset.HasValue, offset) .TakeIf>(count.HasValue, count) - .As>() .ToListAsync(GetCancellationToken(cancellationToken)); } } diff --git a/modules/openiddict/src/Volo.Abp.OpenIddict.MongoDB/Volo/Abp/OpenIddict/Authorizations/MongoOpenIddictAuthorizationRepository.cs b/modules/openiddict/src/Volo.Abp.OpenIddict.MongoDB/Volo/Abp/OpenIddict/Authorizations/MongoOpenIddictAuthorizationRepository.cs index f4bd5f4817..87ed933f00 100644 --- a/modules/openiddict/src/Volo.Abp.OpenIddict.MongoDB/Volo/Abp/OpenIddict/Authorizations/MongoOpenIddictAuthorizationRepository.cs +++ b/modules/openiddict/src/Volo.Abp.OpenIddict.MongoDB/Volo/Abp/OpenIddict/Authorizations/MongoOpenIddictAuthorizationRepository.cs @@ -29,53 +29,52 @@ public class MongoOpenIddictAuthorizationRepository : MongoDbRepository> FindAsync(string subject, Guid? client, string status, string type, CancellationToken cancellationToken = default) { - return await (await GetMongoQueryableAsync(cancellationToken)) + return await (await GetQueryableAsync(cancellationToken)) .WhereIf(!subject.IsNullOrWhiteSpace(), x => x.Subject == subject) .WhereIf(client.HasValue, x => x.ApplicationId == client) .WhereIf(!status.IsNullOrWhiteSpace(), x => x.Status == status) .WhereIf(!type.IsNullOrWhiteSpace(), x => x.Type == type) - .As>() .ToListAsync(GetCancellationToken(cancellationToken)); } public virtual async Task> FindByApplicationIdAsync(Guid applicationId, CancellationToken cancellationToken = default) { - return await (await GetMongoQueryableAsync(GetCancellationToken(cancellationToken))).Where(x => x.ApplicationId == applicationId).ToListAsync(GetCancellationToken(cancellationToken)); + return await (await GetQueryableAsync(GetCancellationToken(cancellationToken))).Where(x => x.ApplicationId == applicationId).ToListAsync(GetCancellationToken(cancellationToken)); } public virtual async Task FindByIdAsync(Guid id, CancellationToken cancellationToken = default) { - return await (await GetMongoQueryableAsync(GetCancellationToken(cancellationToken))).FirstOrDefaultAsync(x => x.Id == id, GetCancellationToken(cancellationToken)); + return await (await GetQueryableAsync(GetCancellationToken(cancellationToken))).FirstOrDefaultAsync(x => x.Id == id, GetCancellationToken(cancellationToken)); } public virtual async Task> FindBySubjectAsync(string subject, CancellationToken cancellationToken = default) { - return await (await GetMongoQueryableAsync(GetCancellationToken(cancellationToken))).Where(x => x.Subject == subject).ToListAsync(GetCancellationToken(cancellationToken)); + return await (await GetQueryableAsync(GetCancellationToken(cancellationToken))).Where(x => x.Subject == subject).ToListAsync(GetCancellationToken(cancellationToken)); } public virtual async Task> ListAsync(int? count, int? offset, CancellationToken cancellationToken = default) { - return await (await GetMongoQueryableAsync(GetCancellationToken(cancellationToken))) + return await (await GetQueryableAsync(GetCancellationToken(cancellationToken))) .OrderBy(authorization => authorization.Id!) .SkipIf>(offset.HasValue, offset) .TakeIf>(count.HasValue, count) - .As>().ToListAsync(GetCancellationToken(cancellationToken)); + .ToListAsync(GetCancellationToken(cancellationToken)); } public virtual async Task PruneAsync(DateTime date, CancellationToken cancellationToken = default) { - var tokenIds = await (await GetMongoQueryableAsync(cancellationToken)) + var tokenIds = await (await GetQueryableAsync(cancellationToken)) .Where(x => x.AuthorizationId != null) .Select(x => x.AuthorizationId.Value) .ToListAsync(GetCancellationToken(cancellationToken)); - var authorizations = await (await GetMongoQueryableAsync(cancellationToken)) + var authorizations = await (await GetQueryableAsync(cancellationToken)) .Where(x => x.CreationDate < date) .Where(x => x.Status != OpenIddictConstants.Statuses.Valid || (x.Type == OpenIddictConstants.AuthorizationTypes.AdHoc && !tokenIds.Contains(x.Id))) .Select(x => x.Id) .ToListAsync(cancellationToken: cancellationToken); - var tokens = await (await GetMongoQueryableAsync(cancellationToken)) + var tokens = await (await GetQueryableAsync(cancellationToken)) .Where(x => x.AuthorizationId != null && authorizations.Contains(x.AuthorizationId.Value)) .ToListAsync(cancellationToken: cancellationToken); diff --git a/modules/openiddict/src/Volo.Abp.OpenIddict.MongoDB/Volo/Abp/OpenIddict/Scopes/MongoOpenIddictScopeRepository.cs b/modules/openiddict/src/Volo.Abp.OpenIddict.MongoDB/Volo/Abp/OpenIddict/Scopes/MongoOpenIddictScopeRepository.cs index 3e16df4e9b..7323b3f272 100644 --- a/modules/openiddict/src/Volo.Abp.OpenIddict.MongoDB/Volo/Abp/OpenIddict/Scopes/MongoOpenIddictScopeRepository.cs +++ b/modules/openiddict/src/Volo.Abp.OpenIddict.MongoDB/Volo/Abp/OpenIddict/Scopes/MongoOpenIddictScopeRepository.cs @@ -21,61 +21,56 @@ public class MongoOpenIddictScopeRepository : MongoDbRepository> GetListAsync(string sorting, int skipCount, int maxResultCount, string filter = null, CancellationToken cancellationToken = default) { - return await (await GetMongoQueryableAsync(cancellationToken)) + return await (await GetQueryableAsync(cancellationToken)) .WhereIf(!filter.IsNullOrWhiteSpace(), x => x.Name.Contains(filter) || x.DisplayName.Contains(filter) || x.Description.Contains(filter)) .OrderBy(sorting.IsNullOrWhiteSpace() ? nameof(OpenIddictScope.CreationTime) + " desc" : sorting) .PageBy(skipCount, maxResultCount) - .As>() .ToListAsync(GetCancellationToken(cancellationToken)); } public virtual async Task GetCountAsync(string filter = null, CancellationToken cancellationToken = default) { - return await (await GetMongoQueryableAsync(cancellationToken)) + return await (await GetQueryableAsync(cancellationToken)) .WhereIf(!filter.IsNullOrWhiteSpace(), x => x.Name.Contains(filter) || x.DisplayName.Contains(filter) || x.Description.Contains(filter)) - .As>() .LongCountAsync(GetCancellationToken(cancellationToken)); } public virtual async Task FindByIdAsync(Guid id, CancellationToken cancellationToken = default) { - return await (await GetMongoQueryableAsync(cancellationToken)).FirstOrDefaultAsync(x => x.Id == id, GetCancellationToken(cancellationToken)); + return await (await GetQueryableAsync(cancellationToken)).FirstOrDefaultAsync(x => x.Id == id, GetCancellationToken(cancellationToken)); } public virtual async Task FindByNameAsync(string name, CancellationToken cancellationToken = default) { - return await (await GetMongoQueryableAsync(cancellationToken)).FirstOrDefaultAsync(x => x.Name == name, GetCancellationToken(cancellationToken)); + return await (await GetQueryableAsync(cancellationToken)).FirstOrDefaultAsync(x => x.Name == name, GetCancellationToken(cancellationToken)); } public virtual async Task> FindByNamesAsync(string[] names, CancellationToken cancellationToken = default) { - return await (await GetMongoQueryableAsync(GetCancellationToken(cancellationToken))) + return await (await GetQueryableAsync(GetCancellationToken(cancellationToken))) .Where(x => names.Contains(x.Name)) - .As>() .ToListAsync(GetCancellationToken(cancellationToken)); } public virtual async Task> FindByResourceAsync(string resource, CancellationToken cancellationToken = default) { - return await (await GetMongoQueryableAsync(GetCancellationToken(cancellationToken))) + return await (await GetQueryableAsync(GetCancellationToken(cancellationToken))) .Where(x => x.Resources.Contains(resource)) - .As>() .ToListAsync(GetCancellationToken(cancellationToken)); } public virtual async Task> ListAsync(int? count, int? offset, CancellationToken cancellationToken = default) { - return await (await GetMongoQueryableAsync(GetCancellationToken(cancellationToken))) + return await (await GetQueryableAsync(GetCancellationToken(cancellationToken))) .OrderBy(x => x.Id) .SkipIf>(offset.HasValue, offset) .TakeIf>(count.HasValue, count) - .As>() .ToListAsync(GetCancellationToken(cancellationToken)); } } diff --git a/modules/openiddict/src/Volo.Abp.OpenIddict.MongoDB/Volo/Abp/OpenIddict/Tokens/MongoOpenIddictTokenRepository.cs b/modules/openiddict/src/Volo.Abp.OpenIddict.MongoDB/Volo/Abp/OpenIddict/Tokens/MongoOpenIddictTokenRepository.cs index 175b137515..2b2a9bec12 100644 --- a/modules/openiddict/src/Volo.Abp.OpenIddict.MongoDB/Volo/Abp/OpenIddict/Tokens/MongoOpenIddictTokenRepository.cs +++ b/modules/openiddict/src/Volo.Abp.OpenIddict.MongoDB/Volo/Abp/OpenIddict/Tokens/MongoOpenIddictTokenRepository.cs @@ -21,7 +21,7 @@ public class MongoOpenIddictTokenRepository : MongoDbRepository x.ApplicationId == applicationId) .ToListAsync(GetCancellationToken(cancellationToken)); @@ -31,7 +31,7 @@ public class MongoOpenIddictTokenRepository : MongoDbRepository x.AuthorizationId == authorizationId) .ToListAsync(GetCancellationToken(cancellationToken)); @@ -40,7 +40,7 @@ public class MongoOpenIddictTokenRepository : MongoDbRepository x.AuthorizationId != null && authorizationIds.Contains(x.AuthorizationId.Value)) .ToListAsync(GetCancellationToken(cancellationToken)); @@ -49,67 +49,62 @@ public class MongoOpenIddictTokenRepository : MongoDbRepository> FindAsync(string subject, Guid? client, string status, string type, CancellationToken cancellationToken = default) { - return await (await GetMongoQueryableAsync(cancellationToken)) + return await (await GetQueryableAsync(cancellationToken)) .WhereIf(!subject.IsNullOrWhiteSpace(), x => x.Subject == subject) .WhereIf(client.HasValue, x => x.ApplicationId == client) .WhereIf(!status.IsNullOrWhiteSpace(), x => x.Status == status) .WhereIf(!type.IsNullOrWhiteSpace(), x => x.Type == type) - .As>() .ToListAsync(GetCancellationToken(cancellationToken)); } public virtual async Task> FindByApplicationIdAsync(Guid applicationId, CancellationToken cancellationToken = default) { - return await (await GetMongoQueryableAsync(GetCancellationToken(cancellationToken))) + return await (await GetQueryableAsync(GetCancellationToken(cancellationToken))) .Where(x => x.ApplicationId == applicationId) - .As>() .ToListAsync(GetCancellationToken(cancellationToken)); } public virtual async Task> FindByAuthorizationIdAsync(Guid authorizationId, CancellationToken cancellationToken = default) { - return await (await GetMongoQueryableAsync(GetCancellationToken(cancellationToken))) + return await (await GetQueryableAsync(GetCancellationToken(cancellationToken))) .Where(x => x.AuthorizationId == authorizationId) - .As>() .ToListAsync(GetCancellationToken(cancellationToken)); } public virtual async Task FindByIdAsync(Guid id, CancellationToken cancellationToken = default) { - return await (await GetMongoQueryableAsync(GetCancellationToken(cancellationToken))).FirstOrDefaultAsync(x => x.Id == id, GetCancellationToken(cancellationToken)); + return await (await GetQueryableAsync(GetCancellationToken(cancellationToken))).FirstOrDefaultAsync(x => x.Id == id, GetCancellationToken(cancellationToken)); } public virtual async Task FindByReferenceIdAsync(string referenceId, CancellationToken cancellationToken = default) { - return await (await GetMongoQueryableAsync(GetCancellationToken(cancellationToken))).FirstOrDefaultAsync(x => x.ReferenceId == referenceId, GetCancellationToken(cancellationToken)); + return await (await GetQueryableAsync(GetCancellationToken(cancellationToken))).FirstOrDefaultAsync(x => x.ReferenceId == referenceId, GetCancellationToken(cancellationToken)); } public virtual async Task> FindBySubjectAsync(string subject, CancellationToken cancellationToken = default) { - return await (await GetMongoQueryableAsync(GetCancellationToken(cancellationToken))) + return await (await GetQueryableAsync(GetCancellationToken(cancellationToken))) .Where(x => x.Subject == subject) - .As>() .ToListAsync(GetCancellationToken(cancellationToken)); } public virtual async Task> ListAsync(int? count, int? offset, CancellationToken cancellationToken = default) { - return await (await GetMongoQueryableAsync(GetCancellationToken(cancellationToken))) + return await (await GetQueryableAsync(GetCancellationToken(cancellationToken))) .OrderBy(x => x.Id) .SkipIf>(offset.HasValue, offset) .TakeIf>(count.HasValue, count) - .As>() .ToListAsync(GetCancellationToken(cancellationToken)); } public virtual async Task PruneAsync(DateTime date, CancellationToken cancellationToken = default) { - var authorizationIds = await (await GetMongoQueryableAsync(cancellationToken)) + var authorizationIds = await (await GetQueryableAsync(cancellationToken)) .Where(x => x.Status != OpenIddictConstants.Statuses.Valid) .Select(x => x.Id) .ToListAsync(GetCancellationToken(cancellationToken)); - var tokens = await (await GetMongoQueryableAsync(GetCancellationToken(cancellationToken))) + var tokens = await (await GetQueryableAsync(GetCancellationToken(cancellationToken))) .Where(x => x.CreationDate < date) .Where(x => (x.Status != OpenIddictConstants.Statuses.Inactive && x.Status != OpenIddictConstants.Statuses.Valid) || diff --git a/modules/openiddict/test/Volo.Abp.OpenIddict.MongoDB.Tests/Volo.Abp.OpenIddict.MongoDB.Tests.csproj b/modules/openiddict/test/Volo.Abp.OpenIddict.MongoDB.Tests/Volo.Abp.OpenIddict.MongoDB.Tests.csproj index 56512b464c..d5f8903293 100644 --- a/modules/openiddict/test/Volo.Abp.OpenIddict.MongoDB.Tests/Volo.Abp.OpenIddict.MongoDB.Tests.csproj +++ b/modules/openiddict/test/Volo.Abp.OpenIddict.MongoDB.Tests/Volo.Abp.OpenIddict.MongoDB.Tests.csproj @@ -9,10 +9,10 @@ - - - - + + + + diff --git a/modules/openiddict/test/Volo.Abp.OpenIddict.MongoDB.Tests/Volo/Abp/OpenIddict/MongoDB/MongoDbFixture.cs b/modules/openiddict/test/Volo.Abp.OpenIddict.MongoDB.Tests/Volo/Abp/OpenIddict/MongoDB/MongoDbFixture.cs index ddceaf8104..1716d478a5 100644 --- a/modules/openiddict/test/Volo.Abp.OpenIddict.MongoDB.Tests/Volo/Abp/OpenIddict/MongoDB/MongoDbFixture.cs +++ b/modules/openiddict/test/Volo.Abp.OpenIddict.MongoDB.Tests/Volo/Abp/OpenIddict/MongoDB/MongoDbFixture.cs @@ -1,5 +1,5 @@ using System; -using EphemeralMongo; +using MongoSandbox; namespace Volo.Abp.OpenIddict.MongoDB; diff --git a/modules/permission-management/src/Volo.Abp.PermissionManagement.MongoDB/Volo/Abp/PermissionManagement/MongoDb/MongoPermissionDefinitionRecordRepository.cs b/modules/permission-management/src/Volo.Abp.PermissionManagement.MongoDB/Volo/Abp/PermissionManagement/MongoDb/MongoPermissionDefinitionRecordRepository.cs index 529f56511c..2f98db4f60 100644 --- a/modules/permission-management/src/Volo.Abp.PermissionManagement.MongoDB/Volo/Abp/PermissionManagement/MongoDb/MongoPermissionDefinitionRecordRepository.cs +++ b/modules/permission-management/src/Volo.Abp.PermissionManagement.MongoDB/Volo/Abp/PermissionManagement/MongoDb/MongoPermissionDefinitionRecordRepository.cs @@ -1,6 +1,7 @@ using System; using System.Threading; using System.Threading.Tasks; +using System.Linq; using MongoDB.Driver.Linq; using Volo.Abp.Domain.Repositories.MongoDB; using Volo.Abp.MongoDB; @@ -22,7 +23,7 @@ public class MongoPermissionDefinitionRecordRepository : CancellationToken cancellationToken = default) { cancellationToken = GetCancellationToken(cancellationToken); - return await (await GetMongoQueryableAsync(cancellationToken)) + return await (await GetQueryableAsync(cancellationToken)) .OrderBy(x => x.Id) .FirstOrDefaultAsync( s => s.Name == name, 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 aa7694b7d5..d83d916890 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 @@ -27,7 +27,7 @@ public class MongoPermissionGrantRepository : CancellationToken cancellationToken = default) { cancellationToken = GetCancellationToken(cancellationToken); - return await (await GetMongoQueryableAsync(cancellationToken)) + return await (await GetQueryableAsync(cancellationToken)) .OrderBy(x => x.Id) .FirstOrDefaultAsync(s => s.Name == name && @@ -43,7 +43,7 @@ public class MongoPermissionGrantRepository : CancellationToken cancellationToken = default) { cancellationToken = GetCancellationToken(cancellationToken); - return await (await GetMongoQueryableAsync(cancellationToken)) + return await (await GetQueryableAsync(cancellationToken)) .Where(s => s.ProviderName == providerName && s.ProviderKey == providerKey @@ -54,7 +54,7 @@ public class MongoPermissionGrantRepository : CancellationToken cancellationToken = default) { cancellationToken = GetCancellationToken(cancellationToken); - return await (await GetMongoQueryableAsync(cancellationToken)) + return await (await GetQueryableAsync(cancellationToken)) .Where(s => names.Contains(s.Name) && s.ProviderName == providerName && diff --git a/modules/permission-management/test/Volo.Abp.PermissionManagement.MongoDB.Tests/Volo.Abp.PermissionManagement.MongoDB.Tests.csproj b/modules/permission-management/test/Volo.Abp.PermissionManagement.MongoDB.Tests/Volo.Abp.PermissionManagement.MongoDB.Tests.csproj index 757b0f164c..0f9e0169e8 100644 --- a/modules/permission-management/test/Volo.Abp.PermissionManagement.MongoDB.Tests/Volo.Abp.PermissionManagement.MongoDB.Tests.csproj +++ b/modules/permission-management/test/Volo.Abp.PermissionManagement.MongoDB.Tests/Volo.Abp.PermissionManagement.MongoDB.Tests.csproj @@ -19,10 +19,10 @@ - - - - + + + + diff --git a/modules/permission-management/test/Volo.Abp.PermissionManagement.MongoDB.Tests/Volo/Abp/PermissionManagement/MongoDb/MongoDbFixture.cs b/modules/permission-management/test/Volo.Abp.PermissionManagement.MongoDB.Tests/Volo/Abp/PermissionManagement/MongoDb/MongoDbFixture.cs index fc039d7ee2..05fae7288c 100644 --- a/modules/permission-management/test/Volo.Abp.PermissionManagement.MongoDB.Tests/Volo/Abp/PermissionManagement/MongoDb/MongoDbFixture.cs +++ b/modules/permission-management/test/Volo.Abp.PermissionManagement.MongoDB.Tests/Volo/Abp/PermissionManagement/MongoDb/MongoDbFixture.cs @@ -1,5 +1,5 @@ using System; -using EphemeralMongo; +using MongoSandbox; namespace Volo.Abp.PermissionManagement.MongoDB; diff --git a/modules/setting-management/src/Volo.Abp.SettingManagement.MongoDB/Volo/Abp/SettingManagement/MongoDB/MongoSettingDefinitionRecordRepository.cs b/modules/setting-management/src/Volo.Abp.SettingManagement.MongoDB/Volo/Abp/SettingManagement/MongoDB/MongoSettingDefinitionRecordRepository.cs index d2500cccd2..3ea0206759 100644 --- a/modules/setting-management/src/Volo.Abp.SettingManagement.MongoDB/Volo/Abp/SettingManagement/MongoDB/MongoSettingDefinitionRecordRepository.cs +++ b/modules/setting-management/src/Volo.Abp.SettingManagement.MongoDB/Volo/Abp/SettingManagement/MongoDB/MongoSettingDefinitionRecordRepository.cs @@ -1,6 +1,7 @@ using System; using System.Threading; using System.Threading.Tasks; +using System.Linq; using MongoDB.Driver.Linq; using Volo.Abp.Domain.Repositories.MongoDB; using Volo.Abp.MongoDB; @@ -16,7 +17,7 @@ public class MongoSettingDefinitionRecordRepository : MongoDbRepository FindByNameAsync(string name, CancellationToken cancellationToken = default) { - return await (await GetMongoQueryableAsync(cancellationToken)) + return await (await GetQueryableAsync(cancellationToken)) .OrderBy(x => x.Id) .FirstOrDefaultAsync(s => s.Name == name, GetCancellationToken(cancellationToken)); } 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 74c680e7e2..ea264b254e 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 @@ -24,7 +24,7 @@ public class MongoSettingRepository : MongoDbRepository x.Id) .FirstOrDefaultAsync( s => s.Name == name && s.ProviderName == providerName && s.ProviderKey == providerKey, @@ -36,7 +36,7 @@ public class MongoSettingRepository : MongoDbRepository s.ProviderName == providerName && s.ProviderKey == providerKey) .ToListAsync(GetCancellationToken(cancellationToken)); } @@ -47,7 +47,7 @@ public class MongoSettingRepository : MongoDbRepository names.Contains(s.Name) && s.ProviderName == providerName && s.ProviderKey == providerKey) .ToListAsync(GetCancellationToken(cancellationToken)); } diff --git a/modules/setting-management/test/Volo.Abp.SettingManagement.MongoDB.Tests/Volo.Abp.SettingManagement.MongoDB.Tests.csproj b/modules/setting-management/test/Volo.Abp.SettingManagement.MongoDB.Tests/Volo.Abp.SettingManagement.MongoDB.Tests.csproj index 65ea9436ee..9c2c2f36a9 100644 --- a/modules/setting-management/test/Volo.Abp.SettingManagement.MongoDB.Tests/Volo.Abp.SettingManagement.MongoDB.Tests.csproj +++ b/modules/setting-management/test/Volo.Abp.SettingManagement.MongoDB.Tests/Volo.Abp.SettingManagement.MongoDB.Tests.csproj @@ -18,10 +18,10 @@ - - - - + + + + diff --git a/modules/setting-management/test/Volo.Abp.SettingManagement.MongoDB.Tests/Volo/Abp/SettingManagement/MongoDB/MongoDbFixture.cs b/modules/setting-management/test/Volo.Abp.SettingManagement.MongoDB.Tests/Volo/Abp/SettingManagement/MongoDB/MongoDbFixture.cs index 625b66b328..bc5feb98b1 100644 --- a/modules/setting-management/test/Volo.Abp.SettingManagement.MongoDB.Tests/Volo/Abp/SettingManagement/MongoDB/MongoDbFixture.cs +++ b/modules/setting-management/test/Volo.Abp.SettingManagement.MongoDB.Tests/Volo/Abp/SettingManagement/MongoDB/MongoDbFixture.cs @@ -1,5 +1,5 @@ using System; -using EphemeralMongo; +using MongoSandbox; namespace Volo.Abp.SettingManagement.MongoDB; diff --git a/modules/tenant-management/src/Volo.Abp.TenantManagement.MongoDB/Volo/Abp/TenantManagement/MongoDb/MongoTenantRepository.cs b/modules/tenant-management/src/Volo.Abp.TenantManagement.MongoDB/Volo/Abp/TenantManagement/MongoDb/MongoTenantRepository.cs index 049dc5e57c..758ece4d71 100644 --- a/modules/tenant-management/src/Volo.Abp.TenantManagement.MongoDB/Volo/Abp/TenantManagement/MongoDb/MongoTenantRepository.cs +++ b/modules/tenant-management/src/Volo.Abp.TenantManagement.MongoDB/Volo/Abp/TenantManagement/MongoDb/MongoTenantRepository.cs @@ -24,21 +24,21 @@ public class MongoTenantRepository : MongoDbRepository t.NormalizedName == normalizedName, GetCancellationToken(cancellationToken)); } [Obsolete("Use FindByNameAsync method.")] public virtual Tenant FindByName(string normalizedName, bool includeDetails = true) { - return GetMongoQueryable() + return GetQueryable() .FirstOrDefault(t => t.NormalizedName == normalizedName); } [Obsolete("Use FindAsync method.")] public virtual Tenant FindById(Guid id, bool includeDetails = true) { - return GetMongoQueryable() + return GetQueryable() .FirstOrDefault(t => t.Id == id); } @@ -50,22 +50,21 @@ public class MongoTenantRepository : MongoDbRepository>( + return await (await GetQueryableAsync(cancellationToken)) + .WhereIf( !filter.IsNullOrWhiteSpace(), u => u.Name.Contains(filter) ) .OrderBy(sorting.IsNullOrEmpty() ? nameof(Tenant.Name) : sorting) - .As>() - .PageBy>(skipCount, maxResultCount) + .PageBy(skipCount, maxResultCount) .ToListAsync(GetCancellationToken(cancellationToken)); } public virtual async Task GetCountAsync(string filter = null, CancellationToken cancellationToken = default) { - return await (await GetMongoQueryableAsync(cancellationToken)) - .WhereIf>( + return await (await GetQueryableAsync(cancellationToken)) + .WhereIf( !filter.IsNullOrWhiteSpace(), u => u.Name.Contains(filter) diff --git a/modules/tenant-management/test/Volo.Abp.TenantManagement.MongoDB.Tests/Volo.Abp.TenantManagement.MongoDB.Tests.csproj b/modules/tenant-management/test/Volo.Abp.TenantManagement.MongoDB.Tests/Volo.Abp.TenantManagement.MongoDB.Tests.csproj index c22da31998..2913a0ed53 100644 --- a/modules/tenant-management/test/Volo.Abp.TenantManagement.MongoDB.Tests/Volo.Abp.TenantManagement.MongoDB.Tests.csproj +++ b/modules/tenant-management/test/Volo.Abp.TenantManagement.MongoDB.Tests/Volo.Abp.TenantManagement.MongoDB.Tests.csproj @@ -18,10 +18,10 @@ - - - - + + + + diff --git a/modules/tenant-management/test/Volo.Abp.TenantManagement.MongoDB.Tests/Volo/Abp/TenantManagement/MongoDb/MongoDbFixture.cs b/modules/tenant-management/test/Volo.Abp.TenantManagement.MongoDB.Tests/Volo/Abp/TenantManagement/MongoDb/MongoDbFixture.cs index 7b12dc33e7..4610234bf6 100644 --- a/modules/tenant-management/test/Volo.Abp.TenantManagement.MongoDB.Tests/Volo/Abp/TenantManagement/MongoDb/MongoDbFixture.cs +++ b/modules/tenant-management/test/Volo.Abp.TenantManagement.MongoDB.Tests/Volo/Abp/TenantManagement/MongoDb/MongoDbFixture.cs @@ -1,5 +1,5 @@ using System; -using EphemeralMongo; +using MongoSandbox; using MongoDB.Driver; using Volo.Abp.MongoDB; 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 d0e1e76873..2e657227b1 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 @@ -24,7 +24,7 @@ public abstract class MongoUserRepositoryBase : MongoDbReposi public virtual async Task FindByUserNameAsync(string userName, CancellationToken cancellationToken = default) { cancellationToken = GetCancellationToken(cancellationToken); - return await (await GetMongoQueryableAsync(cancellationToken)) + return await (await GetQueryableAsync(cancellationToken)) .OrderBy(x => x.Id) .FirstOrDefaultAsync(u => u.UserName == userName, cancellationToken); } @@ -32,7 +32,7 @@ public abstract class MongoUserRepositoryBase : MongoDbReposi public virtual async Task> GetListAsync(IEnumerable ids, CancellationToken cancellationToken = default) { cancellationToken = GetCancellationToken(cancellationToken); - return await (await GetMongoQueryableAsync(cancellationToken)) + return await (await GetQueryableAsync(cancellationToken)) .Where(u => ids.Contains(u.Id)) .ToListAsync(cancellationToken); } @@ -45,8 +45,8 @@ public abstract class MongoUserRepositoryBase : MongoDbReposi CancellationToken cancellationToken = default) { cancellationToken = GetCancellationToken(cancellationToken); - return await (await GetMongoQueryableAsync(cancellationToken)) - .WhereIf>( + return await (await GetQueryableAsync(cancellationToken)) + .WhereIf( !filter.IsNullOrWhiteSpace(), u => u.UserName.Contains(filter) || @@ -55,16 +55,15 @@ public abstract class MongoUserRepositoryBase : MongoDbReposi (u.Surname != null && u.Surname.Contains(filter)) ) .OrderBy(sorting.IsNullOrEmpty() ? nameof(IUserData.UserName) : sorting) - .As>() - .PageBy>(skipCount, maxResultCount) + .PageBy(skipCount, maxResultCount) .ToListAsync(cancellationToken); } public async Task GetCountAsync(string filter = null, CancellationToken cancellationToken = default) { cancellationToken = GetCancellationToken(cancellationToken); - return await (await GetMongoQueryableAsync(cancellationToken)) - .WhereIf>( + return await (await GetQueryableAsync(cancellationToken)) + .WhereIf( !filter.IsNullOrWhiteSpace(), u => u.UserName.Contains(filter) || diff --git a/templates/app/aspnet-core/test/MyCompanyName.MyProjectName.MongoDB.Tests/MongoDb/MyProjectNameMongoDbFixture.cs b/templates/app/aspnet-core/test/MyCompanyName.MyProjectName.MongoDB.Tests/MongoDb/MyProjectNameMongoDbFixture.cs index 55387d7ba5..e69539eff8 100644 --- a/templates/app/aspnet-core/test/MyCompanyName.MyProjectName.MongoDB.Tests/MongoDb/MyProjectNameMongoDbFixture.cs +++ b/templates/app/aspnet-core/test/MyCompanyName.MyProjectName.MongoDB.Tests/MongoDb/MyProjectNameMongoDbFixture.cs @@ -1,5 +1,5 @@ using System; -using EphemeralMongo; +using MongoSandbox; namespace MyCompanyName.MyProjectName.MongoDB; diff --git a/templates/app/aspnet-core/test/MyCompanyName.MyProjectName.MongoDB.Tests/MongoDb/Samples/SampleRepositoryTests.cs b/templates/app/aspnet-core/test/MyCompanyName.MyProjectName.MongoDB.Tests/MongoDb/Samples/SampleRepositoryTests.cs index 9f51c616ec..f705959e83 100644 --- a/templates/app/aspnet-core/test/MyCompanyName.MyProjectName.MongoDB.Tests/MongoDb/Samples/SampleRepositoryTests.cs +++ b/templates/app/aspnet-core/test/MyCompanyName.MyProjectName.MongoDB.Tests/MongoDb/Samples/SampleRepositoryTests.cs @@ -32,7 +32,7 @@ public class SampleRepositoryTests : MyProjectNameMongoDbTestBase await WithUnitOfWorkAsync(async () => { //Act - var adminUser = await (await _appUserRepository.GetMongoQueryableAsync()) + var adminUser = await (await _appUserRepository.GetQueryableAsync()) .FirstOrDefaultAsync(u => u.UserName == "admin"); //Assert diff --git a/templates/app/aspnet-core/test/MyCompanyName.MyProjectName.MongoDB.Tests/MyCompanyName.MyProjectName.MongoDB.Tests.csproj b/templates/app/aspnet-core/test/MyCompanyName.MyProjectName.MongoDB.Tests/MyCompanyName.MyProjectName.MongoDB.Tests.csproj index 53cc18991c..e18c27a2de 100644 --- a/templates/app/aspnet-core/test/MyCompanyName.MyProjectName.MongoDB.Tests/MyCompanyName.MyProjectName.MongoDB.Tests.csproj +++ b/templates/app/aspnet-core/test/MyCompanyName.MyProjectName.MongoDB.Tests/MyCompanyName.MyProjectName.MongoDB.Tests.csproj @@ -15,10 +15,10 @@ - - - - + + + + diff --git a/templates/module/aspnet-core/test/MyCompanyName.MyProjectName.MongoDB.Tests/MongoDB/MongoDbFixture.cs b/templates/module/aspnet-core/test/MyCompanyName.MyProjectName.MongoDB.Tests/MongoDB/MongoDbFixture.cs index 07cfd77583..63a2f598c5 100644 --- a/templates/module/aspnet-core/test/MyCompanyName.MyProjectName.MongoDB.Tests/MongoDB/MongoDbFixture.cs +++ b/templates/module/aspnet-core/test/MyCompanyName.MyProjectName.MongoDB.Tests/MongoDB/MongoDbFixture.cs @@ -1,5 +1,5 @@ using System; -using EphemeralMongo; +using MongoSandbox; namespace MyCompanyName.MyProjectName.MongoDB; diff --git a/templates/module/aspnet-core/test/MyCompanyName.MyProjectName.MongoDB.Tests/MyCompanyName.MyProjectName.MongoDB.Tests.csproj b/templates/module/aspnet-core/test/MyCompanyName.MyProjectName.MongoDB.Tests/MyCompanyName.MyProjectName.MongoDB.Tests.csproj index fed5495bbe..5e43f82146 100644 --- a/templates/module/aspnet-core/test/MyCompanyName.MyProjectName.MongoDB.Tests/MyCompanyName.MyProjectName.MongoDB.Tests.csproj +++ b/templates/module/aspnet-core/test/MyCompanyName.MyProjectName.MongoDB.Tests/MyCompanyName.MyProjectName.MongoDB.Tests.csproj @@ -10,10 +10,10 @@ - - - - + + + +