Browse Source

Merge pull request #21807 from abpframework/MongoDB.Driver.3

Upgrade `MongoDB.Driver` to `3.1.0`.
pull/21999/head
Halil İbrahim Kalkan 2 years ago
committed by GitHub
parent
commit
25d70e254f
No known key found for this signature in database GPG Key ID: B5690EEEBB952194
  1. 6
      Directory.Packages.props
  2. 6
      build/common.ps1
  3. 8
      docs/en/framework/architecture/best-practices/mongodb-integration.md
  4. 13
      docs/en/framework/architecture/domain-driven-design/repositories.md
  5. 8
      docs/en/guides/microservice-mongodb.md
  6. 59
      docs/en/release-info/migration-guides/MongoDB-Driver-2-to-3.md
  7. 7
      docs/en/tutorials/book-store/part-07.md
  8. 11
      framework/src/Volo.Abp.MongoDB/Volo/Abp/Domain/Repositories/MongoDB/IMongoDbRepository.cs
  9. 53
      framework/src/Volo.Abp.MongoDB/Volo/Abp/Domain/Repositories/MongoDB/MongoDbRepository.cs
  10. 15
      framework/src/Volo.Abp.MongoDB/Volo/Abp/Domain/Repositories/MongoDbCoreRepositoryExtensions.cs
  11. 2
      framework/src/Volo.Abp.MongoDB/Volo/Abp/MongoDB/AbpMongoDbDateTimeSerializer.cs
  12. 5
      framework/src/Volo.Abp.MongoDB/Volo/Abp/MongoDB/AbpMongoDbModule.cs
  13. 1
      framework/src/Volo.Abp.MongoDB/Volo/Abp/MongoDB/DistributedEvents/MongoDbContextEventInbox.cs
  14. 1
      framework/src/Volo.Abp.MongoDB/Volo/Abp/MongoDB/DistributedEvents/MongoDbContextEventOutbox.cs
  15. 141
      framework/src/Volo.Abp.MongoDB/Volo/Abp/MongoDB/MongoDbAsyncQueryableProvider.cs
  16. 8
      framework/test/Volo.Abp.MongoDB.Tests/Volo.Abp.MongoDB.Tests.csproj
  17. 5
      framework/test/Volo.Abp.MongoDB.Tests/Volo/Abp/MongoDB/MongoDbFixture.cs
  18. 12
      framework/test/Volo.Abp.MongoDB.Tests/Volo/Abp/MongoDB/Repositories/Repository_Basic_Tests.cs
  19. 1
      framework/test/Volo.Abp.MongoDB.Tests/Volo/Abp/TestApp/MongoDb/CityRepository.cs
  20. 24
      modules/audit-logging/src/Volo.Abp.AuditLogging.MongoDB/Volo/Abp/AuditLogging/MongoDB/MongoAuditLogRepository.cs
  21. 8
      modules/audit-logging/test/Volo.Abp.AuditLogging.MongoDB.Tests/Volo.Abp.AuditLogging.MongoDB.Tests.csproj
  22. 2
      modules/audit-logging/test/Volo.Abp.AuditLogging.MongoDB.Tests/Volo/Abp/AuditLogging/MongoDB/MongoDbFixture.cs
  23. 5
      modules/background-jobs/src/Volo.Abp.BackgroundJobs.MongoDB/Volo/Abp/BackgroundJobs/MongoDB/MongoBackgroundJobRepository.cs
  24. 8
      modules/background-jobs/test/Volo.Abp.BackgroundJobs.MongoDB.Tests/Volo.Abp.BackgroundJobs.MongoDB.Tests.csproj
  25. 2
      modules/background-jobs/test/Volo.Abp.BackgroundJobs.MongoDB.Tests/Volo/Abp/BackgroundJobs/MongoDB/MongoDbFixture.cs
  26. 4
      modules/blob-storing-database/src/Volo.Abp.BlobStoring.Database.MongoDB/Volo/Abp/BlobStoring/Database/MongoDB/MongoDbDatabaseBlobRepository.cs
  27. 2
      modules/blob-storing-database/test/Volo.Abp.BlobStoring.Database.MongoDB.Tests/MongoDB/MongoDbFixture.cs
  28. 8
      modules/blob-storing-database/test/Volo.Abp.BlobStoring.Database.MongoDB.Tests/Volo.Abp.BlobStoring.Database.MongoDB.Tests.csproj
  29. 2
      modules/blogging/src/Volo.Blogging.MongoDB/Volo/Blogging/Blogs/MongoBlogRepository.cs
  30. 9
      modules/blogging/src/Volo.Blogging.MongoDB/Volo/Blogging/Comments/MongoCommentRepository.cs
  31. 13
      modules/blogging/src/Volo.Blogging.MongoDB/Volo/Blogging/Posts/MongoPostRepository.cs
  32. 10
      modules/blogging/src/Volo.Blogging.MongoDB/Volo/Blogging/Tagging/MongoTagRepository.cs
  33. 3
      modules/blogging/src/Volo.Blogging.MongoDB/Volo/Blogging/Users/MongoBlogUserRepository.cs
  34. 8
      modules/blogging/test/Volo.Blogging.MongoDB.Tests/Volo.Blogging.MongoDB.Tests.csproj
  35. 2
      modules/blogging/test/Volo.Blogging.MongoDB.Tests/Volo/Blogging/MongoDB/MongoDbFixture.cs
  36. 4
      modules/cms-kit/src/Volo.CmsKit.MongoDB/Volo/CmsKit/MongoDB/Blogs/MongoBlogFeatureRepository.cs
  37. 22
      modules/cms-kit/src/Volo.CmsKit.MongoDB/Volo/CmsKit/MongoDB/Blogs/MongoBlogPostRepository.cs
  38. 13
      modules/cms-kit/src/Volo.CmsKit.MongoDB/Volo/CmsKit/MongoDB/Blogs/MongoBlogRepository.cs
  39. 24
      modules/cms-kit/src/Volo.CmsKit.MongoDB/Volo/CmsKit/MongoDB/Comments/MongoCommentRepository.cs
  40. 6
      modules/cms-kit/src/Volo.CmsKit.MongoDB/Volo/CmsKit/MongoDB/MarkedItems/MongoUserMarkedItemRepository.cs
  41. 15
      modules/cms-kit/src/Volo.CmsKit.MongoDB/Volo/CmsKit/MongoDB/Pages/MongoPageRepository.cs
  42. 4
      modules/cms-kit/src/Volo.CmsKit.MongoDB/Volo/CmsKit/MongoDB/Ratings/MongoRatingRepository.cs
  43. 6
      modules/cms-kit/src/Volo.CmsKit.MongoDB/Volo/CmsKit/MongoDB/Reactions/MongoUserReactionRepository.cs
  44. 2
      modules/cms-kit/src/Volo.CmsKit.MongoDB/Volo/CmsKit/MongoDB/Tags/MongoEntityTagRepository.cs
  45. 17
      modules/cms-kit/src/Volo.CmsKit.MongoDB/Volo/CmsKit/MongoDB/Tags/MongoTagRepository.cs
  46. 2
      modules/cms-kit/test/Volo.CmsKit.MongoDB.Tests/MongoDB/MongoDbFixture.cs
  47. 8
      modules/cms-kit/test/Volo.CmsKit.MongoDB.Tests/Volo.CmsKit.MongoDB.Tests.csproj
  48. 108
      modules/docs/src/Volo.Docs.MongoDB/Volo/Docs/Documents/MongoDocumentRepository.cs
  49. 9
      modules/docs/src/Volo.Docs.MongoDB/Volo/Docs/Projects/MongoProjectRepository.cs
  50. 8
      modules/docs/test/Volo.Docs.MongoDB.Tests/Volo.Docs.MongoDB.Tests.csproj
  51. 2
      modules/docs/test/Volo.Docs.MongoDB.Tests/Volo/Docs/MongoDB/MongoDbFixture.cs
  52. 3
      modules/feature-management/src/Volo.Abp.FeatureManagement.MongoDB/Volo/Abp/FeatureManagement/MongoDB/MongoFeatureDefinitionRecordRepository.cs
  53. 6
      modules/feature-management/src/Volo.Abp.FeatureManagement.MongoDB/Volo/Abp/FeatureManagement/MongoDB/MongoFeatureValueRepository.cs
  54. 8
      modules/feature-management/test/Volo.Abp.FeatureManagement.MongoDB.Tests/Volo.Abp.FeatureManagement.MongoDB.Tests.csproj
  55. 2
      modules/feature-management/test/Volo.Abp.FeatureManagement.MongoDB.Tests/Volo/Abp/FeatureManagement/MongoDB/MongoDbFixture.cs
  56. 18
      modules/identity/src/Volo.Abp.Identity.MongoDB/Volo/Abp/Identity/MongoDB/MongoIdentityClaimTypeRepository.cs
  57. 6
      modules/identity/src/Volo.Abp.Identity.MongoDB/Volo/Abp/Identity/MongoDB/MongoIdentityLinkUserRepository.cs
  58. 18
      modules/identity/src/Volo.Abp.Identity.MongoDB/Volo/Abp/Identity/MongoDB/MongoIdentityRoleRepository.cs
  59. 10
      modules/identity/src/Volo.Abp.Identity.MongoDB/Volo/Abp/Identity/MongoDB/MongoIdentitySecurityLogRepository.cs
  60. 15
      modules/identity/src/Volo.Abp.Identity.MongoDB/Volo/Abp/Identity/MongoDB/MongoIdentitySessionRepository.cs
  61. 8
      modules/identity/src/Volo.Abp.Identity.MongoDB/Volo/Abp/Identity/MongoDB/MongoIdentityUserDelegationRepository.cs
  62. 91
      modules/identity/src/Volo.Abp.Identity.MongoDB/Volo/Abp/Identity/MongoDB/MongoIdentityUserRepository.cs
  63. 65
      modules/identity/src/Volo.Abp.Identity.MongoDB/Volo/Abp/Identity/MongoDB/MongoOrganizationUnitRepository.cs
  64. 8
      modules/identity/test/Volo.Abp.Identity.MongoDB.Tests/Volo.Abp.Identity.MongoDB.Tests.csproj
  65. 2
      modules/identity/test/Volo.Abp.Identity.MongoDB.Tests/Volo/Abp/Identity/MongoDB/MongoDbFixture.cs
  66. 17
      modules/identityserver/src/Volo.Abp.IdentityServer.MongoDB/Volo/Abp/IdentityServer/MongoDB/MongoApiResourceRepository.cs
  67. 15
      modules/identityserver/src/Volo.Abp.IdentityServer.MongoDB/Volo/Abp/IdentityServer/MongoDB/MongoApiScopeRepository.cs
  68. 15
      modules/identityserver/src/Volo.Abp.IdentityServer.MongoDB/Volo/Abp/IdentityServer/MongoDB/MongoClientRepository.cs
  69. 7
      modules/identityserver/src/Volo.Abp.IdentityServer.MongoDB/Volo/Abp/IdentityServer/MongoDB/MongoDeviceFlowCodesRepository.cs
  70. 15
      modules/identityserver/src/Volo.Abp.IdentityServer.MongoDB/Volo/Abp/IdentityServer/MongoDB/MongoIdentityResourceRepository.cs
  71. 19
      modules/identityserver/src/Volo.Abp.IdentityServer.MongoDB/Volo/Abp/IdentityServer/MongoDB/MongoPersistentGrantRepository.cs
  72. 8
      modules/identityserver/test/Volo.Abp.IdentityServer.MongoDB.Tests/Volo.Abp.IdentityServer.MongoDB.Tests.csproj
  73. 2
      modules/identityserver/test/Volo.Abp.IdentityServer.MongoDB.Tests/Volo/Abp/IdentityServer/MongoDbFixture.cs
  74. 17
      modules/openiddict/src/Volo.Abp.OpenIddict.MongoDB/Volo/Abp/OpenIddict/Applications/MongoOpenIddictApplicationRepository.cs
  75. 19
      modules/openiddict/src/Volo.Abp.OpenIddict.MongoDB/Volo/Abp/OpenIddict/Authorizations/MongoOpenIddictAuthorizationRepository.cs
  76. 19
      modules/openiddict/src/Volo.Abp.OpenIddict.MongoDB/Volo/Abp/OpenIddict/Scopes/MongoOpenIddictScopeRepository.cs
  77. 29
      modules/openiddict/src/Volo.Abp.OpenIddict.MongoDB/Volo/Abp/OpenIddict/Tokens/MongoOpenIddictTokenRepository.cs
  78. 8
      modules/openiddict/test/Volo.Abp.OpenIddict.MongoDB.Tests/Volo.Abp.OpenIddict.MongoDB.Tests.csproj
  79. 2
      modules/openiddict/test/Volo.Abp.OpenIddict.MongoDB.Tests/Volo/Abp/OpenIddict/MongoDB/MongoDbFixture.cs
  80. 3
      modules/permission-management/src/Volo.Abp.PermissionManagement.MongoDB/Volo/Abp/PermissionManagement/MongoDb/MongoPermissionDefinitionRecordRepository.cs
  81. 6
      modules/permission-management/src/Volo.Abp.PermissionManagement.MongoDB/Volo/Abp/PermissionManagement/MongoDb/MongoPermissionGrantRepository.cs
  82. 8
      modules/permission-management/test/Volo.Abp.PermissionManagement.MongoDB.Tests/Volo.Abp.PermissionManagement.MongoDB.Tests.csproj
  83. 2
      modules/permission-management/test/Volo.Abp.PermissionManagement.MongoDB.Tests/Volo/Abp/PermissionManagement/MongoDb/MongoDbFixture.cs
  84. 3
      modules/setting-management/src/Volo.Abp.SettingManagement.MongoDB/Volo/Abp/SettingManagement/MongoDB/MongoSettingDefinitionRecordRepository.cs
  85. 6
      modules/setting-management/src/Volo.Abp.SettingManagement.MongoDB/Volo/Abp/SettingManagement/MongoDB/MongoSettingRepository.cs
  86. 8
      modules/setting-management/test/Volo.Abp.SettingManagement.MongoDB.Tests/Volo.Abp.SettingManagement.MongoDB.Tests.csproj
  87. 2
      modules/setting-management/test/Volo.Abp.SettingManagement.MongoDB.Tests/Volo/Abp/SettingManagement/MongoDB/MongoDbFixture.cs
  88. 17
      modules/tenant-management/src/Volo.Abp.TenantManagement.MongoDB/Volo/Abp/TenantManagement/MongoDb/MongoTenantRepository.cs
  89. 8
      modules/tenant-management/test/Volo.Abp.TenantManagement.MongoDB.Tests/Volo.Abp.TenantManagement.MongoDB.Tests.csproj
  90. 2
      modules/tenant-management/test/Volo.Abp.TenantManagement.MongoDB.Tests/Volo/Abp/TenantManagement/MongoDb/MongoDbFixture.cs
  91. 15
      modules/users/src/Volo.Abp.Users.MongoDB/Volo/Abp/Users/MongoDB/MongoUserRepositoryBase.cs
  92. 2
      templates/app/aspnet-core/test/MyCompanyName.MyProjectName.MongoDB.Tests/MongoDb/MyProjectNameMongoDbFixture.cs
  93. 2
      templates/app/aspnet-core/test/MyCompanyName.MyProjectName.MongoDB.Tests/MongoDb/Samples/SampleRepositoryTests.cs
  94. 8
      templates/app/aspnet-core/test/MyCompanyName.MyProjectName.MongoDB.Tests/MyCompanyName.MyProjectName.MongoDB.Tests.csproj
  95. 2
      templates/module/aspnet-core/test/MyCompanyName.MyProjectName.MongoDB.Tests/MongoDB/MongoDbFixture.cs
  96. 8
      templates/module/aspnet-core/test/MyCompanyName.MyProjectName.MongoDB.Tests/MyCompanyName.MyProjectName.MongoDB.Tests.csproj

6
Directory.Packages.props

@ -37,6 +37,10 @@
<PackageVersion Include="EphemeralMongo6.runtime.linux-x64" Version="1.1.3" /> <PackageVersion Include="EphemeralMongo6.runtime.linux-x64" Version="1.1.3" />
<PackageVersion Include="EphemeralMongo6.runtime.osx-x64" Version="1.1.3" /> <PackageVersion Include="EphemeralMongo6.runtime.osx-x64" Version="1.1.3" />
<PackageVersion Include="EphemeralMongo6.runtime.win-x64" Version="1.1.3" /> <PackageVersion Include="EphemeralMongo6.runtime.win-x64" Version="1.1.3" />
<PackageVersion Include="MongoSandbox.Core" Version="1.0.1" />
<PackageVersion Include="MongoSandbox6.runtime.linux-x64" Version="1.0.1" />
<PackageVersion Include="MongoSandbox6.runtime.osx-x64" Version="1.0.1" />
<PackageVersion Include="MongoSandbox6.runtime.win-x64" Version="1.0.1" />
<PackageVersion Include="FluentValidation" Version="11.10.0" /> <PackageVersion Include="FluentValidation" Version="11.10.0" />
<PackageVersion Include="Google.Cloud.Storage.V1" Version="4.10.0" /> <PackageVersion Include="Google.Cloud.Storage.V1" Version="4.10.0" />
<PackageVersion Include="Hangfire.AspNetCore" Version="1.8.17" /> <PackageVersion Include="Hangfire.AspNetCore" Version="1.8.17" />
@ -111,7 +115,7 @@
<PackageVersion Include="Microsoft.IdentityModel.Tokens" Version="8.3.0" /> <PackageVersion Include="Microsoft.IdentityModel.Tokens" Version="8.3.0" />
<PackageVersion Include="Microsoft.IdentityModel.JsonWebTokens" Version="8.3.0" /> <PackageVersion Include="Microsoft.IdentityModel.JsonWebTokens" Version="8.3.0" />
<PackageVersion Include="Minio" Version="6.0.3" /> <PackageVersion Include="Minio" Version="6.0.3" />
<PackageVersion Include="MongoDB.Driver" Version="2.29.0" /> <PackageVersion Include="MongoDB.Driver" Version="3.1.0" />
<PackageVersion Include="NEST" Version="7.17.5" /> <PackageVersion Include="NEST" Version="7.17.5" />
<PackageVersion Include="Newtonsoft.Json" Version="13.0.3" /> <PackageVersion Include="Newtonsoft.Json" Version="13.0.3" />
<PackageVersion Include="Nito.AsyncEx.Context" Version="5.1.2" /> <PackageVersion Include="Nito.AsyncEx.Context" Version="5.1.2" />

6
build/common.ps1

@ -34,11 +34,13 @@ if ($full -eq "-f")
"../templates/module/aspnet-core", "../templates/module/aspnet-core",
"../templates/app/aspnet-core", "../templates/app/aspnet-core",
"../templates/console", "../templates/console",
"../templates/wpf",
"../templates/app-nolayers/aspnet-core", "../templates/app-nolayers/aspnet-core",
"../abp_io/AbpIoLocalization", "../abp_io/AbpIoLocalization",
"../source-code" "../source-code"
) )
if ($env:OS -eq "Windows_NT") {
$solutionPaths += "../templates/wpf"
}
}else{ }else{
Write-host "" Write-host ""
Write-host ":::::::::::::: !!! You are in development mode !!! ::::::::::::::" -ForegroundColor red -BackgroundColor yellow Write-host ":::::::::::::: !!! You are in development mode !!! ::::::::::::::" -ForegroundColor red -BackgroundColor yellow

8
docs/en/framework/architecture/best-practices/mongodb-integration.md

@ -114,7 +114,7 @@ public async Task<IdentityUser> FindByNormalizedUserNameAsync(
bool includeDetails = true, bool includeDetails = true,
CancellationToken cancellationToken = default) CancellationToken cancellationToken = default)
{ {
return await (await GetMongoQueryableAsync()) return await (await GetQueryableAsync())
.FirstOrDefaultAsync( .FirstOrDefaultAsync(
u => u.NormalizedUserName == normalizedUserName, u => u.NormalizedUserName == normalizedUserName,
GetCancellationToken(cancellationToken) GetCancellationToken(cancellationToken)
@ -125,10 +125,10 @@ public async Task<IdentityUser> FindByNormalizedUserNameAsync(
`GetCancellationToken` fallbacks to the `ICancellationTokenProvider.Token` to obtain the cancellation token if it is not provided by the caller code. `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** 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<TEntity>` to perform queries wherever possible. Because; * **Do** use the `GetQueryableAsync()` method to obtain an `IQueryable<TEntity>` 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). * `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<TEntity>` makes the code as much as similar to the EF Core repository implementation and easy to write and read. * Using `IQueryable<TEntity>` 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 ## Module Class

13
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. * 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<T>`, but provides for `IMongoQueryable<T>`. You need to cast the query to `IMongoQueryable<T>` first to be able to use the async extension methods.
**Example: Cast `IQueryable<T>` to `IMongoQueryable<T>` and use `ToListAsync()`**
````csharp
var queryable = await _personRepository.GetQueryableAsync();
var people = ((IMongoQueryable<Person>) queryable
.Where(p => p.Name.Contains(nameFilter)))
.ToListAsync();
````
### Option-2: Use the IRepository Async Extension Methods ### Option-2: Use the IRepository Async Extension Methods
ABP provides async extension methods for the repositories, just similar to async LINQ extension methods. ABP provides async extension methods for the repositories, just similar to async LINQ extension methods.

8
docs/en/guides/microservice-mongodb.md

@ -97,9 +97,9 @@ Here we use `BookStore.ProductService` project as an example:
int skipCount = 0, int skipCount = 0,
CancellationToken cancellationToken = default) 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); query = query.OrderBy(string.IsNullOrWhiteSpace(sorting) ? ProductConsts.GetDefaultSorting(false) : sorting);
return await query.As<IMongoQueryable<Product>>().PageBy<Product, IMongoQueryable<Product>>(skipCount, maxResultCount).ToListAsync(cancellationToken); return await query.PageBy(skipCount, maxResultCount).ToListAsync(cancellationToken);
} }
public async Task<long> GetCountAsync( public async Task<long> GetCountAsync(
@ -109,8 +109,8 @@ Here we use `BookStore.ProductService` project as an example:
float? priceMax = null, float? priceMax = null,
CancellationToken cancellationToken = default) CancellationToken cancellationToken = default)
{ {
var query = ApplyFilter(await GetMongoQueryableAsync(cancellationToken), filterText, name, priceMin, priceMax); var query = ApplyFilter(await GetQueryableAsync(cancellationToken), filterText, name, priceMin, priceMax);
return await query.As<IMongoQueryable<Product>>().LongCountAsync(GetCancellationToken(cancellationToken)); return await query.LongCountAsync(GetCancellationToken(cancellationToken));
} }
protected virtual IQueryable<Product> ApplyFilter( protected virtual IQueryable<Product> ApplyFilter(

59
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<TEntity>`.
- The `GetMongoQueryable` and `GetMongoQueryableAsync` methods return `IQueryable<TEntity>` instead of `IMongoQueryable<TEntity>`,
- 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<TEntity>`, 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<IMongoQueryable<MyEntity>>().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
<PackageReference Include="EphemeralMongo.Core" Version="1.1.3" />
<PackageReference Include="EphemeralMongo6.runtime.linux-x64" Version="1.1.3" Condition="$([MSBuild]::IsOSPlatform('Linux'))" />
<PackageReference Include="EphemeralMongo6.runtime.osx-x64" Version="1.1.3" Condition="$([MSBuild]::IsOSPlatform('OSX'))" />
<PackageReference Include="EphemeralMongo6.runtime.win-x64" Version="1.1.3" Condition="$([MSBuild]::IsOSPlatform('Windows'))" />
```
With:
```xml
<PackageReference Include="MongoSandbox.Core" Version="1.0.1" />
<PackageReference Include="MongoSandbox6.runtime.linux-x64" Version="1.0.1" Condition="$([MSBuild]::IsOSPlatform('Linux'))" />
<PackageReference Include="MongoSandbox6.runtime.osx-x64" Version="1.0.1" Condition="$([MSBuild]::IsOSPlatform('OSX'))" />
<PackageReference Include="MongoSandbox6.runtime.win-x64" Version="1.0.1" Condition="$([MSBuild]::IsOSPlatform('Windows'))" />
```
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.

7
docs/en/tutorials/book-store/part-07.md

@ -180,7 +180,7 @@ public class MongoDbAuthorRepository
public async Task<Author> FindByNameAsync(string name) public async Task<Author> FindByNameAsync(string name)
{ {
var queryable = await GetMongoQueryableAsync(); var queryable = await GetQueryableAsync();
return await queryable.FirstOrDefaultAsync(author => author.Name == name); return await queryable.FirstOrDefaultAsync(author => author.Name == name);
} }
@ -190,14 +190,13 @@ public class MongoDbAuthorRepository
string sorting, string sorting,
string filter = null) string filter = null)
{ {
var queryable = await GetMongoQueryableAsync(); var queryable = await GetQueryableAsync();
return await queryable return await queryable
.WhereIf<Author, IMongoQueryable<Author>>( .WhereIf<Author, IQueryable<Author>>(
!filter.IsNullOrWhiteSpace(), !filter.IsNullOrWhiteSpace(),
author => author.Name.Contains(filter) author => author.Name.Contains(filter)
) )
.OrderBy(sorting) .OrderBy(sorting)
.As<IMongoQueryable<Author>>()
.Skip(skipCount) .Skip(skipCount)
.Take(maxResultCount) .Take(maxResultCount)
.ToListAsync(); .ToListAsync();

11
framework/src/Volo.Abp.MongoDB/Volo/Abp/Domain/Repositories/MongoDB/IMongoDbRepository.cs

@ -1,8 +1,8 @@
using System; using System;
using System.Linq;
using System.Threading; using System.Threading;
using System.Threading.Tasks; using System.Threading.Tasks;
using MongoDB.Driver; using MongoDB.Driver;
using MongoDB.Driver.Linq;
using Volo.Abp.Domain.Entities; using Volo.Abp.Domain.Entities;
namespace Volo.Abp.Domain.Repositories.MongoDB; namespace Volo.Abp.Domain.Repositories.MongoDB;
@ -20,10 +20,13 @@ public interface IMongoDbRepository<TEntity> : IRepository<TEntity>
Task<IMongoCollection<TEntity>> GetCollectionAsync(CancellationToken cancellationToken = default); Task<IMongoCollection<TEntity>> GetCollectionAsync(CancellationToken cancellationToken = default);
[Obsolete("Use GetMongoQueryableAsync method.")] [Obsolete("Use GetQueryable method.")]
IMongoQueryable<TEntity> GetMongoQueryable(); IQueryable<TEntity> GetMongoQueryable();
Task<IMongoQueryable<TEntity>> GetMongoQueryableAsync(CancellationToken cancellationToken = default, AggregateOptions? options = null); [Obsolete("Use GetQueryableAsync method.")]
Task<IQueryable<TEntity>> GetMongoQueryableAsync(CancellationToken cancellationToken = default, AggregateOptions? options = null);
Task<IQueryable<TEntity>> GetQueryableAsync(CancellationToken cancellationToken = default, AggregateOptions? options = null);
Task<IAggregateFluent<TEntity>> GetAggregateAsync(CancellationToken cancellationToken = default, AggregateOptions? options = null); Task<IAggregateFluent<TEntity>> GetAggregateAsync(CancellationToken cancellationToken = default, AggregateOptions? options = null);
} }

53
framework/src/Volo.Abp.MongoDB/Volo/Abp/Domain/Repositories/MongoDB/MongoDbRepository.cs

@ -455,19 +455,19 @@ public class MongoDbRepository<TMongoDbContext, TEntity>
public async override Task<List<TEntity>> GetListAsync(bool includeDetails = false, CancellationToken cancellationToken = default) public async override Task<List<TEntity>> GetListAsync(bool includeDetails = false, CancellationToken cancellationToken = default)
{ {
cancellationToken = GetCancellationToken(cancellationToken); cancellationToken = GetCancellationToken(cancellationToken);
return await (await GetMongoQueryableAsync(cancellationToken)).ToListAsync(cancellationToken); return await (await GetQueryableAsync(cancellationToken)).ToListAsync(cancellationToken);
} }
public async override Task<List<TEntity>> GetListAsync(Expression<Func<TEntity, bool>> predicate, bool includeDetails = false, CancellationToken cancellationToken = default) public async override Task<List<TEntity>> GetListAsync(Expression<Func<TEntity, bool>> predicate, bool includeDetails = false, CancellationToken cancellationToken = default)
{ {
cancellationToken = GetCancellationToken(cancellationToken); 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<long> GetCountAsync(CancellationToken cancellationToken = default) public async override Task<long> GetCountAsync(CancellationToken cancellationToken = default)
{ {
cancellationToken = GetCancellationToken(cancellationToken); cancellationToken = GetCancellationToken(cancellationToken);
return await (await GetMongoQueryableAsync(cancellationToken)).LongCountAsync(cancellationToken); return await (await GetQueryableAsync(cancellationToken)).LongCountAsync(cancellationToken);
} }
public async override Task<List<TEntity>> GetPagedListAsync( public async override Task<List<TEntity>> GetPagedListAsync(
@ -479,10 +479,9 @@ public class MongoDbRepository<TMongoDbContext, TEntity>
{ {
cancellationToken = GetCancellationToken(cancellationToken); cancellationToken = GetCancellationToken(cancellationToken);
return await (await GetMongoQueryableAsync(cancellationToken)) return await (await GetQueryableAsync(cancellationToken))
.OrderByIf<TEntity, IQueryable<TEntity>>(!sorting.IsNullOrWhiteSpace(), sorting) .OrderByIf<TEntity, IQueryable<TEntity>>(!sorting.IsNullOrWhiteSpace(), sorting)
.As<IMongoQueryable<TEntity>>() .PageBy<TEntity, IQueryable<TEntity>>(skipCount, maxResultCount)
.PageBy<TEntity, IMongoQueryable<TEntity>>(skipCount, maxResultCount)
.ToListAsync(cancellationToken); .ToListAsync(cancellationToken);
} }
@ -493,14 +492,14 @@ public class MongoDbRepository<TMongoDbContext, TEntity>
{ {
cancellationToken = GetCancellationToken(cancellationToken); cancellationToken = GetCancellationToken(cancellationToken);
var entities = await (await GetMongoQueryableAsync(cancellationToken)) var entities = await (await GetQueryableAsync(cancellationToken))
.Where(predicate) .Where(predicate)
.ToListAsync(cancellationToken); .ToListAsync(cancellationToken);
await DeleteManyAsync(entities, autoSave, cancellationToken); await DeleteManyAsync(entities, autoSave, cancellationToken);
} }
public override async Task DeleteDirectAsync(Expression<Func<TEntity, bool>> predicate, CancellationToken cancellationToken = default) public async override Task DeleteDirectAsync(Expression<Func<TEntity, bool>> predicate, CancellationToken cancellationToken = default)
{ {
cancellationToken = GetCancellationToken(cancellationToken); cancellationToken = GetCancellationToken(cancellationToken);
@ -527,12 +526,16 @@ public class MongoDbRepository<TMongoDbContext, TEntity>
[Obsolete("Use GetQueryableAsync method.")] [Obsolete("Use GetQueryableAsync method.")]
protected override IQueryable<TEntity> GetQueryable() protected override IQueryable<TEntity> GetQueryable()
{ {
return GetMongoQueryable(); return ApplyDataFilters(
SessionHandle != null
? Collection.AsQueryable(SessionHandle)
: Collection.AsQueryable()
);
} }
public async override Task<IQueryable<TEntity>> GetQueryableAsync() public async override Task<IQueryable<TEntity>> GetQueryableAsync()
{ {
return await GetMongoQueryableAsync(); return await GetQueryableAsync();
} }
public async override Task<TEntity?> FindAsync( public async override Task<TEntity?> FindAsync(
@ -542,34 +545,36 @@ public class MongoDbRepository<TMongoDbContext, TEntity>
{ {
cancellationToken = GetCancellationToken(cancellationToken); cancellationToken = GetCancellationToken(cancellationToken);
return await (await GetMongoQueryableAsync(cancellationToken)) return await (await GetQueryableAsync(cancellationToken))
.Where(predicate) .Where(predicate)
.SingleOrDefaultAsync(cancellationToken); .SingleOrDefaultAsync(cancellationToken);
} }
[Obsolete("Use GetMongoQueryableAsync method.")] [Obsolete("Use GetQueryableAsync method.")]
public virtual IMongoQueryable<TEntity> GetMongoQueryable() public virtual IQueryable<TEntity> GetMongoQueryable()
{ {
return ApplyDataFilters( return GetQueryable();
SessionHandle != null }
? Collection.AsQueryable(SessionHandle)
: Collection.AsQueryable() [Obsolete("Use GetQueryableAsync method.")]
); public virtual Task<IQueryable<TEntity>> GetMongoQueryableAsync(CancellationToken cancellationToken = default, AggregateOptions? options = null)
{
return GetQueryableAsync<TEntity>(cancellationToken, options);
} }
public virtual Task<IMongoQueryable<TEntity>> GetMongoQueryableAsync(CancellationToken cancellationToken = default, AggregateOptions? aggregateOptions = null) public virtual async Task<IQueryable<TEntity>> GetQueryableAsync(CancellationToken cancellationToken = default, AggregateOptions? options = null)
{ {
return GetMongoQueryableAsync<TEntity>(cancellationToken, aggregateOptions); return await GetQueryableAsync<TEntity>(cancellationToken, options);
} }
protected virtual async Task<IMongoQueryable<TOtherEntity>> GetMongoQueryableAsync<TOtherEntity>(CancellationToken cancellationToken = default, AggregateOptions? aggregateOptions = null) protected virtual async Task<IQueryable<TOtherEntity>> GetQueryableAsync<TOtherEntity>(CancellationToken cancellationToken = default, AggregateOptions? aggregateOptions = null)
{ {
cancellationToken = GetCancellationToken(cancellationToken); cancellationToken = GetCancellationToken(cancellationToken);
var dbContext = await GetDbContextAsync(cancellationToken); var dbContext = await GetDbContextAsync(cancellationToken);
var collection = dbContext.Collection<TOtherEntity>(); var collection = dbContext.Collection<TOtherEntity>();
return ApplyDataFilters<IMongoQueryable<TOtherEntity>, TOtherEntity>( return ApplyDataFilters<IQueryable<TOtherEntity>, TOtherEntity>(
dbContext.SessionHandle != null dbContext.SessionHandle != null
? collection.AsQueryable(dbContext.SessionHandle, aggregateOptions) ? collection.AsQueryable(dbContext.SessionHandle, aggregateOptions)
: collection.AsQueryable(aggregateOptions) : collection.AsQueryable(aggregateOptions)
@ -810,7 +815,7 @@ public class MongoDbRepository<TMongoDbContext, TEntity, TKey>
{ {
cancellationToken = GetCancellationToken(cancellationToken); cancellationToken = GetCancellationToken(cancellationToken);
return await (await GetMongoQueryableAsync(cancellationToken)) return await (await GetQueryableAsync(cancellationToken))
.Where(x => x.Id!.Equals(id)) .Where(x => x.Id!.Equals(id))
.FirstOrDefaultAsync(cancellationToken); .FirstOrDefaultAsync(cancellationToken);
} }
@ -827,7 +832,7 @@ public class MongoDbRepository<TMongoDbContext, TEntity, TKey>
{ {
cancellationToken = GetCancellationToken(cancellationToken); cancellationToken = GetCancellationToken(cancellationToken);
var entities = await (await GetMongoQueryableAsync(cancellationToken)) var entities = await (await GetQueryableAsync(cancellationToken))
.Where(x => ids.Contains(x.Id)) .Where(x => ids.Contains(x.Id))
.ToListAsync(cancellationToken); .ToListAsync(cancellationToken);

15
framework/src/Volo.Abp.MongoDB/Volo/Abp/Domain/Repositories/MongoDbCoreRepositoryExtensions.cs

@ -1,8 +1,8 @@
using System; using System;
using System.Linq;
using System.Threading; using System.Threading;
using System.Threading.Tasks; using System.Threading.Tasks;
using MongoDB.Driver; using MongoDB.Driver;
using MongoDB.Driver.Linq;
using Volo.Abp.Domain.Entities; using Volo.Abp.Domain.Entities;
using Volo.Abp.Domain.Repositories.MongoDB; using Volo.Abp.Domain.Repositories.MongoDB;
@ -36,19 +36,26 @@ public static class MongoDbCoreRepositoryExtensions
return repository.ToMongoDbRepository().GetCollectionAsync(cancellationToken); return repository.ToMongoDbRepository().GetCollectionAsync(cancellationToken);
} }
[Obsolete("Use GetMongoQueryableAsync method.")] [Obsolete("Use GetQueryableAsync method.")]
public static IMongoQueryable<TEntity> GetMongoQueryable<TEntity>(this IReadOnlyBasicRepository<TEntity> repository) public static IQueryable<TEntity> GetMongoQueryable<TEntity>(this IReadOnlyBasicRepository<TEntity> repository)
where TEntity : class, IEntity where TEntity : class, IEntity
{ {
return repository.ToMongoDbRepository().GetMongoQueryable(); return repository.ToMongoDbRepository().GetMongoQueryable();
} }
public static Task<IMongoQueryable<TEntity>> GetMongoQueryableAsync<TEntity>(this IReadOnlyBasicRepository<TEntity> repository, CancellationToken cancellationToken = default, AggregateOptions? aggregateOptions = null) [Obsolete("Use GetQueryableAsync method.")]
public static Task<IQueryable<TEntity>> GetMongoQueryableAsync<TEntity>(this IReadOnlyBasicRepository<TEntity> repository, CancellationToken cancellationToken = default, AggregateOptions? aggregateOptions = null)
where TEntity : class, IEntity where TEntity : class, IEntity
{ {
return repository.ToMongoDbRepository().GetMongoQueryableAsync(cancellationToken, aggregateOptions); return repository.ToMongoDbRepository().GetMongoQueryableAsync(cancellationToken, aggregateOptions);
} }
public static Task<IQueryable<TEntity>> GetQueryableAsync<TEntity>(this IReadOnlyBasicRepository<TEntity> repository)
where TEntity : class, IEntity
{
return repository.ToMongoDbRepository().GetQueryableAsync();
}
public static Task<IAggregateFluent<TEntity>> GetAggregateAsync<TEntity>(this IReadOnlyBasicRepository<TEntity> repository, CancellationToken cancellationToken = default, AggregateOptions? aggregateOptions = null) public static Task<IAggregateFluent<TEntity>> GetAggregateAsync<TEntity>(this IReadOnlyBasicRepository<TEntity> repository, CancellationToken cancellationToken = default, AggregateOptions? aggregateOptions = null)
where TEntity : class, IEntity where TEntity : class, IEntity
{ {

2
framework/src/Volo.Abp.MongoDB/Volo/Abp/MongoDB/AbpMongoDbDateTimeSerializer.cs

@ -5,7 +5,7 @@ using MongoDB.Bson.Serialization.Serializers;
namespace Volo.Abp.MongoDB; namespace Volo.Abp.MongoDB;
public class AbpMongoDbDateTimeSerializer : DateTimeSerializer public class AbpMongoDbDateTimeSerializer : StructSerializerBase<DateTime>
{ {
protected DateTimeKind DateTimeKind { get; set; } protected DateTimeKind DateTimeKind { get; set; }
protected bool DisableDateTimeNormalization { get; set; } protected bool DisableDateTimeNormalization { get; set; }

5
framework/src/Volo.Abp.MongoDB/Volo/Abp/MongoDB/AbpMongoDbModule.cs

@ -1,5 +1,8 @@
using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.DependencyInjection.Extensions; 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;
using Volo.Abp.Domain.Repositories.MongoDB; using Volo.Abp.Domain.Repositories.MongoDB;
using Volo.Abp.Modularity; using Volo.Abp.Modularity;
@ -19,6 +22,8 @@ public class AbpMongoDbModule : AbpModule
public override void ConfigureServices(ServiceConfigurationContext context) public override void ConfigureServices(ServiceConfigurationContext context)
{ {
BsonSerializer.TryRegisterSerializer(new GuidSerializer(GuidRepresentation.Standard));
context.Services.TryAddTransient( context.Services.TryAddTransient(
typeof(IMongoDbContextProvider<>), typeof(IMongoDbContextProvider<>),
typeof(UnitOfWorkMongoDbContextProvider<>) typeof(UnitOfWorkMongoDbContextProvider<>)

1
framework/src/Volo.Abp.MongoDB/Volo/Abp/MongoDB/DistributedEvents/MongoDbContextEventInbox.cs

@ -68,7 +68,6 @@ public class MongoDbContextEventInbox<TMongoDbContext> : IMongoDbContextEventInb
.WhereIf(transformedFilter != null, transformedFilter!) .WhereIf(transformedFilter != null, transformedFilter!)
.OrderBy(x => x.CreationTime) .OrderBy(x => x.CreationTime)
.Take(maxCount) .Take(maxCount)
.As<IMongoQueryable<IncomingEventRecord>>()
.ToListAsync(cancellationToken: cancellationToken); .ToListAsync(cancellationToken: cancellationToken);
return outgoingEventRecords return outgoingEventRecords

1
framework/src/Volo.Abp.MongoDB/Volo/Abp/MongoDB/DistributedEvents/MongoDbContextEventOutbox.cs

@ -56,7 +56,6 @@ public class MongoDbContextEventOutbox<TMongoDbContext> : IMongoDbContextEventOu
.WhereIf(transformedFilter != null, transformedFilter!) .WhereIf(transformedFilter != null, transformedFilter!)
.OrderBy(x => x.CreationTime) .OrderBy(x => x.CreationTime)
.Take(maxCount) .Take(maxCount)
.As<IMongoQueryable<OutgoingEventRecord>>()
.ToListAsync(cancellationToken: cancellationToken); .ToListAsync(cancellationToken: cancellationToken);
return outgoingEventRecords return outgoingEventRecords

141
framework/src/Volo.Abp.MongoDB/Volo/Abp/MongoDB/MongoDbAsyncQueryableProvider.cs

@ -6,9 +6,7 @@ using System.Threading;
using System.Threading.Tasks; using System.Threading.Tasks;
using Volo.Abp.DependencyInjection; using Volo.Abp.DependencyInjection;
using Volo.Abp.Linq; using Volo.Abp.Linq;
using MongoDB.Driver;
using MongoDB.Driver.Linq; using MongoDB.Driver.Linq;
using Volo.Abp.DynamicProxy;
namespace Volo.Abp.MongoDB; namespace Volo.Abp.MongoDB;
@ -16,344 +14,339 @@ public class MongoDbAsyncQueryableProvider : IAsyncQueryableProvider, ISingleton
{ {
public bool CanExecute<T>(IQueryable<T> queryable) public bool CanExecute<T>(IQueryable<T> queryable)
{ {
return ProxyHelper.UnProxy(queryable) is IMongoQueryable<T>; return queryable.Provider is IMongoQueryProvider;
}
protected virtual IMongoQueryable<T> GetMongoQueryable<T>(IQueryable<T> queryable)
{
return ProxyHelper.UnProxy(queryable).As<IMongoQueryable<T>>();
} }
public Task<bool> ContainsAsync<T>(IQueryable<T> queryable, T item, CancellationToken cancellationToken = default) public Task<bool> ContainsAsync<T>(IQueryable<T> queryable, T item, CancellationToken cancellationToken = default)
{ {
return Task.FromResult(GetMongoQueryable(queryable).Contains(item)); return Task.FromResult(queryable.Contains(item));
} }
public Task<bool> AnyAsync<T>(IQueryable<T> queryable, CancellationToken cancellationToken = default) public Task<bool> AnyAsync<T>(IQueryable<T> queryable, CancellationToken cancellationToken = default)
{ {
return GetMongoQueryable(queryable).AnyAsync(cancellationToken); return queryable.AnyAsync(cancellationToken);
} }
public Task<bool> AnyAsync<T>(IQueryable<T> queryable, Expression<Func<T, bool>> predicate, CancellationToken cancellationToken = default) public Task<bool> AnyAsync<T>(IQueryable<T> queryable, Expression<Func<T, bool>> predicate, CancellationToken cancellationToken = default)
{ {
return GetMongoQueryable(queryable).AnyAsync(predicate, cancellationToken); return queryable.AnyAsync(predicate, cancellationToken);
} }
public Task<bool> AllAsync<T>(IQueryable<T> queryable, Expression<Func<T, bool>> predicate, CancellationToken cancellationToken = default) public Task<bool> AllAsync<T>(IQueryable<T> queryable, Expression<Func<T, bool>> predicate, CancellationToken cancellationToken = default)
{ {
return Task.FromResult(GetMongoQueryable(queryable).All(predicate)); return Task.FromResult(queryable.All(predicate));
} }
public Task<int> CountAsync<T>(IQueryable<T> queryable, CancellationToken cancellationToken = default) public Task<int> CountAsync<T>(IQueryable<T> queryable, CancellationToken cancellationToken = default)
{ {
return GetMongoQueryable(queryable).CountAsync(cancellationToken); return queryable.CountAsync(cancellationToken);
} }
public Task<int> CountAsync<T>(IQueryable<T> queryable, Expression<Func<T, bool>> predicate, CancellationToken cancellationToken = default) public Task<int> CountAsync<T>(IQueryable<T> queryable, Expression<Func<T, bool>> predicate, CancellationToken cancellationToken = default)
{ {
return GetMongoQueryable(queryable).CountAsync(predicate, cancellationToken); return queryable.CountAsync(predicate, cancellationToken);
} }
public Task<long> LongCountAsync<T>(IQueryable<T> queryable, CancellationToken cancellationToken = default) public Task<long> LongCountAsync<T>(IQueryable<T> queryable, CancellationToken cancellationToken = default)
{ {
return GetMongoQueryable(queryable).LongCountAsync(cancellationToken); return queryable.LongCountAsync(cancellationToken);
} }
public Task<long> LongCountAsync<T>(IQueryable<T> queryable, Expression<Func<T, bool>> predicate, CancellationToken cancellationToken = default) public Task<long> LongCountAsync<T>(IQueryable<T> queryable, Expression<Func<T, bool>> predicate, CancellationToken cancellationToken = default)
{ {
return GetMongoQueryable(queryable).LongCountAsync(predicate, cancellationToken); return queryable.LongCountAsync(predicate, cancellationToken);
} }
public Task<T> FirstAsync<T>(IQueryable<T> queryable, CancellationToken cancellationToken = default) public Task<T> FirstAsync<T>(IQueryable<T> queryable, CancellationToken cancellationToken = default)
{ {
return GetMongoQueryable(queryable).FirstAsync(cancellationToken); return queryable.FirstAsync(cancellationToken);
} }
public Task<T> FirstAsync<T>(IQueryable<T> queryable, Expression<Func<T, bool>> predicate, CancellationToken cancellationToken = default) public Task<T> FirstAsync<T>(IQueryable<T> queryable, Expression<Func<T, bool>> predicate, CancellationToken cancellationToken = default)
{ {
return GetMongoQueryable(queryable).FirstAsync(predicate, cancellationToken); return queryable.FirstAsync(predicate, cancellationToken);
} }
public Task<T?> FirstOrDefaultAsync<T>(IQueryable<T> queryable, CancellationToken cancellationToken = default) public Task<T?> FirstOrDefaultAsync<T>(IQueryable<T> queryable, CancellationToken cancellationToken = default)
{ {
return GetMongoQueryable(queryable).FirstOrDefaultAsync(cancellationToken)!; return queryable.FirstOrDefaultAsync(cancellationToken)!;
} }
public Task<T?> FirstOrDefaultAsync<T>(IQueryable<T> queryable, Expression<Func<T, bool>> predicate, public Task<T?> FirstOrDefaultAsync<T>(IQueryable<T> queryable, Expression<Func<T, bool>> predicate,
CancellationToken cancellationToken = default) CancellationToken cancellationToken = default)
{ {
return GetMongoQueryable(queryable).FirstOrDefaultAsync(predicate, cancellationToken)!; return queryable.FirstOrDefaultAsync(predicate, cancellationToken)!;
} }
public Task<T> LastAsync<T>(IQueryable<T> queryable, CancellationToken cancellationToken = default) public Task<T> LastAsync<T>(IQueryable<T> queryable, CancellationToken cancellationToken = default)
{ {
return Task.FromResult(GetMongoQueryable(queryable).Last()); return Task.FromResult(queryable.Last());
} }
public Task<T> LastAsync<T>(IQueryable<T> queryable, Expression<Func<T, bool>> predicate, CancellationToken cancellationToken = default) public Task<T> LastAsync<T>(IQueryable<T> queryable, Expression<Func<T, bool>> predicate, CancellationToken cancellationToken = default)
{ {
return Task.FromResult(GetMongoQueryable(queryable).Last(predicate)); return Task.FromResult(queryable.Last(predicate));
} }
public Task<T?> LastOrDefaultAsync<T>(IQueryable<T> queryable, CancellationToken cancellationToken = default) public Task<T?> LastOrDefaultAsync<T>(IQueryable<T> queryable, CancellationToken cancellationToken = default)
{ {
return Task.FromResult<T?>(GetMongoQueryable(queryable).LastOrDefault()); return Task.FromResult<T?>(queryable.LastOrDefault());
} }
public Task<T?> LastOrDefaultAsync<T>(IQueryable<T> queryable, Expression<Func<T, bool>> predicate, public Task<T?> LastOrDefaultAsync<T>(IQueryable<T> queryable, Expression<Func<T, bool>> predicate,
CancellationToken cancellationToken = default) CancellationToken cancellationToken = default)
{ {
return Task.FromResult<T?>(GetMongoQueryable(queryable).LastOrDefault(predicate)); return Task.FromResult<T?>(queryable.LastOrDefault(predicate));
} }
public Task<T> SingleAsync<T>(IQueryable<T> queryable, CancellationToken cancellationToken = default) public Task<T> SingleAsync<T>(IQueryable<T> queryable, CancellationToken cancellationToken = default)
{ {
return GetMongoQueryable(queryable).SingleAsync(cancellationToken); return queryable.SingleAsync(cancellationToken);
} }
public Task<T> SingleAsync<T>(IQueryable<T> queryable, Expression<Func<T, bool>> predicate, CancellationToken cancellationToken = default) public Task<T> SingleAsync<T>(IQueryable<T> queryable, Expression<Func<T, bool>> predicate, CancellationToken cancellationToken = default)
{ {
return GetMongoQueryable(queryable).SingleAsync(predicate, cancellationToken); return queryable.SingleAsync(predicate, cancellationToken);
} }
public Task<T?> SingleOrDefaultAsync<T>(IQueryable<T> queryable, CancellationToken cancellationToken = default) public Task<T?> SingleOrDefaultAsync<T>(IQueryable<T> queryable, CancellationToken cancellationToken = default)
{ {
return GetMongoQueryable(queryable).SingleOrDefaultAsync(cancellationToken)!; return queryable.SingleOrDefaultAsync(cancellationToken)!;
} }
public Task<T?> SingleOrDefaultAsync<T>(IQueryable<T> queryable, Expression<Func<T, bool>> predicate, public Task<T?> SingleOrDefaultAsync<T>(IQueryable<T> queryable, Expression<Func<T, bool>> predicate,
CancellationToken cancellationToken = default) CancellationToken cancellationToken = default)
{ {
return GetMongoQueryable(queryable).SingleOrDefaultAsync(predicate, cancellationToken)!; return queryable.SingleOrDefaultAsync(predicate, cancellationToken)!;
} }
public Task<T> MinAsync<T>(IQueryable<T> queryable, CancellationToken cancellationToken = default) public Task<T> MinAsync<T>(IQueryable<T> queryable, CancellationToken cancellationToken = default)
{ {
return GetMongoQueryable(queryable).MinAsync(cancellationToken); return queryable.MinAsync(cancellationToken);
} }
public Task<TResult> MinAsync<T, TResult>(IQueryable<T> queryable, Expression<Func<T, TResult>> selector, CancellationToken cancellationToken = default) public Task<TResult> MinAsync<T, TResult>(IQueryable<T> queryable, Expression<Func<T, TResult>> selector, CancellationToken cancellationToken = default)
{ {
return GetMongoQueryable(queryable).MinAsync(selector, cancellationToken); return queryable.MinAsync(selector, cancellationToken);
} }
public Task<T> MaxAsync<T>(IQueryable<T> queryable, CancellationToken cancellationToken = default) public Task<T> MaxAsync<T>(IQueryable<T> queryable, CancellationToken cancellationToken = default)
{ {
return GetMongoQueryable(queryable).MaxAsync(cancellationToken); return queryable.MaxAsync(cancellationToken);
} }
public Task<TResult> MaxAsync<T, TResult>(IQueryable<T> queryable, Expression<Func<T, TResult>> selector, CancellationToken cancellationToken = default) public Task<TResult> MaxAsync<T, TResult>(IQueryable<T> queryable, Expression<Func<T, TResult>> selector, CancellationToken cancellationToken = default)
{ {
return GetMongoQueryable(queryable).MaxAsync(selector, cancellationToken); return queryable.MaxAsync(selector, cancellationToken);
} }
public Task<decimal> SumAsync(IQueryable<decimal> queryable, CancellationToken cancellationToken = default) public Task<decimal> SumAsync(IQueryable<decimal> queryable, CancellationToken cancellationToken = default)
{ {
return GetMongoQueryable(queryable).SumAsync(cancellationToken); return queryable.SumAsync(cancellationToken);
} }
public Task<decimal?> SumAsync(IQueryable<decimal?> queryable, CancellationToken cancellationToken = default) public Task<decimal?> SumAsync(IQueryable<decimal?> queryable, CancellationToken cancellationToken = default)
{ {
return GetMongoQueryable(queryable).SumAsync(cancellationToken); return queryable.SumAsync(cancellationToken);
} }
public Task<decimal> SumAsync<T>(IQueryable<T> queryable, Expression<Func<T, decimal>> selector, CancellationToken cancellationToken = default) public Task<decimal> SumAsync<T>(IQueryable<T> queryable, Expression<Func<T, decimal>> selector, CancellationToken cancellationToken = default)
{ {
return GetMongoQueryable(queryable).SumAsync(selector, cancellationToken); return queryable.SumAsync(selector, cancellationToken);
} }
public Task<decimal?> SumAsync<T>(IQueryable<T> queryable, Expression<Func<T, decimal?>> selector, CancellationToken cancellationToken = default) public Task<decimal?> SumAsync<T>(IQueryable<T> queryable, Expression<Func<T, decimal?>> selector, CancellationToken cancellationToken = default)
{ {
return GetMongoQueryable(queryable).SumAsync(selector, cancellationToken); return queryable.SumAsync(selector, cancellationToken);
} }
public Task<int> SumAsync(IQueryable<int> queryable, CancellationToken cancellationToken = default) public Task<int> SumAsync(IQueryable<int> queryable, CancellationToken cancellationToken = default)
{ {
return GetMongoQueryable(queryable).SumAsync(cancellationToken); return queryable.SumAsync(cancellationToken);
} }
public Task<int?> SumAsync(IQueryable<int?> queryable, CancellationToken cancellationToken = default) public Task<int?> SumAsync(IQueryable<int?> queryable, CancellationToken cancellationToken = default)
{ {
return GetMongoQueryable(queryable).SumAsync(cancellationToken); return queryable.SumAsync(cancellationToken);
} }
public Task<int> SumAsync<T>(IQueryable<T> queryable, Expression<Func<T, int>> selector, CancellationToken cancellationToken = default) public Task<int> SumAsync<T>(IQueryable<T> queryable, Expression<Func<T, int>> selector, CancellationToken cancellationToken = default)
{ {
return GetMongoQueryable(queryable).SumAsync(selector, cancellationToken); return queryable.SumAsync(selector, cancellationToken);
} }
public Task<int?> SumAsync<T>(IQueryable<T> queryable, Expression<Func<T, int?>> selector, CancellationToken cancellationToken = default) public Task<int?> SumAsync<T>(IQueryable<T> queryable, Expression<Func<T, int?>> selector, CancellationToken cancellationToken = default)
{ {
return GetMongoQueryable(queryable).SumAsync(selector, cancellationToken); return queryable.SumAsync(selector, cancellationToken);
} }
public Task<long> SumAsync(IQueryable<long> queryable, CancellationToken cancellationToken = default) public Task<long> SumAsync(IQueryable<long> queryable, CancellationToken cancellationToken = default)
{ {
return GetMongoQueryable(queryable).SumAsync(cancellationToken); return queryable.SumAsync(cancellationToken);
} }
public Task<long?> SumAsync(IQueryable<long?> queryable, CancellationToken cancellationToken = default) public Task<long?> SumAsync(IQueryable<long?> queryable, CancellationToken cancellationToken = default)
{ {
return GetMongoQueryable(queryable).SumAsync(cancellationToken); return queryable.SumAsync(cancellationToken);
} }
public Task<long> SumAsync<T>(IQueryable<T> queryable, Expression<Func<T, long>> selector, CancellationToken cancellationToken = default) public Task<long> SumAsync<T>(IQueryable<T> queryable, Expression<Func<T, long>> selector, CancellationToken cancellationToken = default)
{ {
return GetMongoQueryable(queryable).SumAsync(selector, cancellationToken); return queryable.SumAsync(selector, cancellationToken);
} }
public Task<long?> SumAsync<T>(IQueryable<T> queryable, Expression<Func<T, long?>> selector, CancellationToken cancellationToken = default) public Task<long?> SumAsync<T>(IQueryable<T> queryable, Expression<Func<T, long?>> selector, CancellationToken cancellationToken = default)
{ {
return GetMongoQueryable(queryable).SumAsync(selector, cancellationToken); return queryable.SumAsync(selector, cancellationToken);
} }
public Task<double> SumAsync(IQueryable<double> queryable, CancellationToken cancellationToken = default) public Task<double> SumAsync(IQueryable<double> queryable, CancellationToken cancellationToken = default)
{ {
return GetMongoQueryable(queryable).SumAsync(cancellationToken); return queryable.SumAsync(cancellationToken);
} }
public Task<double?> SumAsync(IQueryable<double?> queryable, CancellationToken cancellationToken = default) public Task<double?> SumAsync(IQueryable<double?> queryable, CancellationToken cancellationToken = default)
{ {
return GetMongoQueryable(queryable).SumAsync(cancellationToken); return queryable.SumAsync(cancellationToken);
} }
public Task<double> SumAsync<T>(IQueryable<T> queryable, Expression<Func<T, double>> selector, CancellationToken cancellationToken = default) public Task<double> SumAsync<T>(IQueryable<T> queryable, Expression<Func<T, double>> selector, CancellationToken cancellationToken = default)
{ {
return GetMongoQueryable(queryable).SumAsync(selector, cancellationToken); return queryable.SumAsync(selector, cancellationToken);
} }
public Task<double?> SumAsync<T>(IQueryable<T> queryable, Expression<Func<T, double?>> selector, CancellationToken cancellationToken = default) public Task<double?> SumAsync<T>(IQueryable<T> queryable, Expression<Func<T, double?>> selector, CancellationToken cancellationToken = default)
{ {
return GetMongoQueryable(queryable).SumAsync(selector, cancellationToken); return queryable.SumAsync(selector, cancellationToken);
} }
public Task<float> SumAsync(IQueryable<float> queryable, CancellationToken cancellationToken = default) public Task<float> SumAsync(IQueryable<float> queryable, CancellationToken cancellationToken = default)
{ {
return GetMongoQueryable(queryable).SumAsync(cancellationToken); return queryable.SumAsync(cancellationToken);
} }
public Task<float?> SumAsync(IQueryable<float?> queryable, CancellationToken cancellationToken = default) public Task<float?> SumAsync(IQueryable<float?> queryable, CancellationToken cancellationToken = default)
{ {
return GetMongoQueryable(queryable).SumAsync(cancellationToken); return queryable.SumAsync(cancellationToken);
} }
public Task<float> SumAsync<T>(IQueryable<T> queryable, Expression<Func<T, float>> selector, CancellationToken cancellationToken = default) public Task<float> SumAsync<T>(IQueryable<T> queryable, Expression<Func<T, float>> selector, CancellationToken cancellationToken = default)
{ {
return GetMongoQueryable(queryable).SumAsync(selector, cancellationToken); return queryable.SumAsync(selector, cancellationToken);
} }
public Task<float?> SumAsync<T>(IQueryable<T> queryable, Expression<Func<T, float?>> selector, CancellationToken cancellationToken = default) public Task<float?> SumAsync<T>(IQueryable<T> queryable, Expression<Func<T, float?>> selector, CancellationToken cancellationToken = default)
{ {
return GetMongoQueryable(queryable).SumAsync(selector, cancellationToken); return queryable.SumAsync(selector, cancellationToken);
} }
public Task<decimal> AverageAsync(IQueryable<decimal> queryable, CancellationToken cancellationToken = default) public Task<decimal> AverageAsync(IQueryable<decimal> queryable, CancellationToken cancellationToken = default)
{ {
return GetMongoQueryable(queryable).AverageAsync(cancellationToken); return queryable.AverageAsync(cancellationToken);
} }
public Task<decimal?> AverageAsync(IQueryable<decimal?> queryable, CancellationToken cancellationToken = default) public Task<decimal?> AverageAsync(IQueryable<decimal?> queryable, CancellationToken cancellationToken = default)
{ {
return GetMongoQueryable(queryable).AverageAsync(cancellationToken); return queryable.AverageAsync(cancellationToken);
} }
public Task<decimal> AverageAsync<T>(IQueryable<T> queryable, Expression<Func<T, decimal>> selector, CancellationToken cancellationToken = default) public Task<decimal> AverageAsync<T>(IQueryable<T> queryable, Expression<Func<T, decimal>> selector, CancellationToken cancellationToken = default)
{ {
return GetMongoQueryable(queryable).AverageAsync(selector, cancellationToken); return queryable.AverageAsync(selector, cancellationToken);
} }
public Task<decimal?> AverageAsync<T>(IQueryable<T> queryable, Expression<Func<T, decimal?>> selector, CancellationToken cancellationToken = default) public Task<decimal?> AverageAsync<T>(IQueryable<T> queryable, Expression<Func<T, decimal?>> selector, CancellationToken cancellationToken = default)
{ {
return GetMongoQueryable(queryable).AverageAsync(selector, cancellationToken); return queryable.AverageAsync(selector, cancellationToken);
} }
public Task<double> AverageAsync(IQueryable<int> queryable, CancellationToken cancellationToken = default) public Task<double> AverageAsync(IQueryable<int> queryable, CancellationToken cancellationToken = default)
{ {
return GetMongoQueryable(queryable).AverageAsync(cancellationToken); return queryable.AverageAsync(cancellationToken);
} }
public Task<double?> AverageAsync(IQueryable<int?> queryable, CancellationToken cancellationToken = default) public Task<double?> AverageAsync(IQueryable<int?> queryable, CancellationToken cancellationToken = default)
{ {
return GetMongoQueryable(queryable).AverageAsync(cancellationToken); return queryable.AverageAsync(cancellationToken);
} }
public Task<double> AverageAsync<T>(IQueryable<T> queryable, Expression<Func<T, int>> selector, CancellationToken cancellationToken = default) public Task<double> AverageAsync<T>(IQueryable<T> queryable, Expression<Func<T, int>> selector, CancellationToken cancellationToken = default)
{ {
return GetMongoQueryable(queryable).AverageAsync(selector, cancellationToken); return queryable.AverageAsync(selector, cancellationToken);
} }
public Task<double?> AverageAsync<T>(IQueryable<T> queryable, Expression<Func<T, int?>> selector, CancellationToken cancellationToken = default) public Task<double?> AverageAsync<T>(IQueryable<T> queryable, Expression<Func<T, int?>> selector, CancellationToken cancellationToken = default)
{ {
return GetMongoQueryable(queryable).AverageAsync(selector, cancellationToken); return queryable.AverageAsync(selector, cancellationToken);
} }
public Task<double> AverageAsync(IQueryable<long> queryable, CancellationToken cancellationToken = default) public Task<double> AverageAsync(IQueryable<long> queryable, CancellationToken cancellationToken = default)
{ {
return GetMongoQueryable(queryable).AverageAsync(cancellationToken); return queryable.AverageAsync(cancellationToken);
} }
public Task<double?> AverageAsync(IQueryable<long?> queryable, CancellationToken cancellationToken = default) public Task<double?> AverageAsync(IQueryable<long?> queryable, CancellationToken cancellationToken = default)
{ {
return GetMongoQueryable(queryable).AverageAsync(cancellationToken); return queryable.AverageAsync(cancellationToken);
} }
public Task<double> AverageAsync<T>(IQueryable<T> queryable, Expression<Func<T, long>> selector, CancellationToken cancellationToken = default) public Task<double> AverageAsync<T>(IQueryable<T> queryable, Expression<Func<T, long>> selector, CancellationToken cancellationToken = default)
{ {
return GetMongoQueryable(queryable).AverageAsync(selector, cancellationToken); return queryable.AverageAsync(selector, cancellationToken);
} }
public Task<double?> AverageAsync<T>(IQueryable<T> queryable, Expression<Func<T, long?>> selector, CancellationToken cancellationToken = default) public Task<double?> AverageAsync<T>(IQueryable<T> queryable, Expression<Func<T, long?>> selector, CancellationToken cancellationToken = default)
{ {
return GetMongoQueryable(queryable).AverageAsync(selector, cancellationToken); return queryable.AverageAsync(selector, cancellationToken);
} }
public Task<double> AverageAsync(IQueryable<double> queryable, CancellationToken cancellationToken = default) public Task<double> AverageAsync(IQueryable<double> queryable, CancellationToken cancellationToken = default)
{ {
return GetMongoQueryable(queryable).AverageAsync(cancellationToken); return queryable.AverageAsync(cancellationToken);
} }
public Task<double?> AverageAsync(IQueryable<double?> queryable, CancellationToken cancellationToken = default) public Task<double?> AverageAsync(IQueryable<double?> queryable, CancellationToken cancellationToken = default)
{ {
return GetMongoQueryable(queryable).AverageAsync(cancellationToken); return queryable.AverageAsync(cancellationToken);
} }
public Task<double> AverageAsync<T>(IQueryable<T> queryable, Expression<Func<T, double>> selector, CancellationToken cancellationToken = default) public Task<double> AverageAsync<T>(IQueryable<T> queryable, Expression<Func<T, double>> selector, CancellationToken cancellationToken = default)
{ {
return GetMongoQueryable(queryable).AverageAsync(selector, cancellationToken); return queryable.AverageAsync(selector, cancellationToken);
} }
public Task<double?> AverageAsync<T>(IQueryable<T> queryable, Expression<Func<T, double?>> selector, CancellationToken cancellationToken = default) public Task<double?> AverageAsync<T>(IQueryable<T> queryable, Expression<Func<T, double?>> selector, CancellationToken cancellationToken = default)
{ {
return GetMongoQueryable(queryable).AverageAsync(selector, cancellationToken); return queryable.AverageAsync(selector, cancellationToken);
} }
public Task<float> AverageAsync(IQueryable<float> queryable, CancellationToken cancellationToken = default) public Task<float> AverageAsync(IQueryable<float> queryable, CancellationToken cancellationToken = default)
{ {
return GetMongoQueryable(queryable).AverageAsync(cancellationToken); return queryable.AverageAsync(cancellationToken);
} }
public Task<float?> AverageAsync(IQueryable<float?> queryable, CancellationToken cancellationToken = default) public Task<float?> AverageAsync(IQueryable<float?> queryable, CancellationToken cancellationToken = default)
{ {
return GetMongoQueryable(queryable).AverageAsync(cancellationToken); return queryable.AverageAsync(cancellationToken);
} }
public Task<float> AverageAsync<T>(IQueryable<T> queryable, Expression<Func<T, float>> selector, CancellationToken cancellationToken = default) public Task<float> AverageAsync<T>(IQueryable<T> queryable, Expression<Func<T, float>> selector, CancellationToken cancellationToken = default)
{ {
return GetMongoQueryable(queryable).AverageAsync(selector, cancellationToken); return queryable.AverageAsync(selector, cancellationToken);
} }
public Task<float?> AverageAsync<T>(IQueryable<T> queryable, Expression<Func<T, float?>> selector, CancellationToken cancellationToken = default) public Task<float?> AverageAsync<T>(IQueryable<T> queryable, Expression<Func<T, float?>> selector, CancellationToken cancellationToken = default)
{ {
return GetMongoQueryable(queryable).AverageAsync(selector, cancellationToken); return queryable.AverageAsync(selector, cancellationToken);
} }
public Task<List<T>> ToListAsync<T>(IQueryable<T> queryable, CancellationToken cancellationToken = default) public Task<List<T>> ToListAsync<T>(IQueryable<T> queryable, CancellationToken cancellationToken = default)
{ {
return GetMongoQueryable(queryable).ToListAsync(cancellationToken); return queryable.ToListAsync(cancellationToken);
} }
public async Task<T[]> ToArrayAsync<T>(IQueryable<T> queryable, CancellationToken cancellationToken = default) public async Task<T[]> ToArrayAsync<T>(IQueryable<T> queryable, CancellationToken cancellationToken = default)
{ {
return (await GetMongoQueryable(queryable).ToListAsync(cancellationToken)).ToArray(); return (await queryable.ToListAsync(cancellationToken)).ToArray();
} }
} }

8
framework/test/Volo.Abp.MongoDB.Tests/Volo.Abp.MongoDB.Tests.csproj

@ -15,10 +15,10 @@
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<PackageReference Include="EphemeralMongo.Core" /> <PackageReference Include="MongoSandbox.Core" />
<PackageReference Include="EphemeralMongo6.runtime.linux-x64" Condition="$([MSBuild]::IsOSPlatform('Linux'))" /> <PackageReference Include="MongoSandbox6.runtime.linux-x64" Condition="$([MSBuild]::IsOSPlatform('Linux'))" />
<PackageReference Include="EphemeralMongo6.runtime.osx-x64" Condition="$([MSBuild]::IsOSPlatform('OSX'))" /> <PackageReference Include="MongoSandbox6.runtime.osx-x64" Condition="$([MSBuild]::IsOSPlatform('OSX'))" />
<PackageReference Include="EphemeralMongo6.runtime.win-x64" Condition="$([MSBuild]::IsOSPlatform('Windows'))" /> <PackageReference Include="MongoSandbox6.runtime.win-x64" Condition="$([MSBuild]::IsOSPlatform('Windows'))" />
<PackageReference Include="Microsoft.NET.Test.Sdk" /> <PackageReference Include="Microsoft.NET.Test.Sdk" />
</ItemGroup> </ItemGroup>

5
framework/test/Volo.Abp.MongoDB.Tests/Volo/Abp/MongoDB/MongoDbFixture.cs

@ -1,5 +1,5 @@
using System; using System;
using EphemeralMongo; using MongoSandbox;
namespace Volo.Abp.MongoDB; namespace Volo.Abp.MongoDB;
@ -11,7 +11,8 @@ public class MongoDbFixture : IDisposable
{ {
MongoDbRunner = MongoRunner.Run(new MongoRunnerOptions MongoDbRunner = MongoRunner.Run(new MongoRunnerOptions
{ {
UseSingleNodeReplicaSet = true UseSingleNodeReplicaSet = true,
ReplicaSetSetupTimeout = TimeSpan.FromSeconds(30)
}); });
} }

12
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<AbpMongoDbTestModul
public async Task ToMongoQueryable_Test() public async Task ToMongoQueryable_Test()
{ {
(await PersonRepository.GetQueryableAsync()).ShouldNotBeNull(); (await PersonRepository.GetQueryableAsync()).ShouldNotBeNull();
(await PersonRepository.GetQueryableAsync()).As<IMongoQueryable<Person>>().ShouldNotBeNull(); (await PersonRepository.GetQueryableAsync()).ShouldNotBeNull();
((IMongoQueryable<Person>)(await PersonRepository.GetQueryableAsync()).Where(p => p.Name == "Douglas")).ShouldNotBeNull(); ((IQueryable<Person>)(await PersonRepository.GetQueryableAsync()).Where(p => p.Name == "Douglas")).ShouldNotBeNull();
(await PersonRepository.GetQueryableAsync()).Where(p => p.Name == "Douglas").As<IMongoQueryable<Person>>().ShouldNotBeNull(); (await PersonRepository.GetQueryableAsync()).Where(p => p.Name == "Douglas").ShouldNotBeNull();
} }
[Fact] [Fact]
@ -69,9 +69,9 @@ public class Repository_Basic_Tests : Repository_Basic_Tests<AbpMongoDbTestModul
[Fact] [Fact]
public async Task Filter_Case_Insensitive() public async Task Filter_Case_Insensitive()
{ {
(await CityRepository.GetMongoQueryableAsync()).FirstOrDefault(c => c.Name == "ISTANBUL").ShouldBeNull(); (await CityRepository.GetQueryableAsync()).FirstOrDefault(c => c.Name == "ISTANBUL").ShouldBeNull();
(await CityRepository.GetMongoQueryableAsync()).FirstOrDefault(c => c.Name == "istanbul").ShouldBeNull(); (await CityRepository.GetQueryableAsync()).FirstOrDefault(c => c.Name == "istanbul").ShouldBeNull();
(await CityRepository.GetMongoQueryableAsync()).FirstOrDefault(c => c.Name == "Istanbul").ShouldNotBeNull(); (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();
(await PersonRepository.GetQueryableAsync()).FirstOrDefault(p => p.Name == "DOUGLAS").ShouldNotBeNull(); (await PersonRepository.GetQueryableAsync()).FirstOrDefault(p => p.Name == "DOUGLAS").ShouldNotBeNull();

1
framework/test/Volo.Abp.MongoDB.Tests/Volo/Abp/TestApp/MongoDb/CityRepository.cs

@ -1,5 +1,6 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks; using System.Threading.Tasks;
using MongoDB.Driver; using MongoDB.Driver;
using MongoDB.Driver.Linq; using MongoDB.Driver.Linq;

24
modules/audit-logging/src/Volo.Abp.AuditLogging.MongoDB/Volo/Abp/AuditLogging/MongoDB/MongoAuditLogRepository.cs

@ -64,8 +64,7 @@ public class MongoAuditLogRepository : MongoDbRepository<IAuditLoggingMongoDbCon
return await query return await query
.OrderBy(sorting.IsNullOrWhiteSpace() ? (nameof(AuditLog.ExecutionTime) + " DESC") : sorting) .OrderBy(sorting.IsNullOrWhiteSpace() ? (nameof(AuditLog.ExecutionTime) + " DESC") : sorting)
.As<IMongoQueryable<AuditLog>>() .PageBy(skipCount, maxResultCount)
.PageBy<AuditLog, IMongoQueryable<AuditLog>>(skipCount, maxResultCount)
.ToListAsync(GetCancellationToken(cancellationToken)); .ToListAsync(GetCancellationToken(cancellationToken));
} }
@ -104,8 +103,7 @@ public class MongoAuditLogRepository : MongoDbRepository<IAuditLoggingMongoDbCon
cancellationToken: cancellationToken cancellationToken: cancellationToken
); );
var count = await query.As<IMongoQueryable<AuditLog>>() var count = await query.LongCountAsync(GetCancellationToken(cancellationToken));
.LongCountAsync(GetCancellationToken(cancellationToken));
return count; return count;
} }
@ -128,7 +126,7 @@ public class MongoAuditLogRepository : MongoDbRepository<IAuditLoggingMongoDbCon
bool includeDetails = false, bool includeDetails = false,
CancellationToken cancellationToken = default) CancellationToken cancellationToken = default)
{ {
return (await GetMongoQueryableAsync(cancellationToken)) return (await GetQueryableAsync(cancellationToken))
.WhereIf(startTime.HasValue, auditLog => auditLog.ExecutionTime >= startTime) .WhereIf(startTime.HasValue, auditLog => auditLog.ExecutionTime >= startTime)
.WhereIf(endTime.HasValue, auditLog => auditLog.ExecutionTime <= endTime) .WhereIf(endTime.HasValue, auditLog => auditLog.ExecutionTime <= endTime)
.WhereIf(hasException.HasValue && hasException.Value, auditLog => auditLog.Exceptions != null && auditLog.Exceptions != "") .WhereIf(hasException.HasValue && hasException.Value, auditLog => auditLog.Exceptions != null && auditLog.Exceptions != "")
@ -151,7 +149,7 @@ public class MongoAuditLogRepository : MongoDbRepository<IAuditLoggingMongoDbCon
DateTime endDate, DateTime endDate,
CancellationToken cancellationToken = default) CancellationToken cancellationToken = default)
{ {
var result = await (await GetMongoQueryableAsync(cancellationToken)) var result = await (await GetQueryableAsync(cancellationToken))
.Where(a => a.ExecutionTime < endDate.AddDays(1) && a.ExecutionTime > startDate) .Where(a => a.ExecutionTime < endDate.AddDays(1) && a.ExecutionTime > startDate)
.OrderBy(t => t.ExecutionTime) .OrderBy(t => t.ExecutionTime)
.GroupBy(t => new { .GroupBy(t => new {
@ -169,7 +167,7 @@ public class MongoAuditLogRepository : MongoDbRepository<IAuditLoggingMongoDbCon
Guid entityChangeId, Guid entityChangeId,
CancellationToken cancellationToken = default) CancellationToken cancellationToken = default)
{ {
var entityChange = (await (await GetMongoQueryableAsync(cancellationToken)) var entityChange = (await (await GetQueryableAsync(cancellationToken))
.Where(x => x.EntityChanges.Any(y => y.Id == entityChangeId)) .Where(x => x.EntityChanges.Any(y => y.Id == entityChangeId))
.OrderBy(x => x.Id) .OrderBy(x => x.Id)
.FirstAsync(GetCancellationToken(cancellationToken))).EntityChanges.FirstOrDefault(x => x.Id == entityChangeId); .FirstAsync(GetCancellationToken(cancellationToken))).EntityChanges.FirstOrDefault(x => x.Id == entityChangeId);
@ -199,8 +197,7 @@ public class MongoAuditLogRepository : MongoDbRepository<IAuditLoggingMongoDbCon
return await query return await query
.OrderBy(sorting.IsNullOrWhiteSpace() ? (nameof(EntityChange.ChangeTime) + " DESC") : sorting) .OrderBy(sorting.IsNullOrWhiteSpace() ? (nameof(EntityChange.ChangeTime) + " DESC") : sorting)
.As<IMongoQueryable<EntityChange>>() .PageBy(skipCount, maxResultCount)
.PageBy<EntityChange, IMongoQueryable<EntityChange>>(skipCount, maxResultCount)
.ToListAsync(GetCancellationToken(cancellationToken)); .ToListAsync(GetCancellationToken(cancellationToken));
} }
@ -215,7 +212,7 @@ public class MongoAuditLogRepository : MongoDbRepository<IAuditLoggingMongoDbCon
{ {
var query = await GetEntityChangeListQueryAsync(auditLogId, startTime, endTime, changeType, entityId, entityTypeFullName, cancellationToken); var query = await GetEntityChangeListQueryAsync(auditLogId, startTime, endTime, changeType, entityId, entityTypeFullName, cancellationToken);
var count = await query.As<IMongoQueryable<EntityChange>>().LongCountAsync(GetCancellationToken(cancellationToken)); var count = await query.LongCountAsync(GetCancellationToken(cancellationToken));
return count; return count;
} }
@ -224,7 +221,7 @@ public class MongoAuditLogRepository : MongoDbRepository<IAuditLoggingMongoDbCon
Guid entityChangeId, Guid entityChangeId,
CancellationToken cancellationToken = default) CancellationToken cancellationToken = default)
{ {
var auditLog = await (await GetMongoQueryableAsync(cancellationToken)) var auditLog = await (await GetQueryableAsync(cancellationToken))
.Where(x => x.EntityChanges.Any(y => y.Id == entityChangeId)) .Where(x => x.EntityChanges.Any(y => y.Id == entityChangeId))
.FirstAsync(GetCancellationToken(cancellationToken)); .FirstAsync(GetCancellationToken(cancellationToken));
@ -240,9 +237,8 @@ public class MongoAuditLogRepository : MongoDbRepository<IAuditLoggingMongoDbCon
string entityTypeFullName, string entityTypeFullName,
CancellationToken cancellationToken = default) CancellationToken cancellationToken = default)
{ {
var auditLogs = await (await GetMongoQueryableAsync(cancellationToken)) var auditLogs = await (await GetQueryableAsync(cancellationToken))
.Where(x => x.EntityChanges.Any(y => y.EntityId == entityId && y.EntityTypeFullName == entityTypeFullName)) .Where(x => x.EntityChanges.Any(y => y.EntityId == entityId && y.EntityTypeFullName == entityTypeFullName))
.As<IMongoQueryable<AuditLog>>()
.OrderByDescending(x => x.ExecutionTime) .OrderByDescending(x => x.ExecutionTime)
.ToListAsync(GetCancellationToken(cancellationToken)); .ToListAsync(GetCancellationToken(cancellationToken));
@ -263,7 +259,7 @@ public class MongoAuditLogRepository : MongoDbRepository<IAuditLoggingMongoDbCon
string entityTypeFullName = null, string entityTypeFullName = null,
CancellationToken cancellationToken = default) CancellationToken cancellationToken = default)
{ {
return (await GetMongoQueryableAsync(cancellationToken)) return (await GetQueryableAsync(cancellationToken))
.SelectMany(x => x.EntityChanges) .SelectMany(x => x.EntityChanges)
.WhereIf(auditLogId.HasValue, e => e.Id == auditLogId) .WhereIf(auditLogId.HasValue, e => e.Id == auditLogId)
.WhereIf(startTime.HasValue, e => e.ChangeTime >= startTime) .WhereIf(startTime.HasValue, e => e.ChangeTime >= startTime)

8
modules/audit-logging/test/Volo.Abp.AuditLogging.MongoDB.Tests/Volo.Abp.AuditLogging.MongoDB.Tests.csproj

@ -14,10 +14,10 @@
<ItemGroup> <ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" /> <PackageReference Include="Microsoft.NET.Test.Sdk" />
<PackageReference Include="EphemeralMongo.Core" /> <PackageReference Include="MongoSandbox.Core" />
<PackageReference Include="EphemeralMongo6.runtime.linux-x64" Condition="$([MSBuild]::IsOSPlatform('Linux'))" /> <PackageReference Include="MongoSandbox6.runtime.linux-x64" Condition="$([MSBuild]::IsOSPlatform('Linux'))" />
<PackageReference Include="EphemeralMongo6.runtime.osx-x64" Condition="$([MSBuild]::IsOSPlatform('OSX'))" /> <PackageReference Include="MongoSandbox6.runtime.osx-x64" Condition="$([MSBuild]::IsOSPlatform('OSX'))" />
<PackageReference Include="EphemeralMongo6.runtime.win-x64" Condition="$([MSBuild]::IsOSPlatform('Windows'))" /> <PackageReference Include="MongoSandbox6.runtime.win-x64" Condition="$([MSBuild]::IsOSPlatform('Windows'))" />
</ItemGroup> </ItemGroup>
</Project> </Project>

2
modules/audit-logging/test/Volo.Abp.AuditLogging.MongoDB.Tests/Volo/Abp/AuditLogging/MongoDB/MongoDbFixture.cs

@ -1,5 +1,5 @@
using System; using System;
using EphemeralMongo; using MongoSandbox;
namespace Volo.Abp.AuditLogging.MongoDB; namespace Volo.Abp.AuditLogging.MongoDB;

5
modules/background-jobs/src/Volo.Abp.BackgroundJobs.MongoDB/Volo/Abp/BackgroundJobs/MongoDB/MongoBackgroundJobRepository.cs

@ -2,6 +2,7 @@
using System.Collections.Generic; using System.Collections.Generic;
using System.Threading; using System.Threading;
using System.Threading.Tasks; using System.Threading.Tasks;
using System.Linq;
using MongoDB.Driver; using MongoDB.Driver;
using MongoDB.Driver.Linq; using MongoDB.Driver.Linq;
using Volo.Abp.Domain.Repositories.MongoDB; using Volo.Abp.Domain.Repositories.MongoDB;
@ -29,10 +30,10 @@ public class MongoBackgroundJobRepository : MongoDbRepository<IBackgroundJobsMon
return await (await GetWaitingListQuery(maxResultCount)).ToListAsync(GetCancellationToken(cancellationToken)); return await (await GetWaitingListQuery(maxResultCount)).ToListAsync(GetCancellationToken(cancellationToken));
} }
protected virtual async Task<IMongoQueryable<BackgroundJobRecord>> GetWaitingListQuery(int maxResultCount, CancellationToken cancellationToken = default) protected virtual async Task<IQueryable<BackgroundJobRecord>> GetWaitingListQuery(int maxResultCount, CancellationToken cancellationToken = default)
{ {
var now = Clock.Now; var now = Clock.Now;
return (await GetMongoQueryableAsync(cancellationToken)) return (await GetQueryableAsync(cancellationToken))
.Where(t => !t.IsAbandoned && t.NextTryTime <= now) .Where(t => !t.IsAbandoned && t.NextTryTime <= now)
.OrderByDescending(t => t.Priority) .OrderByDescending(t => t.Priority)
.ThenBy(t => t.TryCount) .ThenBy(t => t.TryCount)

8
modules/background-jobs/test/Volo.Abp.BackgroundJobs.MongoDB.Tests/Volo.Abp.BackgroundJobs.MongoDB.Tests.csproj

@ -14,10 +14,10 @@
<ItemGroup> <ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" /> <PackageReference Include="Microsoft.NET.Test.Sdk" />
<PackageReference Include="EphemeralMongo.Core" /> <PackageReference Include="MongoSandbox.Core" />
<PackageReference Include="EphemeralMongo6.runtime.linux-x64" Condition="$([MSBuild]::IsOSPlatform('Linux'))" /> <PackageReference Include="MongoSandbox6.runtime.linux-x64" Condition="$([MSBuild]::IsOSPlatform('Linux'))" />
<PackageReference Include="EphemeralMongo6.runtime.osx-x64" Condition="$([MSBuild]::IsOSPlatform('OSX'))" /> <PackageReference Include="MongoSandbox6.runtime.osx-x64" Condition="$([MSBuild]::IsOSPlatform('OSX'))" />
<PackageReference Include="EphemeralMongo6.runtime.win-x64" Condition="$([MSBuild]::IsOSPlatform('Windows'))" /> <PackageReference Include="MongoSandbox6.runtime.win-x64" Condition="$([MSBuild]::IsOSPlatform('Windows'))" />
</ItemGroup> </ItemGroup>
</Project> </Project>

2
modules/background-jobs/test/Volo.Abp.BackgroundJobs.MongoDB.Tests/Volo/Abp/BackgroundJobs/MongoDB/MongoDbFixture.cs

@ -1,5 +1,5 @@
using System; using System;
using EphemeralMongo; using MongoSandbox;
namespace Volo.Abp.BackgroundJobs.MongoDB; namespace Volo.Abp.BackgroundJobs.MongoDB;

4
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<IBlobStoringMongo
{ {
cancellationToken = GetCancellationToken(cancellationToken); cancellationToken = GetCancellationToken(cancellationToken);
return await (await GetMongoQueryableAsync(cancellationToken)) return await (await GetQueryableAsync(cancellationToken))
.FirstOrDefaultAsync( .FirstOrDefaultAsync(
x => x.ContainerId == containerId && x.Name == name, x => x.ContainerId == containerId && x.Name == name,
cancellationToken cancellationToken
@ -28,7 +28,7 @@ public class MongoDbDatabaseBlobRepository : MongoDbRepository<IBlobStoringMongo
{ {
cancellationToken = GetCancellationToken(cancellationToken); cancellationToken = GetCancellationToken(cancellationToken);
return await (await GetMongoQueryableAsync(cancellationToken)) return await (await GetQueryableAsync(cancellationToken))
.AnyAsync( .AnyAsync(
x => x.ContainerId == containerId && x.Name == name, x => x.ContainerId == containerId && x.Name == name,
cancellationToken cancellationToken

2
modules/blob-storing-database/test/Volo.Abp.BlobStoring.Database.MongoDB.Tests/MongoDB/MongoDbFixture.cs

@ -1,5 +1,5 @@
using System; using System;
using EphemeralMongo; using MongoSandbox;
namespace Volo.Abp.BlobStoring.Database.MongoDB; namespace Volo.Abp.BlobStoring.Database.MongoDB;

8
modules/blob-storing-database/test/Volo.Abp.BlobStoring.Database.MongoDB.Tests/Volo.Abp.BlobStoring.Database.MongoDB.Tests.csproj

@ -7,10 +7,10 @@
<ItemGroup> <ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" /> <PackageReference Include="Microsoft.NET.Test.Sdk" />
<PackageReference Include="EphemeralMongo.Core" /> <PackageReference Include="MongoSandbox.Core" />
<PackageReference Include="EphemeralMongo6.runtime.linux-x64" Condition="$([MSBuild]::IsOSPlatform('Linux'))" /> <PackageReference Include="MongoSandbox6.runtime.linux-x64" Condition="$([MSBuild]::IsOSPlatform('Linux'))" />
<PackageReference Include="EphemeralMongo6.runtime.osx-x64" Condition="$([MSBuild]::IsOSPlatform('OSX'))" /> <PackageReference Include="MongoSandbox6.runtime.osx-x64" Condition="$([MSBuild]::IsOSPlatform('OSX'))" />
<PackageReference Include="EphemeralMongo6.runtime.win-x64" Condition="$([MSBuild]::IsOSPlatform('Windows'))" /> <PackageReference Include="MongoSandbox6.runtime.win-x64" Condition="$([MSBuild]::IsOSPlatform('Windows'))" />
<ProjectReference Include="..\..\src\Volo.Abp.BlobStoring.Database.MongoDB\Volo.Abp.BlobStoring.Database.MongoDB.csproj" /> <ProjectReference Include="..\..\src\Volo.Abp.BlobStoring.Database.MongoDB\Volo.Abp.BlobStoring.Database.MongoDB.csproj" />
<ProjectReference Include="..\Volo.Abp.BlobStoring.Database.TestBase\Volo.Abp.BlobStoring.Database.TestBase.csproj" /> <ProjectReference Include="..\Volo.Abp.BlobStoring.Database.TestBase\Volo.Abp.BlobStoring.Database.TestBase.csproj" />
</ItemGroup> </ItemGroup>

2
modules/blogging/src/Volo.Blogging.MongoDB/Volo/Blogging/Blogs/MongoBlogRepository.cs

@ -16,7 +16,7 @@ namespace Volo.Blogging.Blogs
public virtual async Task<Blog> FindByShortNameAsync(string shortName, CancellationToken cancellationToken = default) public virtual async Task<Blog> 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));
} }
} }
} }

9
modules/blogging/src/Volo.Blogging.MongoDB/Volo/Blogging/Comments/MongoCommentRepository.cs

@ -2,6 +2,7 @@
using System.Collections.Generic; using System.Collections.Generic;
using System.Threading; using System.Threading;
using System.Threading.Tasks; using System.Threading.Tasks;
using System.Linq;
using MongoDB.Driver; using MongoDB.Driver;
using MongoDB.Driver.Linq; using MongoDB.Driver.Linq;
using Volo.Abp.Domain.Repositories.MongoDB; using Volo.Abp.Domain.Repositories.MongoDB;
@ -18,7 +19,7 @@ namespace Volo.Blogging.Comments
public virtual async Task<List<Comment>> GetListOfPostAsync(Guid postId, CancellationToken cancellationToken = default) public virtual async Task<List<Comment>> GetListOfPostAsync(Guid postId, CancellationToken cancellationToken = default)
{ {
return await (await GetMongoQueryableAsync(cancellationToken)) return await (await GetQueryableAsync(cancellationToken))
.Where(a => a.PostId == postId) .Where(a => a.PostId == postId)
.OrderBy(a => a.CreationTime) .OrderBy(a => a.CreationTime)
.ToListAsync(GetCancellationToken(cancellationToken)); .ToListAsync(GetCancellationToken(cancellationToken));
@ -26,19 +27,19 @@ namespace Volo.Blogging.Comments
public virtual async Task<int> GetCommentCountOfPostAsync(Guid postId, CancellationToken cancellationToken = default) public virtual async Task<int> GetCommentCountOfPostAsync(Guid postId, CancellationToken cancellationToken = default)
{ {
return await (await GetMongoQueryableAsync(cancellationToken)) return await (await GetQueryableAsync(cancellationToken))
.CountAsync(a => a.PostId == postId, GetCancellationToken(cancellationToken)); .CountAsync(a => a.PostId == postId, GetCancellationToken(cancellationToken));
} }
public virtual async Task<List<Comment>> GetRepliesOfComment(Guid id, CancellationToken cancellationToken = default) public virtual async Task<List<Comment>> GetRepliesOfComment(Guid id, CancellationToken cancellationToken = default)
{ {
return await (await GetMongoQueryableAsync(cancellationToken)) return await (await GetQueryableAsync(cancellationToken))
.Where(a => a.RepliedCommentId == id).ToListAsync(GetCancellationToken(cancellationToken)); .Where(a => a.RepliedCommentId == id).ToListAsync(GetCancellationToken(cancellationToken));
} }
public virtual async Task DeleteOfPost(Guid id, CancellationToken cancellationToken = default) 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) foreach (var record in recordsToDelete)
{ {

13
modules/blogging/src/Volo.Blogging.MongoDB/Volo/Blogging/Posts/MongoPostRepository.cs

@ -2,6 +2,7 @@
using System.Collections.Generic; using System.Collections.Generic;
using System.Threading; using System.Threading;
using System.Threading.Tasks; using System.Threading.Tasks;
using System.Linq;
using MongoDB.Driver; using MongoDB.Driver;
using MongoDB.Driver.Linq; using MongoDB.Driver.Linq;
using Nito.AsyncEx; using Nito.AsyncEx;
@ -20,13 +21,13 @@ namespace Volo.Blogging.Posts
public virtual async Task<List<Post>> GetPostsByBlogId(Guid id, CancellationToken cancellationToken = default) public virtual async Task<List<Post>> 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<bool> IsPostUrlInUseAsync(Guid blogId, string url, Guid? excludingPostId = null, CancellationToken cancellationToken = default) public virtual async Task<bool> 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) if (excludingPostId != null)
{ {
@ -38,7 +39,7 @@ namespace Volo.Blogging.Posts
public virtual async Task<Post> GetPostByUrl(Guid blogId, string url, CancellationToken cancellationToken = default) public virtual async Task<Post> 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) if (post == null)
{ {
@ -50,7 +51,7 @@ namespace Volo.Blogging.Posts
public virtual async Task<List<Post>> GetOrderedList(Guid blogId, bool @descending = false, CancellationToken cancellationToken = default) public virtual async Task<List<Post>> 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) if (!descending)
{ {
@ -62,7 +63,7 @@ namespace Volo.Blogging.Posts
public virtual async Task<List<Post>> GetListByUserIdAsync(Guid userId, CancellationToken cancellationToken = default) public virtual async Task<List<Post>> 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); .OrderByDescending(x => x.CreationTime);
return await query.ToListAsync(GetCancellationToken(cancellationToken)); return await query.ToListAsync(GetCancellationToken(cancellationToken));
@ -70,7 +71,7 @@ namespace Volo.Blogging.Posts
public virtual async Task<List<Post>> GetLatestBlogPostsAsync(Guid blogId, int count, CancellationToken cancellationToken = default) public virtual async Task<List<Post>> 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) .OrderByDescending(x => x.CreationTime)
.Take(count); .Take(count);

10
modules/blogging/src/Volo.Blogging.MongoDB/Volo/Blogging/Tagging/MongoTagRepository.cs

@ -20,27 +20,27 @@ namespace Volo.Blogging.Tagging
public virtual async Task<List<Tag>> GetListAsync(Guid blogId, CancellationToken cancellationToken = default) public virtual async Task<List<Tag>> 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<Tag> GetByNameAsync(Guid blogId, string name, CancellationToken cancellationToken = default) public virtual async Task<Tag> 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<Tag> FindByNameAsync(Guid blogId, string name, CancellationToken cancellationToken = default) public virtual async Task<Tag> 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<List<Tag>> GetListAsync(IEnumerable<Guid> ids, CancellationToken cancellationToken = default) public virtual async Task<List<Tag>> GetListAsync(IEnumerable<Guid> 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<Guid> ids, CancellationToken cancellationToken = default) public virtual async Task DecreaseUsageCountOfTagsAsync(List<Guid> ids, CancellationToken cancellationToken = default)
{ {
var tags = await (await GetMongoQueryableAsync(cancellationToken)) var tags = await (await GetQueryableAsync(cancellationToken))
.Where(t => ids.Contains(t.Id)) .Where(t => ids.Contains(t.Id))
.ToListAsync(GetCancellationToken(cancellationToken)); .ToListAsync(GetCancellationToken(cancellationToken));

3
modules/blogging/src/Volo.Blogging.MongoDB/Volo/Blogging/Users/MongoBlogUserRepository.cs

@ -1,6 +1,7 @@
using System.Collections.Generic; using System.Collections.Generic;
using System.Threading; using System.Threading;
using System.Threading.Tasks; using System.Threading.Tasks;
using System.Linq;
using Volo.Abp.MongoDB; using Volo.Abp.MongoDB;
using Volo.Abp.Users.MongoDB; using Volo.Abp.Users.MongoDB;
using Volo.Blogging.MongoDB; using Volo.Blogging.MongoDB;
@ -17,7 +18,7 @@ namespace Volo.Blogging.Users
public virtual async Task<List<BlogUser>> GetUsersAsync(int maxCount, string filter, CancellationToken cancellationToken = default) public virtual async Task<List<BlogUser>> GetUsersAsync(int maxCount, string filter, CancellationToken cancellationToken = default)
{ {
var query = await GetMongoQueryableAsync(cancellationToken); var query = await GetQueryableAsync(cancellationToken);
if (!string.IsNullOrWhiteSpace(filter)) if (!string.IsNullOrWhiteSpace(filter))
{ {

8
modules/blogging/test/Volo.Blogging.MongoDB.Tests/Volo.Blogging.MongoDB.Tests.csproj

@ -7,10 +7,10 @@
<ItemGroup> <ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" /> <PackageReference Include="Microsoft.NET.Test.Sdk" />
<PackageReference Include="EphemeralMongo.Core" /> <PackageReference Include="MongoSandbox.Core" />
<PackageReference Include="EphemeralMongo6.runtime.linux-x64" Condition="$([MSBuild]::IsOSPlatform('Linux'))" /> <PackageReference Include="MongoSandbox6.runtime.linux-x64" Condition="$([MSBuild]::IsOSPlatform('Linux'))" />
<PackageReference Include="EphemeralMongo6.runtime.osx-x64" Condition="$([MSBuild]::IsOSPlatform('OSX'))" /> <PackageReference Include="MongoSandbox6.runtime.osx-x64" Condition="$([MSBuild]::IsOSPlatform('OSX'))" />
<PackageReference Include="EphemeralMongo6.runtime.win-x64" Condition="$([MSBuild]::IsOSPlatform('Windows'))" /> <PackageReference Include="MongoSandbox6.runtime.win-x64" Condition="$([MSBuild]::IsOSPlatform('Windows'))" />
<ProjectReference Include="..\..\src\Volo.Blogging.MongoDB\Volo.Blogging.MongoDB.csproj" /> <ProjectReference Include="..\..\src\Volo.Blogging.MongoDB\Volo.Blogging.MongoDB.csproj" />
<ProjectReference Include="..\Volo.Blogging.TestBase\Volo.Blogging.TestBase.csproj" /> <ProjectReference Include="..\Volo.Blogging.TestBase\Volo.Blogging.TestBase.csproj" />
</ItemGroup> </ItemGroup>

2
modules/blogging/test/Volo.Blogging.MongoDB.Tests/Volo/Blogging/MongoDB/MongoDbFixture.cs

@ -1,5 +1,5 @@
using System; using System;
using EphemeralMongo; using MongoSandbox;
public class MongoDbFixture : IDisposable public class MongoDbFixture : IDisposable
{ {

4
modules/cms-kit/src/Volo.CmsKit.MongoDB/Volo/CmsKit/MongoDB/Blogs/MongoBlogFeatureRepository.cs

@ -25,14 +25,14 @@ public class MongoBlogFeatureRepository : MongoDbRepository<ICmsKitMongoDbContex
public virtual async Task<List<BlogFeature>> GetListAsync(Guid blogId, CancellationToken cancellationToken = default) public virtual async Task<List<BlogFeature>> GetListAsync(Guid blogId, CancellationToken cancellationToken = default)
{ {
return await (await GetMongoQueryableAsync(cancellationToken)) return await (await GetQueryableAsync(cancellationToken))
.Where(x => x.BlogId == blogId) .Where(x => x.BlogId == blogId)
.ToListAsync(GetCancellationToken(cancellationToken)); .ToListAsync(GetCancellationToken(cancellationToken));
} }
public virtual async Task<List<BlogFeature>> GetListAsync(Guid blogId, List<string> featureNames, CancellationToken cancellationToken = default) public virtual async Task<List<BlogFeature>> GetListAsync(Guid blogId, List<string> featureNames, CancellationToken cancellationToken = default)
{ {
return await (await GetMongoQueryableAsync(cancellationToken)) return await (await GetQueryableAsync(cancellationToken))
.Where(x => x.BlogId == blogId && featureNames.Contains(x.FeatureName)) .Where(x => x.BlogId == blogId && featureNames.Contains(x.FeatureName))
.ToListAsync(GetCancellationToken(cancellationToken)); .ToListAsync(GetCancellationToken(cancellationToken));
} }

22
modules/cms-kit/src/Volo.CmsKit.MongoDB/Volo/CmsKit/MongoDB/Blogs/MongoBlogPostRepository.cs

@ -44,7 +44,7 @@ public class MongoBlogPostRepository : MongoDbRepository<CmsKitMongoDbContext, B
x.Slug.ToLower() == slug, x.Slug.ToLower() == slug,
cancellationToken: token); cancellationToken: token);
blogPost.Author = await (await GetMongoQueryableAsync<CmsUser>(token)).FirstOrDefaultAsync(x => x.Id == blogPost.AuthorId, token); blogPost.Author = await (await GetQueryableAsync<CmsUser>(token)).FirstOrDefaultAsync(x => x.Id == blogPost.AuthorId, token);
return blogPost; return blogPost;
} }
@ -64,13 +64,13 @@ public class MongoBlogPostRepository : MongoDbRepository<CmsKitMongoDbContext, B
var favoriteUserFilteredEntityIds = await GetFavoriteEntityIdsByUserId(favoriteUserId, cancellationToken); var favoriteUserFilteredEntityIds = await GetFavoriteEntityIdsByUserId(favoriteUserId, cancellationToken);
return await (await GetMongoQueryableAsync(cancellationToken)) return await (await GetQueryableAsync(cancellationToken))
.WhereIf<BlogPost, IMongoQueryable<BlogPost>>(tagFilteredEntityIds.Any(), x => tagFilteredEntityIds.Contains(x.Id)) .WhereIf(tagFilteredEntityIds.Any(), x => tagFilteredEntityIds.Contains(x.Id))
.WhereIf<BlogPost, IMongoQueryable<BlogPost>>(favoriteUserFilteredEntityIds.Any(), x => favoriteUserFilteredEntityIds.Contains(x.Id)) .WhereIf(favoriteUserFilteredEntityIds.Any(), x => favoriteUserFilteredEntityIds.Contains(x.Id))
.WhereIf<BlogPost, IMongoQueryable<BlogPost>>(!string.IsNullOrWhiteSpace(filter), x => x.Title.Contains(filter) || x.Slug.Contains(filter)) .WhereIf(!string.IsNullOrWhiteSpace(filter), x => x.Title.Contains(filter) || x.Slug.Contains(filter))
.WhereIf<BlogPost, IMongoQueryable<BlogPost>>(blogId.HasValue, x => x.BlogId == blogId) .WhereIf(blogId.HasValue, x => x.BlogId == blogId)
.WhereIf<BlogPost, IMongoQueryable<BlogPost>>(authorId.HasValue, x => x.AuthorId == authorId) .WhereIf(authorId.HasValue, x => x.AuthorId == authorId)
.WhereIf<BlogPost, IMongoQueryable<BlogPost>>(statusFilter.HasValue, x => x.Status == statusFilter) .WhereIf(statusFilter.HasValue, x => x.Status == statusFilter)
.CountAsync(cancellationToken); .CountAsync(cancellationToken);
} }
@ -174,7 +174,7 @@ public class MongoBlogPostRepository : MongoDbRepository<CmsKitMongoDbContext, B
Check.NotNullOrEmpty(slug, nameof(slug)); Check.NotNullOrEmpty(slug, nameof(slug));
cancellationToken = GetCancellationToken(cancellationToken); cancellationToken = GetCancellationToken(cancellationToken);
var queryable = await GetMongoQueryableAsync(cancellationToken); var queryable = await GetQueryableAsync(cancellationToken);
return await queryable.AnyAsync(x => x.BlogId == blogId && x.Slug.ToLower() == slug, cancellationToken); return await queryable.AnyAsync(x => x.BlogId == blogId && x.Slug.ToLower() == slug, cancellationToken);
} }
@ -225,14 +225,14 @@ public class MongoBlogPostRepository : MongoDbRepository<CmsKitMongoDbContext, B
{ {
cancellationToken = GetCancellationToken(cancellationToken); cancellationToken = GetCancellationToken(cancellationToken);
return await (await GetMongoQueryableAsync(cancellationToken)) return await (await GetQueryableAsync(cancellationToken))
.AnyAsync(x => x.Status == BlogPostStatus.WaitingForReview, cancellationToken); .AnyAsync(x => x.Status == BlogPostStatus.WaitingForReview, cancellationToken);
} }
public async Task UpdateBlogAsync(Guid sourceBlogId, Guid? targetBlogId, CancellationToken cancellationToken = default) public async Task UpdateBlogAsync(Guid sourceBlogId, Guid? targetBlogId, CancellationToken cancellationToken = default)
{ {
cancellationToken = GetCancellationToken(cancellationToken); 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) if (targetBlogId.HasValue)
{ {
foreach (var blogPost in blogPosts) foreach (var blogPost in blogPosts)

13
modules/cms-kit/src/Volo.CmsKit.MongoDB/Volo/CmsKit/MongoDB/Blogs/MongoBlogRepository.cs

@ -23,13 +23,13 @@ public class MongoBlogRepository : MongoDbRepository<ICmsKitMongoDbContext, Blog
public virtual async Task<bool> ExistsAsync(Guid id, CancellationToken cancellationToken = default) public virtual async Task<bool> ExistsAsync(Guid id, CancellationToken cancellationToken = default)
{ {
var token = GetCancellationToken(cancellationToken); 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<bool> SlugExistsAsync(string slug, CancellationToken cancellationToken = default) public virtual async Task<bool> SlugExistsAsync(string slug, CancellationToken cancellationToken = default)
{ {
var token = GetCancellationToken(cancellationToken); 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<List<Blog>> GetListAsync( public virtual async Task<List<Blog>> GetListAsync(
@ -44,8 +44,7 @@ public class MongoBlogRepository : MongoDbRepository<ICmsKitMongoDbContext, Blog
var query = await GetListQueryAsync(filter, token); var query = await GetListQueryAsync(filter, token);
return await query.OrderBy(sorting.IsNullOrEmpty() ? "creationTime desc" : sorting) return await query.OrderBy(sorting.IsNullOrEmpty() ? "creationTime desc" : sorting)
.As<IMongoQueryable<Blog>>() .PageBy(skipCount, maxResultCount)
.PageBy<Blog, IMongoQueryable<Blog>>(skipCount, maxResultCount)
.ToListAsync(token); .ToListAsync(token);
} }
@ -63,7 +62,7 @@ public class MongoBlogRepository : MongoDbRepository<ICmsKitMongoDbContext, Blog
var blogIds = blogs.OrderBy(sorting.IsNullOrEmpty() ? "creationTime desc" : sorting) var blogIds = blogs.OrderBy(sorting.IsNullOrEmpty() ? "creationTime desc" : sorting)
.PageBy(skipCount, maxResultCount).Select(x => x.Id).ToList(); .PageBy(skipCount, maxResultCount).Select(x => x.Id).ToList();
var blogPostCount = await (await GetMongoQueryableAsync<BlogPost>(token)) var blogPostCount = await (await GetQueryableAsync<BlogPost>(token))
.Where(blogPost => blogIds.Contains(blogPost.Id)) .Where(blogPost => blogIds.Contains(blogPost.Id))
.GroupBy(blogPost => blogPost.BlogId) .GroupBy(blogPost => blogPost.BlogId)
.Select(x => new .Select(x => new
@ -82,7 +81,7 @@ public class MongoBlogRepository : MongoDbRepository<ICmsKitMongoDbContext, Blog
var query = await GetListQueryAsync(filter, token); var query = await GetListQueryAsync(filter, token);
return await query.As<IMongoQueryable<Blog>>().LongCountAsync(token); return await query.LongCountAsync(token);
} }
public virtual Task<Blog> GetBySlugAsync([NotNull] string slug, CancellationToken cancellationToken = default) public virtual Task<Blog> GetBySlugAsync([NotNull] string slug, CancellationToken cancellationToken = default)
@ -93,7 +92,7 @@ public class MongoBlogRepository : MongoDbRepository<ICmsKitMongoDbContext, Blog
protected virtual async Task<IQueryable<Blog>> GetListQueryAsync(string filter = null, CancellationToken cancellationToken = default) protected virtual async Task<IQueryable<Blog>> GetListQueryAsync(string filter = null, CancellationToken cancellationToken = default)
{ {
return (await GetMongoQueryableAsync(cancellationToken)) return (await GetQueryableAsync(cancellationToken))
.WhereIf(!filter.IsNullOrWhiteSpace(), b => b.Name.Contains(filter)); .WhereIf(!filter.IsNullOrWhiteSpace(), b => b.Name.Contains(filter));
} }
} }

24
modules/cms-kit/src/Volo.CmsKit.MongoDB/Volo/CmsKit/MongoDB/Comments/MongoCommentRepository.cs

@ -61,19 +61,18 @@ public class MongoCommentRepository : MongoDbRepository<ICmsKitMongoDbContext, C
token); token);
var comments = await query.OrderBy(sorting.IsNullOrEmpty() ? "creationTime desc" : sorting) var comments = await query.OrderBy(sorting.IsNullOrEmpty() ? "creationTime desc" : sorting)
.As<IMongoQueryable<Comment>>() .PageBy(skipCount, maxResultCount)
.PageBy<Comment, IMongoQueryable<Comment>>(skipCount, maxResultCount)
.ToListAsync(token); .ToListAsync(token);
var commentIds = comments.Select(x => x.Id).ToList(); 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 join user in (await GetDbContextAsync(token)).CmsUsers on comment.CreatorId equals user.Id
where commentIds.Contains(comment.Id) where commentIds.Contains(comment.Id)
orderby comment.CreationTime orderby comment.CreationTime
select user; select user;
var authors = await ApplyDataFilters<IMongoQueryable<CmsUser>, CmsUser>(authorsQuery).ToListAsync(token); var authors = await ApplyDataFilters<IQueryable<CmsUser>, CmsUser>(authorsQuery).ToListAsync(token);
return comments return comments
.Select( .Select(
@ -104,8 +103,7 @@ public class MongoCommentRepository : MongoDbRepository<ICmsKitMongoDbContext, C
commentApproveState, commentApproveState,
cancellationToken); cancellationToken);
return await query.As<IMongoQueryable<Comment>>() return await query.LongCountAsync(GetCancellationToken(cancellationToken));
.LongCountAsync(GetCancellationToken(cancellationToken));
} }
public virtual async Task<List<CommentWithAuthorQueryResultItem>> GetListWithAuthorsAsync( public virtual async Task<List<CommentWithAuthorQueryResultItem>> GetListWithAuthorsAsync(
@ -117,15 +115,15 @@ public class MongoCommentRepository : MongoDbRepository<ICmsKitMongoDbContext, C
Check.NotNullOrWhiteSpace(entityType, nameof(entityType)); Check.NotNullOrWhiteSpace(entityType, nameof(entityType));
Check.NotNullOrWhiteSpace(entityId, nameof(entityId)); Check.NotNullOrWhiteSpace(entityId, nameof(entityId));
var authorsQuery = from comment in (await GetMongoQueryableAsync(cancellationToken)) var authorsQuery = from comment in (await GetQueryableAsync(cancellationToken))
join user in (await GetDbContextAsync(cancellationToken)).CmsUsers on comment.CreatorId equals user.Id join user in (await GetDbContextAsync(cancellationToken)).CmsUsers on comment.CreatorId equals user.Id
where entityType == comment.EntityType && entityId == comment.EntityId where entityType == comment.EntityType && entityId == comment.EntityId
orderby comment.CreationTime orderby comment.CreationTime
select user; select user;
var authors = await ApplyDataFilters<IMongoQueryable<CmsUser>, CmsUser>(authorsQuery).ToListAsync(GetCancellationToken(cancellationToken)); var authors = await ApplyDataFilters<IQueryable<CmsUser>, CmsUser>(authorsQuery).ToListAsync(GetCancellationToken(cancellationToken));
var commentsQuery = (await GetMongoQueryableAsync(cancellationToken)) var commentsQuery = (await GetQueryableAsync(cancellationToken))
.Where(c => c.EntityId == entityId && c.EntityType == entityType); .Where(c => c.EntityId == entityId && c.EntityType == entityType);
commentsQuery = commentApproveState switch { commentsQuery = commentApproveState switch {
@ -152,7 +150,7 @@ public class MongoCommentRepository : MongoDbRepository<ICmsKitMongoDbContext, C
Comment comment, Comment comment,
CancellationToken cancellationToken = default) CancellationToken cancellationToken = default)
{ {
var replies = await (await GetMongoQueryableAsync(cancellationToken)) var replies = await (await GetQueryableAsync(cancellationToken))
.Where(x => x.RepliedCommentId == comment.Id) .Where(x => x.RepliedCommentId == comment.Id)
.ToListAsync(GetCancellationToken(cancellationToken)); .ToListAsync(GetCancellationToken(cancellationToken));
@ -172,7 +170,7 @@ public class MongoCommentRepository : MongoDbRepository<ICmsKitMongoDbContext, C
public virtual async Task<bool> ExistsAsync(string idempotencyToken, CancellationToken cancellationToken = default) public virtual async Task<bool> ExistsAsync(string idempotencyToken, CancellationToken cancellationToken = default)
{ {
return await (await GetMongoQueryableAsync(cancellationToken)) return await (await GetQueryableAsync(cancellationToken))
.AnyAsync(x => x.IdempotencyToken == idempotencyToken, GetCancellationToken(cancellationToken)); .AnyAsync(x => x.IdempotencyToken == idempotencyToken, GetCancellationToken(cancellationToken));
} }
@ -187,11 +185,11 @@ public class MongoCommentRepository : MongoDbRepository<ICmsKitMongoDbContext, C
CancellationToken cancellationToken = default CancellationToken cancellationToken = default
) )
{ {
var queryable = await GetMongoQueryableAsync(cancellationToken); var queryable = await GetQueryableAsync(cancellationToken);
if (!string.IsNullOrEmpty(authorUsername)) if (!string.IsNullOrEmpty(authorUsername))
{ {
var author = await (await GetMongoQueryableAsync<CmsUser>(cancellationToken)).FirstOrDefaultAsync(x => x.UserName == authorUsername, cancellationToken: cancellationToken); var author = await (await GetQueryableAsync<CmsUser>(cancellationToken)).FirstOrDefaultAsync(x => x.UserName == authorUsername, cancellationToken: cancellationToken);
var authorId = author?.Id ?? Guid.Empty; var authorId = author?.Id ?? Guid.Empty;

6
modules/cms-kit/src/Volo.CmsKit.MongoDB/Volo/CmsKit/MongoDB/MarkedItems/MongoUserMarkedItemRepository.cs

@ -24,7 +24,7 @@ public class MongoUserMarkedItemRepository : MongoDbRepository<ICmsKitMongoDbCon
Check.NotNullOrWhiteSpace(entityType, nameof(entityType)); Check.NotNullOrWhiteSpace(entityType, nameof(entityType));
Check.NotNull(entityId, nameof(entityId)); Check.NotNull(entityId, nameof(entityId));
var entity = await (await GetMongoQueryableAsync(cancellationToken)) var entity = await (await GetQueryableAsync(cancellationToken))
.Where(x => .Where(x =>
x.CreatorId == userId && x.CreatorId == userId &&
x.EntityType == entityType && x.EntityType == entityType &&
@ -39,7 +39,7 @@ public class MongoUserMarkedItemRepository : MongoDbRepository<ICmsKitMongoDbCon
Check.NotNull(userId, nameof(userId)); Check.NotNull(userId, nameof(userId));
Check.NotNullOrWhiteSpace(entityType, nameof(entityType)); Check.NotNullOrWhiteSpace(entityType, nameof(entityType));
return await(await GetMongoQueryableAsync(cancellationToken)) return await(await GetQueryableAsync(cancellationToken))
.Where(x => .Where(x =>
x.CreatorId == userId && x.CreatorId == userId &&
x.EntityType == entityType) x.EntityType == entityType)
@ -49,7 +49,7 @@ public class MongoUserMarkedItemRepository : MongoDbRepository<ICmsKitMongoDbCon
public virtual async Task<List<string>> GetEntityIdsFilteredByUserAsync([NotNull] Guid userId, [NotNull] string entityType, [CanBeNull] Guid? tenantId = null, CancellationToken cancellationToken = default) public virtual async Task<List<string>> GetEntityIdsFilteredByUserAsync([NotNull] Guid userId, [NotNull] string entityType, [CanBeNull] Guid? tenantId = null, CancellationToken cancellationToken = default)
{ {
var dbContext = await GetDbContextAsync(); var dbContext = await GetDbContextAsync();
var userMarkedItemQueryable = await GetMongoQueryableAsync(GetCancellationToken(cancellationToken)); var userMarkedItemQueryable = await GetQueryableAsync(GetCancellationToken(cancellationToken));
var resultQueryable = userMarkedItemQueryable var resultQueryable = userMarkedItemQueryable
.Where(x => x.CreatorId == userId .Where(x => x.CreatorId == userId

15
modules/cms-kit/src/Volo.CmsKit.MongoDB/Volo/CmsKit/MongoDB/Pages/MongoPageRepository.cs

@ -26,8 +26,8 @@ public class MongoPageRepository : MongoDbRepository<ICmsKitMongoDbContext, Page
{ {
var cancellation = GetCancellationToken(cancellationToken); var cancellation = GetCancellationToken(cancellationToken);
return await (await GetMongoQueryableAsync(cancellation)) return await (await GetQueryableAsync(cancellation))
.WhereIf<Page, IMongoQueryable<Page>>( .WhereIf(
!filter.IsNullOrWhiteSpace(), !filter.IsNullOrWhiteSpace(),
u => u =>
u.Title.ToLower().Contains(filter.ToLower()) || u.Slug.Contains(filter) u.Title.ToLower().Contains(filter.ToLower()) || u.Slug.Contains(filter)
@ -43,13 +43,12 @@ public class MongoPageRepository : MongoDbRepository<ICmsKitMongoDbContext, Page
{ {
var cancellation = GetCancellationToken(cancellationToken); var cancellation = GetCancellationToken(cancellationToken);
return await (await GetMongoQueryableAsync(cancellation)) return await (await GetQueryableAsync(cancellation))
.WhereIf<Page, IMongoQueryable<Page>>( .WhereIf(
!filter.IsNullOrWhiteSpace(), !filter.IsNullOrWhiteSpace(),
u => u.Title.ToLower().Contains(filter) || u.Slug.Contains(filter)) u => u.Title.ToLower().Contains(filter) || u.Slug.Contains(filter))
.OrderBy(sorting.IsNullOrEmpty() ? nameof(Page.Title) : sorting) .OrderBy(sorting.IsNullOrEmpty() ? nameof(Page.Title) : sorting)
.As<IMongoQueryable<Page>>() .PageBy(skipCount, maxResultCount)
.PageBy<Page, IMongoQueryable<Page>>(skipCount, maxResultCount)
.ToListAsync(cancellation); .ToListAsync(cancellation);
} }
@ -68,7 +67,7 @@ public class MongoPageRepository : MongoDbRepository<ICmsKitMongoDbContext, Page
public virtual async Task<bool> ExistsAsync([NotNull] string slug, CancellationToken cancellationToken = default) public virtual async Task<bool> ExistsAsync([NotNull] string slug, CancellationToken cancellationToken = default)
{ {
Check.NotNullOrEmpty(slug, nameof(slug)); 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)); GetCancellationToken(cancellationToken));
} }
@ -79,7 +78,7 @@ public class MongoPageRepository : MongoDbRepository<ICmsKitMongoDbContext, Page
public async Task<string?> FindTitleAsync(Guid pageId, CancellationToken cancellationToken = default) public async Task<string?> 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); .FirstOrDefaultAsync(cancellationToken);
} }
} }

4
modules/cms-kit/src/Volo.CmsKit.MongoDB/Volo/CmsKit/MongoDB/Ratings/MongoRatingRepository.cs

@ -25,7 +25,7 @@ public class MongoRatingRepository : MongoDbRepository<ICmsKitMongoDbContext, Ra
Check.NotNullOrWhiteSpace(entityType, nameof(entityType)); Check.NotNullOrWhiteSpace(entityType, nameof(entityType));
Check.NotNullOrWhiteSpace(entityId, nameof(entityId)); Check.NotNullOrWhiteSpace(entityId, nameof(entityId));
var rating = await (await GetMongoQueryableAsync(cancellationToken)) var rating = await (await GetQueryableAsync(cancellationToken))
.FirstOrDefaultAsync(r => r.EntityType == entityType && r.EntityId == entityId && r.CreatorId == userId, .FirstOrDefaultAsync(r => r.EntityType == entityType && r.EntityId == entityId && r.CreatorId == userId,
GetCancellationToken(cancellationToken)); GetCancellationToken(cancellationToken));
@ -39,7 +39,7 @@ public class MongoRatingRepository : MongoDbRepository<ICmsKitMongoDbContext, Ra
Check.NotNullOrWhiteSpace(entityId, nameof(entityId)); Check.NotNullOrWhiteSpace(entityId, nameof(entityId));
var query = ( var query = (
from rating in (await GetMongoQueryableAsync(cancellationToken)) from rating in (await GetQueryableAsync(cancellationToken))
where rating.EntityType == entityType && rating.EntityId == entityId where rating.EntityType == entityType && rating.EntityId == entityId
group rating by rating.StarCount group rating by rating.StarCount
into g into g

6
modules/cms-kit/src/Volo.CmsKit.MongoDB/Volo/CmsKit/MongoDB/Reactions/MongoUserReactionRepository.cs

@ -29,7 +29,7 @@ public class MongoUserReactionRepository : MongoDbRepository<ICmsKitMongoDbConte
Check.NotNullOrWhiteSpace(entityId, nameof(entityId)); Check.NotNullOrWhiteSpace(entityId, nameof(entityId));
Check.NotNullOrWhiteSpace(reactionName, nameof(reactionName)); Check.NotNullOrWhiteSpace(reactionName, nameof(reactionName));
return await (await GetMongoQueryableAsync(cancellationToken)) return await (await GetQueryableAsync(cancellationToken))
.Where(x => .Where(x =>
x.CreatorId == userId && x.CreatorId == userId &&
x.EntityType == entityType && x.EntityType == entityType &&
@ -47,7 +47,7 @@ public class MongoUserReactionRepository : MongoDbRepository<ICmsKitMongoDbConte
Check.NotNullOrWhiteSpace(entityType, nameof(entityType)); Check.NotNullOrWhiteSpace(entityType, nameof(entityType));
Check.NotNullOrWhiteSpace(entityId, nameof(entityId)); Check.NotNullOrWhiteSpace(entityId, nameof(entityId));
return await (await GetMongoQueryableAsync(cancellationToken)) return await (await GetQueryableAsync(cancellationToken))
.Where(x => .Where(x =>
x.CreatorId == userId && x.CreatorId == userId &&
x.EntityType == entityType && x.EntityType == entityType &&
@ -63,7 +63,7 @@ public class MongoUserReactionRepository : MongoDbRepository<ICmsKitMongoDbConte
Check.NotNullOrWhiteSpace(entityType, nameof(entityType)); Check.NotNullOrWhiteSpace(entityType, nameof(entityType));
Check.NotNullOrWhiteSpace(entityId, nameof(entityId)); Check.NotNullOrWhiteSpace(entityId, nameof(entityId));
return await (await GetMongoQueryableAsync(cancellationToken)) return await (await GetQueryableAsync(cancellationToken))
.Where(x => .Where(x =>
x.EntityType == entityType && x.EntityType == entityType &&
x.EntityId == entityId) x.EntityId == entityId)

2
modules/cms-kit/src/Volo.CmsKit.MongoDB/Volo/CmsKit/MongoDB/Tags/MongoEntityTagRepository.cs

@ -67,7 +67,7 @@ public class MongoEntityTagRepository : MongoDbRepository<ICmsKitMongoDbContext,
CancellationToken cancellationToken = default) CancellationToken cancellationToken = default)
{ {
var dbContext = await GetDbContextAsync(); var dbContext = await GetDbContextAsync();
var entityTagQueryable = await GetMongoQueryableAsync(GetCancellationToken(cancellationToken)); var entityTagQueryable = await GetQueryableAsync(GetCancellationToken(cancellationToken));
var tagQueryable = dbContext.Tags.AsQueryable(); var tagQueryable = dbContext.Tags.AsQueryable();
var resultQueryable = entityTagQueryable var resultQueryable = entityTagQueryable

17
modules/cms-kit/src/Volo.CmsKit.MongoDB/Volo/CmsKit/MongoDB/Tags/MongoTagRepository.cs

@ -29,7 +29,7 @@ public class MongoTagRepository : MongoDbRepository<ICmsKitMongoDbContext, Volo.
Check.NotNullOrEmpty(entityType, nameof(entityType)); Check.NotNullOrEmpty(entityType, nameof(entityType));
Check.NotNullOrEmpty(name, nameof(name)); Check.NotNullOrEmpty(name, nameof(name));
return await (await GetMongoQueryableAsync(cancellationToken)) return await (await GetQueryableAsync(cancellationToken))
.AnyAsync(x => .AnyAsync(x =>
x.EntityType == entityType && x.EntityType == entityType &&
x.Name == name, x.Name == name,
@ -69,12 +69,12 @@ public class MongoTagRepository : MongoDbRepository<ICmsKitMongoDbContext, Volo.
Check.NotNullOrEmpty(entityType, nameof(entityType)); Check.NotNullOrEmpty(entityType, nameof(entityType));
Check.NotNullOrEmpty(entityId, nameof(entityId)); Check.NotNullOrEmpty(entityId, nameof(entityId));
var entityTagIds = await (await GetMongoQueryableAsync<EntityTag>(cancellationToken)) var entityTagIds = await (await GetQueryableAsync<EntityTag>(cancellationToken))
.Where(q => q.EntityId == entityId) .Where(q => q.EntityId == entityId)
.Select(q => q.TagId) .Select(q => q.TagId)
.ToListAsync(cancellationToken: GetCancellationToken(cancellationToken)); .ToListAsync(cancellationToken: GetCancellationToken(cancellationToken));
var query = (await GetMongoQueryableAsync(cancellationToken)) var query = (await GetQueryableAsync(cancellationToken))
.Where(x => .Where(x =>
x.EntityType == entityType && x.EntityType == entityType &&
entityTagIds.Contains(x.Id)); entityTagIds.Contains(x.Id));
@ -86,14 +86,14 @@ public class MongoTagRepository : MongoDbRepository<ICmsKitMongoDbContext, Volo.
public virtual async Task<List<PopularTag>> GetPopularTagsAsync(string entityType, int maxCount, CancellationToken cancellationToken = default) public virtual async Task<List<PopularTag>> 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) .Where(x => x.EntityType == entityType)
.Select(x => new { x.Id, x.Name }) .Select(x => new { x.Id, x.Name })
.ToListAsync(cancellationToken: GetCancellationToken(cancellationToken)); .ToListAsync(cancellationToken: GetCancellationToken(cancellationToken));
var tagIds = tags.Select(x => x.Id); var tagIds = tags.Select(x => x.Id);
var entityTagCounts = await (await GetMongoQueryableAsync<EntityTag>(cancellationToken)) var entityTagCounts = await (await GetQueryableAsync<EntityTag>(cancellationToken))
.Where(q => tagIds.Contains(q.TagId)) .Where(q => tagIds.Contains(q.TagId))
.GroupBy(q => q.TagId) .GroupBy(q => q.TagId)
.Select(q => new { TagId = q.Key, Count = q.Count() }) .Select(q => new { TagId = q.Key, Count = q.Count() })
@ -116,8 +116,7 @@ public class MongoTagRepository : MongoDbRepository<ICmsKitMongoDbContext, Volo.
{ {
return await (await GetQueryableByFilterAsync(filter, cancellationToken)) return await (await GetQueryableByFilterAsync(filter, cancellationToken))
.OrderBy(sorting.IsNullOrEmpty() ? $"{nameof(Tag.CreationTime)}" : sorting) .OrderBy(sorting.IsNullOrEmpty() ? $"{nameof(Tag.CreationTime)}" : sorting)
.As<IMongoQueryable<Tag>>() .PageBy(skipCount, maxResultCount)
.PageBy<Tag, IMongoQueryable<Tag>>(skipCount, maxResultCount)
.ToListAsync(GetCancellationToken(cancellationToken)); .ToListAsync(GetCancellationToken(cancellationToken));
} }
@ -126,9 +125,9 @@ public class MongoTagRepository : MongoDbRepository<ICmsKitMongoDbContext, Volo.
return await (await GetQueryableByFilterAsync(filter, cancellationToken)).CountAsync(GetCancellationToken(cancellationToken)); return await (await GetQueryableByFilterAsync(filter, cancellationToken)).CountAsync(GetCancellationToken(cancellationToken));
} }
private async Task<IMongoQueryable<Tag>> GetQueryableByFilterAsync(string filter, CancellationToken cancellationToken = default) private async Task<IQueryable<Tag>> GetQueryableByFilterAsync(string filter, CancellationToken cancellationToken = default)
{ {
var mongoQueryable = await GetMongoQueryableAsync(cancellationToken: cancellationToken); var mongoQueryable = await GetQueryableAsync(cancellationToken: cancellationToken);
if (!filter.IsNullOrWhiteSpace()) if (!filter.IsNullOrWhiteSpace())
{ {

2
modules/cms-kit/test/Volo.CmsKit.MongoDB.Tests/MongoDB/MongoDbFixture.cs

@ -1,5 +1,5 @@
using System; using System;
using EphemeralMongo; using MongoSandbox;
namespace Volo.CmsKit.MongoDB; namespace Volo.CmsKit.MongoDB;

8
modules/cms-kit/test/Volo.CmsKit.MongoDB.Tests/Volo.CmsKit.MongoDB.Tests.csproj

@ -7,10 +7,10 @@
<ItemGroup> <ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" /> <PackageReference Include="Microsoft.NET.Test.Sdk" />
<PackageReference Include="EphemeralMongo.Core" /> <PackageReference Include="MongoSandbox.Core" />
<PackageReference Include="EphemeralMongo6.runtime.linux-x64" Condition="$([MSBuild]::IsOSPlatform('Linux'))" /> <PackageReference Include="MongoSandbox6.runtime.linux-x64" Condition="$([MSBuild]::IsOSPlatform('Linux'))" />
<PackageReference Include="EphemeralMongo6.runtime.osx-x64" Condition="$([MSBuild]::IsOSPlatform('OSX'))" /> <PackageReference Include="MongoSandbox6.runtime.osx-x64" Condition="$([MSBuild]::IsOSPlatform('OSX'))" />
<PackageReference Include="EphemeralMongo6.runtime.win-x64" Condition="$([MSBuild]::IsOSPlatform('Windows'))" /> <PackageReference Include="MongoSandbox6.runtime.win-x64" Condition="$([MSBuild]::IsOSPlatform('Windows'))" />
<ProjectReference Include="..\..\src\Volo.CmsKit.MongoDB\Volo.CmsKit.MongoDB.csproj" /> <ProjectReference Include="..\..\src\Volo.CmsKit.MongoDB\Volo.CmsKit.MongoDB.csproj" />
<ProjectReference Include="..\Volo.CmsKit.TestBase\Volo.CmsKit.TestBase.csproj" /> <ProjectReference Include="..\Volo.CmsKit.TestBase\Volo.CmsKit.TestBase.csproj" />
</ItemGroup> </ItemGroup>

108
modules/docs/src/Volo.Docs.MongoDB/Volo/Docs/Documents/MongoDocumentRepository.cs

@ -22,7 +22,7 @@ namespace Volo.Docs.Documents
public virtual async Task<List<DocumentWithoutDetails>> GetListWithoutDetailsByProjectId(Guid projectId, CancellationToken cancellationToken = default) public virtual async Task<List<DocumentWithoutDetails>> GetListWithoutDetailsByProjectId(Guid projectId, CancellationToken cancellationToken = default)
{ {
return await (await GetMongoQueryableAsync(cancellationToken)) return await (await GetQueryableAsync(cancellationToken))
.Where(d => d.ProjectId == projectId) .Where(d => d.ProjectId == projectId)
.Select(x => new DocumentWithoutDetails .Select(x => new DocumentWithoutDetails
{ {
@ -37,7 +37,7 @@ namespace Volo.Docs.Documents
public virtual async Task<List<DocumentInfo>> GetUniqueListDocumentInfoAsync(CancellationToken cancellationToken = default) public virtual async Task<List<DocumentInfo>> GetUniqueListDocumentInfoAsync(CancellationToken cancellationToken = default)
{ {
return await (await GetMongoQueryableAsync(cancellationToken)) return await (await GetQueryableAsync(cancellationToken))
.Select(x=> new DocumentInfo { .Select(x=> new DocumentInfo {
ProjectId = x.ProjectId, ProjectId = x.ProjectId,
Version = x.Version, Version = x.Version,
@ -51,13 +51,13 @@ namespace Volo.Docs.Documents
public virtual async Task<List<Document>> GetListByProjectId(Guid projectId, CancellationToken cancellationToken = default) public virtual async Task<List<Document>> 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<List<Document>> GetUniqueDocumentsByProjectIdPagedAsync(Guid projectId, int skipCount, int maxResultCount, public virtual async Task<List<Document>> GetUniqueDocumentsByProjectIdPagedAsync(Guid projectId, int skipCount, int maxResultCount,
CancellationToken cancellationToken = default) CancellationToken cancellationToken = default)
{ {
return await (await GetMongoQueryableAsync(cancellationToken)) return await (await GetQueryableAsync(cancellationToken))
.Where(d => d.ProjectId == projectId) .Where(d => d.ProjectId == projectId)
.OrderBy(x => x.LastCachedTime) .OrderBy(x => x.LastCachedTime)
.GroupBy(x => new { x.Name, x.LanguageCode, x.Version }) .GroupBy(x => new { x.Name, x.LanguageCode, x.Version })
@ -69,7 +69,7 @@ namespace Volo.Docs.Documents
public virtual async Task<long> GetUniqueDocumentCountByProjectIdAsync(Guid projectId, CancellationToken cancellationToken = default) public virtual async Task<long> 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 }) .GroupBy(x => new { x.Name, x.LanguageCode, x.Version })
.LongCountAsync(GetCancellationToken(cancellationToken)); .LongCountAsync(GetCancellationToken(cancellationToken));
} }
@ -89,17 +89,18 @@ namespace Volo.Docs.Documents
bool includeDetails = true, bool includeDetails = true,
CancellationToken cancellationToken = default) CancellationToken cancellationToken = default)
{ {
return await (await GetMongoQueryableAsync(cancellationToken)).FirstOrDefaultAsync(x => x.ProjectId == projectId && return await (await GetQueryableAsync(cancellationToken)).FirstOrDefaultAsync(x =>
x.Name == name && x.ProjectId == projectId &&
x.LanguageCode == languageCode && x.Name == name &&
x.Version == version, GetCancellationToken(cancellationToken)); x.LanguageCode == languageCode &&
x.Version == version, GetCancellationToken(cancellationToken));
} }
public virtual async Task<Document> FindAsync(Guid projectId, List<string> possibleNames, string languageCode, string version, public virtual async Task<Document> FindAsync(Guid projectId, List<string> possibleNames, string languageCode, string version,
bool includeDetails = true, bool includeDetails = true,
CancellationToken cancellationToken = default) 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) && possibleNames.Contains(x.Name) &&
x.LanguageCode == languageCode && x.LanguageCode == languageCode &&
x.Version == version, GetCancellationToken(cancellationToken)); x.Version == version, GetCancellationToken(cancellationToken));
@ -114,11 +115,10 @@ namespace Volo.Docs.Documents
public virtual async Task<List<Document>> GetListAsync(Guid? projectId, string version, string name, CancellationToken cancellationToken = default) public virtual async Task<List<Document>> 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(version != null, x => x.Version == version)
.WhereIf(name != null, x => x.Name == name) .WhereIf(name != null, x => x.Name == name)
.WhereIf(projectId.HasValue, x => x.ProjectId == projectId) .WhereIf(projectId.HasValue, x => x.ProjectId == projectId)
.As<IMongoQueryable<Document>>()
.ToListAsync(GetCancellationToken(cancellationToken)); .ToListAsync(GetCancellationToken(cancellationToken));
} }
@ -142,26 +142,25 @@ namespace Volo.Docs.Documents
int skipCount = 0, int skipCount = 0,
CancellationToken cancellationToken = default) CancellationToken cancellationToken = default)
{ {
return await return await
(await ApplyFilterForGetAll( (await ApplyFilterForGetAll(
await GetMongoQueryableAsync(cancellationToken), await GetQueryableAsync(cancellationToken),
projectId: projectId, projectId: projectId,
name: name, name: name,
version: version, version: version,
languageCode: languageCode, languageCode: languageCode,
fileName: fileName, fileName: fileName,
format: format, format: format,
creationTimeMin: creationTimeMin, creationTimeMin: creationTimeMin,
creationTimeMax: creationTimeMax, creationTimeMax: creationTimeMax,
lastUpdatedTimeMin: lastUpdatedTimeMin, lastUpdatedTimeMin: lastUpdatedTimeMin,
lastUpdatedTimeMax: lastUpdatedTimeMax, lastUpdatedTimeMax: lastUpdatedTimeMax,
lastSignificantUpdateTimeMin: lastSignificantUpdateTimeMin, lastSignificantUpdateTimeMin: lastSignificantUpdateTimeMin,
lastSignificantUpdateTimeMax: lastSignificantUpdateTimeMax, lastSignificantUpdateTimeMax: lastSignificantUpdateTimeMax,
lastCachedTimeMin: lastCachedTimeMin, lastCachedTimeMax: lastCachedTimeMax)) lastCachedTimeMin: lastCachedTimeMin, lastCachedTimeMax: lastCachedTimeMax, cancellationToken: cancellationToken))
.OrderBy(string.IsNullOrWhiteSpace(sorting) ? "name asc" : sorting).As<IMongoQueryable<DocumentWithoutContent>>() .OrderBy(string.IsNullOrWhiteSpace(sorting) ? "name asc" : sorting)
.PageBy<DocumentWithoutContent, IMongoQueryable<DocumentWithoutContent>>(skipCount, maxResultCount) .PageBy(skipCount, maxResultCount)
.ToListAsync(GetCancellationToken(cancellationToken)); .ToListAsync(GetCancellationToken(cancellationToken));
} }
public virtual async Task<long> GetAllCountAsync( public virtual async Task<long> GetAllCountAsync(
@ -184,36 +183,35 @@ namespace Volo.Docs.Documents
int skipCount = 0, int skipCount = 0,
CancellationToken cancellationToken = default) CancellationToken cancellationToken = default)
{ {
return await return await
(await ApplyFilterForGetAll( (await ApplyFilterForGetAll(
await GetMongoQueryableAsync(cancellationToken), await GetQueryableAsync(cancellationToken),
projectId: projectId, projectId: projectId,
name: name, name: name,
version: version, version: version,
languageCode: languageCode, languageCode: languageCode,
fileName: fileName, fileName: fileName,
format: format, format: format,
creationTimeMin: creationTimeMin, creationTimeMin: creationTimeMin,
creationTimeMax: creationTimeMax, creationTimeMax: creationTimeMax,
lastUpdatedTimeMin: lastUpdatedTimeMin, lastUpdatedTimeMin: lastUpdatedTimeMin,
lastUpdatedTimeMax: lastUpdatedTimeMax, lastUpdatedTimeMax: lastUpdatedTimeMax,
lastSignificantUpdateTimeMin: lastSignificantUpdateTimeMin, lastSignificantUpdateTimeMin: lastSignificantUpdateTimeMin,
lastSignificantUpdateTimeMax: lastSignificantUpdateTimeMax, lastSignificantUpdateTimeMax: lastSignificantUpdateTimeMax,
lastCachedTimeMin: lastCachedTimeMin, lastCachedTimeMax: lastCachedTimeMax)) lastCachedTimeMin: lastCachedTimeMin, lastCachedTimeMax: lastCachedTimeMax,
.OrderBy(string.IsNullOrWhiteSpace(sorting) ? "name asc" : sorting).As<IMongoQueryable<Document>>() cancellationToken: cancellationToken))
.PageBy<Document, IMongoQueryable<Document>>(skipCount, maxResultCount) .OrderBy(string.IsNullOrWhiteSpace(sorting) ? "name asc" : sorting)
.LongCountAsync(GetCancellationToken(cancellationToken)); .PageBy(skipCount, maxResultCount)
.LongCountAsync(GetCancellationToken(cancellationToken));
} }
public virtual async Task<Document> GetAsync(Guid id, CancellationToken cancellationToken = default) public virtual async Task<Document> 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<IMongoQueryable<DocumentWithoutContent>> ApplyFilterForGetAll( protected virtual async Task<IQueryable<DocumentWithoutContent>> ApplyFilterForGetAll(
IMongoQueryable<Document> query, IQueryable<Document> query,
Guid? projectId, Guid? projectId,
string name, string name,
string version, string version,
@ -254,7 +252,7 @@ namespace Volo.Docs.Documents
{ {
query = query.Where(d => d.FileName != null && d.FileName.Contains(fileName)); query = query.Where(d => d.FileName != null && d.FileName.Contains(fileName));
} }
if (format != null) if (format != null)
{ {
query = query.Where(d => d.Format != null && d.Format == format); query = query.Where(d => d.Format != null && d.Format == format);

9
modules/docs/src/Volo.Docs.MongoDB/Volo/Docs/Projects/MongoProjectRepository.cs

@ -22,8 +22,7 @@ namespace Volo.Docs.Projects
public virtual async Task<List<Project>> GetListAsync(string sorting, int maxResultCount, int skipCount, CancellationToken cancellationToken = default) public virtual async Task<List<Project>> GetListAsync(string sorting, int maxResultCount, int skipCount, CancellationToken cancellationToken = default)
{ {
var projects = await (await GetMongoQueryableAsync(cancellationToken)).OrderBy(sorting.IsNullOrEmpty() ? "Id desc" : sorting).As<IMongoQueryable<Project>>() var projects = await (await GetQueryableAsync(cancellationToken)).OrderBy(sorting.IsNullOrEmpty() ? "Id desc" : sorting).PageBy(skipCount, maxResultCount)
.PageBy<Project, IMongoQueryable<Project>>(skipCount, maxResultCount)
.ToListAsync(GetCancellationToken(cancellationToken)); .ToListAsync(GetCancellationToken(cancellationToken));
return projects; return projects;
@ -31,7 +30,7 @@ namespace Volo.Docs.Projects
public virtual async Task<List<ProjectWithoutDetails>> GetListWithoutDetailsAsync(CancellationToken cancellationToken = default) public virtual async Task<List<ProjectWithoutDetails>> GetListWithoutDetailsAsync(CancellationToken cancellationToken = default)
{ {
return await (await GetMongoQueryableAsync(cancellationToken)) return await (await GetQueryableAsync(cancellationToken))
.Select(x=> new ProjectWithoutDetails { .Select(x=> new ProjectWithoutDetails {
Id = x.Id, Id = x.Id,
Name = x.Name, Name = x.Name,
@ -44,7 +43,7 @@ namespace Volo.Docs.Projects
{ {
var normalizeShortName = NormalizeShortName(shortName); 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) if (project == null)
{ {
@ -58,7 +57,7 @@ namespace Volo.Docs.Projects
{ {
var normalizeShortName = NormalizeShortName(shortName); 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) private string NormalizeShortName(string shortName)

8
modules/docs/test/Volo.Docs.MongoDB.Tests/Volo.Docs.MongoDB.Tests.csproj

@ -7,10 +7,10 @@
<ItemGroup> <ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" /> <PackageReference Include="Microsoft.NET.Test.Sdk" />
<PackageReference Include="EphemeralMongo.Core" /> <PackageReference Include="MongoSandbox.Core" />
<PackageReference Include="EphemeralMongo6.runtime.linux-x64" Condition="$([MSBuild]::IsOSPlatform('Linux'))" /> <PackageReference Include="MongoSandbox6.runtime.linux-x64" Condition="$([MSBuild]::IsOSPlatform('Linux'))" />
<PackageReference Include="EphemeralMongo6.runtime.osx-x64" Condition="$([MSBuild]::IsOSPlatform('OSX'))" /> <PackageReference Include="MongoSandbox6.runtime.osx-x64" Condition="$([MSBuild]::IsOSPlatform('OSX'))" />
<PackageReference Include="EphemeralMongo6.runtime.win-x64" Condition="$([MSBuild]::IsOSPlatform('Windows'))" /> <PackageReference Include="MongoSandbox6.runtime.win-x64" Condition="$([MSBuild]::IsOSPlatform('Windows'))" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>

2
modules/docs/test/Volo.Docs.MongoDB.Tests/Volo/Docs/MongoDB/MongoDbFixture.cs

@ -1,5 +1,5 @@
using System; using System;
using EphemeralMongo; using MongoSandbox;
public class MongoDbFixture : IDisposable public class MongoDbFixture : IDisposable
{ {

3
modules/feature-management/src/Volo.Abp.FeatureManagement.MongoDB/Volo/Abp/FeatureManagement/MongoDB/MongoFeatureDefinitionRecordRepository.cs

@ -1,6 +1,7 @@
using System; using System;
using System.Threading; using System.Threading;
using System.Threading.Tasks; using System.Threading.Tasks;
using System.Linq;
using MongoDB.Driver.Linq; using MongoDB.Driver.Linq;
using Volo.Abp.Domain.Repositories.MongoDB; using Volo.Abp.Domain.Repositories.MongoDB;
using Volo.Abp.MongoDB; using Volo.Abp.MongoDB;
@ -20,7 +21,7 @@ public class MongoFeatureDefinitionRecordRepository :
public virtual async Task<FeatureDefinitionRecord> FindByNameAsync(string name, CancellationToken cancellationToken = default) public virtual async Task<FeatureDefinitionRecord> FindByNameAsync(string name, CancellationToken cancellationToken = default)
{ {
cancellationToken = GetCancellationToken(cancellationToken); cancellationToken = GetCancellationToken(cancellationToken);
return await (await GetMongoQueryableAsync(cancellationToken)) return await (await GetQueryableAsync(cancellationToken))
.OrderBy(x => x.Id) .OrderBy(x => x.Id)
.FirstOrDefaultAsync( .FirstOrDefaultAsync(
s => s.Name == name, s => s.Name == name,

6
modules/feature-management/src/Volo.Abp.FeatureManagement.MongoDB/Volo/Abp/FeatureManagement/MongoDB/MongoFeatureValueRepository.cs

@ -27,7 +27,7 @@ public class MongoFeatureValueRepository :
string providerKey, string providerKey,
CancellationToken cancellationToken = default) CancellationToken cancellationToken = default)
{ {
return await (await GetMongoQueryableAsync(cancellationToken)) return await (await GetQueryableAsync(cancellationToken))
.OrderBy(x => x.Id) .OrderBy(x => x.Id)
.FirstOrDefaultAsync(s => s.Name == name && s.ProviderName == providerName && s.ProviderKey == providerKey, GetCancellationToken(cancellationToken)); .FirstOrDefaultAsync(s => s.Name == name && s.ProviderName == providerName && s.ProviderKey == providerKey, GetCancellationToken(cancellationToken));
} }
@ -38,7 +38,7 @@ public class MongoFeatureValueRepository :
string providerKey, string providerKey,
CancellationToken cancellationToken = default) 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)); .Where(s => s.Name == name && s.ProviderName == providerName && s.ProviderKey == providerKey).ToListAsync(GetCancellationToken(cancellationToken));
} }
@ -47,7 +47,7 @@ public class MongoFeatureValueRepository :
string providerKey, string providerKey,
CancellationToken cancellationToken = default) CancellationToken cancellationToken = default)
{ {
return await (await GetMongoQueryableAsync(cancellationToken)) return await (await GetQueryableAsync(cancellationToken))
.Where(s => s.ProviderName == providerName && s.ProviderKey == providerKey) .Where(s => s.ProviderName == providerName && s.ProviderKey == providerKey)
.ToListAsync(GetCancellationToken(cancellationToken)); .ToListAsync(GetCancellationToken(cancellationToken));
} }

8
modules/feature-management/test/Volo.Abp.FeatureManagement.MongoDB.Tests/Volo.Abp.FeatureManagement.MongoDB.Tests.csproj

@ -14,10 +14,10 @@
<ItemGroup> <ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" /> <PackageReference Include="Microsoft.NET.Test.Sdk" />
<PackageReference Include="EphemeralMongo.Core" /> <PackageReference Include="MongoSandbox.Core" />
<PackageReference Include="EphemeralMongo6.runtime.linux-x64" Condition="$([MSBuild]::IsOSPlatform('Linux'))" /> <PackageReference Include="MongoSandbox6.runtime.linux-x64" Condition="$([MSBuild]::IsOSPlatform('Linux'))" />
<PackageReference Include="EphemeralMongo6.runtime.osx-x64" Condition="$([MSBuild]::IsOSPlatform('OSX'))" /> <PackageReference Include="MongoSandbox6.runtime.osx-x64" Condition="$([MSBuild]::IsOSPlatform('OSX'))" />
<PackageReference Include="EphemeralMongo6.runtime.win-x64" Condition="$([MSBuild]::IsOSPlatform('Windows'))" /> <PackageReference Include="MongoSandbox6.runtime.win-x64" Condition="$([MSBuild]::IsOSPlatform('Windows'))" />
</ItemGroup> </ItemGroup>
</Project> </Project>

2
modules/feature-management/test/Volo.Abp.FeatureManagement.MongoDB.Tests/Volo/Abp/FeatureManagement/MongoDB/MongoDbFixture.cs

@ -1,5 +1,5 @@
using System; using System;
using EphemeralMongo; using MongoSandbox;
namespace Volo.Abp.FeatureManagement.MongoDB; namespace Volo.Abp.FeatureManagement.MongoDB;

18
modules/identity/src/Volo.Abp.Identity.MongoDB/Volo/Abp/Identity/MongoDB/MongoIdentityClaimTypeRepository.cs

@ -24,13 +24,13 @@ public class MongoIdentityClaimTypeRepository : MongoDbRepository<IAbpIdentityMo
{ {
if (ignoredId == null) if (ignoredId == null)
{ {
return await (await GetMongoQueryableAsync(cancellationToken)) return await (await GetQueryableAsync(cancellationToken))
.Where(ct => ct.Name == name) .Where(ct => ct.Name == name)
.AnyAsync(GetCancellationToken(cancellationToken)); .AnyAsync(GetCancellationToken(cancellationToken));
} }
else else
{ {
return await (await GetMongoQueryableAsync(cancellationToken)) return await (await GetQueryableAsync(cancellationToken))
.Where(ct => ct.Id != ignoredId && ct.Name == name) .Where(ct => ct.Id != ignoredId && ct.Name == name)
.AnyAsync(GetCancellationToken(cancellationToken)); .AnyAsync(GetCancellationToken(cancellationToken));
} }
@ -43,15 +43,14 @@ public class MongoIdentityClaimTypeRepository : MongoDbRepository<IAbpIdentityMo
string filter, string filter,
CancellationToken cancellationToken = default) CancellationToken cancellationToken = default)
{ {
return await (await GetMongoQueryableAsync(cancellationToken)) return await (await GetQueryableAsync(cancellationToken))
.WhereIf<IdentityClaimType, IMongoQueryable<IdentityClaimType>>( .WhereIf(
!filter.IsNullOrWhiteSpace(), !filter.IsNullOrWhiteSpace(),
u => u =>
u.Name.Contains(filter) u.Name.Contains(filter)
) )
.OrderBy(sorting.IsNullOrWhiteSpace() ? nameof(IdentityClaimType.CreationTime) + " desc" : sorting) .OrderBy(sorting.IsNullOrWhiteSpace() ? nameof(IdentityClaimType.CreationTime) + " desc" : sorting)
.As<IMongoQueryable<IdentityClaimType>>() .PageBy(skipCount, maxResultCount)
.PageBy<IdentityClaimType, IMongoQueryable<IdentityClaimType>>(skipCount, maxResultCount)
.ToListAsync(GetCancellationToken(cancellationToken)); .ToListAsync(GetCancellationToken(cancellationToken));
} }
@ -59,19 +58,18 @@ public class MongoIdentityClaimTypeRepository : MongoDbRepository<IAbpIdentityMo
string filter = null, string filter = null,
CancellationToken cancellationToken = default) CancellationToken cancellationToken = default)
{ {
return await (await GetMongoQueryableAsync(cancellationToken)) return await (await GetQueryableAsync(cancellationToken))
.WhereIf<IdentityClaimType, IMongoQueryable<IdentityClaimType>>( .WhereIf(
!filter.IsNullOrWhiteSpace(), !filter.IsNullOrWhiteSpace(),
u => u =>
u.Name.Contains(filter) u.Name.Contains(filter)
) )
.As<IMongoQueryable<IdentityClaimType>>()
.LongCountAsync(GetCancellationToken(cancellationToken)); .LongCountAsync(GetCancellationToken(cancellationToken));
} }
public virtual async Task<List<IdentityClaimType>> GetListByNamesAsync(IEnumerable<string> names, CancellationToken cancellationToken = default) public virtual async Task<List<IdentityClaimType>> GetListByNamesAsync(IEnumerable<string> names, CancellationToken cancellationToken = default)
{ {
return await (await GetMongoQueryableAsync(cancellationToken)) return await (await GetQueryableAsync(cancellationToken))
.Where(x => names.Contains(x.Name)) .Where(x => names.Contains(x.Name))
.ToListAsync(GetCancellationToken(cancellationToken)); .ToListAsync(GetCancellationToken(cancellationToken));
} }

6
modules/identity/src/Volo.Abp.Identity.MongoDB/Volo/Abp/Identity/MongoDB/MongoIdentityLinkUserRepository.cs

@ -18,7 +18,7 @@ public class MongoIdentityLinkUserRepository : MongoDbRepository<IAbpIdentityMon
public virtual async Task<IdentityLinkUser> FindAsync(IdentityLinkUserInfo sourceLinkUserInfo, IdentityLinkUserInfo targetLinkUserInfo, CancellationToken cancellationToken = default) public virtual async Task<IdentityLinkUser> FindAsync(IdentityLinkUserInfo sourceLinkUserInfo, IdentityLinkUserInfo targetLinkUserInfo, CancellationToken cancellationToken = default)
{ {
return await (await GetMongoQueryableAsync(cancellationToken)) return await (await GetQueryableAsync(cancellationToken))
.OrderBy(x => x.Id).FirstOrDefaultAsync(x => .OrderBy(x => x.Id).FirstOrDefaultAsync(x =>
x.SourceUserId == sourceLinkUserInfo.UserId && x.SourceTenantId == sourceLinkUserInfo.TenantId && x.SourceUserId == sourceLinkUserInfo.UserId && x.SourceTenantId == sourceLinkUserInfo.TenantId &&
x.TargetUserId == targetLinkUserInfo.UserId && x.TargetTenantId == targetLinkUserInfo.TenantId || x.TargetUserId == targetLinkUserInfo.UserId && x.TargetTenantId == targetLinkUserInfo.TenantId ||
@ -30,7 +30,7 @@ public class MongoIdentityLinkUserRepository : MongoDbRepository<IAbpIdentityMon
public virtual async Task<List<IdentityLinkUser>> GetListAsync(IdentityLinkUserInfo linkUserInfo, List<IdentityLinkUserInfo> excludes = null, public virtual async Task<List<IdentityLinkUser>> GetListAsync(IdentityLinkUserInfo linkUserInfo, List<IdentityLinkUserInfo> excludes = null,
CancellationToken cancellationToken = default) 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.SourceUserId == linkUserInfo.UserId && x.SourceTenantId == linkUserInfo.TenantId ||
x.TargetUserId == linkUserInfo.UserId && x.TargetTenantId == linkUserInfo.TenantId); x.TargetUserId == linkUserInfo.UserId && x.TargetTenantId == linkUserInfo.TenantId);
@ -49,7 +49,7 @@ public class MongoIdentityLinkUserRepository : MongoDbRepository<IAbpIdentityMon
public virtual async Task DeleteAsync(IdentityLinkUserInfo linkUserInfo, CancellationToken cancellationToken = default) public virtual async Task DeleteAsync(IdentityLinkUserInfo linkUserInfo, CancellationToken cancellationToken = default)
{ {
var linkUsers = await (await GetMongoQueryableAsync(cancellationToken)).Where(x => var linkUsers = await (await GetQueryableAsync(cancellationToken)).Where(x =>
x.SourceUserId == linkUserInfo.UserId && x.SourceTenantId == linkUserInfo.TenantId || x.SourceUserId == linkUserInfo.UserId && x.SourceTenantId == linkUserInfo.TenantId ||
x.TargetUserId == linkUserInfo.UserId && x.TargetTenantId == linkUserInfo.TenantId) x.TargetUserId == linkUserInfo.UserId && x.TargetTenantId == linkUserInfo.TenantId)
.ToListAsync(cancellationToken: GetCancellationToken(cancellationToken)); .ToListAsync(cancellationToken: GetCancellationToken(cancellationToken));

18
modules/identity/src/Volo.Abp.Identity.MongoDB/Volo/Abp/Identity/MongoDB/MongoIdentityRoleRepository.cs

@ -23,7 +23,7 @@ public class MongoIdentityRoleRepository : MongoDbRepository<IAbpIdentityMongoDb
bool includeDetails = true, bool includeDetails = true,
CancellationToken cancellationToken = default) CancellationToken cancellationToken = default)
{ {
return await (await GetMongoQueryableAsync(cancellationToken)) return await (await GetQueryableAsync(cancellationToken))
.OrderBy(x => x.Id) .OrderBy(x => x.Id)
.FirstOrDefaultAsync(r => r.NormalizedName == normalizedRoleName, GetCancellationToken(cancellationToken)); .FirstOrDefaultAsync(r => r.NormalizedName == normalizedRoleName, GetCancellationToken(cancellationToken));
} }
@ -38,7 +38,7 @@ public class MongoIdentityRoleRepository : MongoDbRepository<IAbpIdentityMongoDb
{ {
var roles = await GetListInternalAsync(sorting, maxResultCount, skipCount, filter, includeDetails, cancellationToken: cancellationToken); var roles = await GetListInternalAsync(sorting, maxResultCount, skipCount, filter, includeDetails, cancellationToken: cancellationToken);
var roleIds = roles.Select(x => x.Id).ToList(); var roleIds = roles.Select(x => x.Id).ToList();
var userCount = await (await GetMongoQueryableAsync<IdentityUser>(cancellationToken)) var userCount = await (await GetQueryableAsync<IdentityUser>(cancellationToken))
.Where(user => user.Roles.Any(role => roleIds.Contains(role.RoleId))) .Where(user => user.Roles.Any(role => roleIds.Contains(role.RoleId)))
.SelectMany(user => user.Roles) .SelectMany(user => user.Roles)
.GroupBy(userRole => userRole.RoleId) .GroupBy(userRole => userRole.RoleId)
@ -73,7 +73,7 @@ public class MongoIdentityRoleRepository : MongoDbRepository<IAbpIdentityMongoDb
IEnumerable<Guid> ids, IEnumerable<Guid> ids,
CancellationToken cancellationToken = default) CancellationToken cancellationToken = default)
{ {
return await (await GetMongoQueryableAsync(cancellationToken)) return await (await GetQueryableAsync(cancellationToken))
.Where(t => ids.Contains(t.Id)) .Where(t => ids.Contains(t.Id))
.ToListAsync(GetCancellationToken(cancellationToken)); .ToListAsync(GetCancellationToken(cancellationToken));
} }
@ -82,7 +82,7 @@ public class MongoIdentityRoleRepository : MongoDbRepository<IAbpIdentityMongoDb
bool includeDetails = false, bool includeDetails = false,
CancellationToken cancellationToken = default) CancellationToken cancellationToken = default)
{ {
return await (await GetMongoQueryableAsync(cancellationToken)) return await (await GetQueryableAsync(cancellationToken))
.Where(r => r.IsDefault) .Where(r => r.IsDefault)
.ToListAsync(GetCancellationToken(cancellationToken)); .ToListAsync(GetCancellationToken(cancellationToken));
} }
@ -91,17 +91,16 @@ public class MongoIdentityRoleRepository : MongoDbRepository<IAbpIdentityMongoDb
string filter = null, string filter = null,
CancellationToken cancellationToken = default) CancellationToken cancellationToken = default)
{ {
return await (await GetMongoQueryableAsync(cancellationToken)) return await (await GetQueryableAsync(cancellationToken))
.WhereIf(!filter.IsNullOrWhiteSpace(), .WhereIf(!filter.IsNullOrWhiteSpace(),
x => x.Name.Contains(filter) || x => x.Name.Contains(filter) ||
x.NormalizedName.Contains(filter)) x.NormalizedName.Contains(filter))
.As<IMongoQueryable<IdentityRole>>()
.LongCountAsync(GetCancellationToken(cancellationToken)); .LongCountAsync(GetCancellationToken(cancellationToken));
} }
public virtual async Task RemoveClaimFromAllRolesAsync(string claimType, bool autoSave = false, CancellationToken cancellationToken = default) 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)) .Where(r => r.Claims.Any(c => c.ClaimType == claimType))
.ToListAsync(GetCancellationToken(cancellationToken)); .ToListAsync(GetCancellationToken(cancellationToken));
@ -121,13 +120,12 @@ public class MongoIdentityRoleRepository : MongoDbRepository<IAbpIdentityMongoDb
bool includeDetails = true, bool includeDetails = true,
CancellationToken cancellationToken = default) CancellationToken cancellationToken = default)
{ {
return await (await GetMongoQueryableAsync(cancellationToken)) return await (await GetQueryableAsync(cancellationToken))
.WhereIf(!filter.IsNullOrWhiteSpace(), .WhereIf(!filter.IsNullOrWhiteSpace(),
x => x.Name.Contains(filter) || x => x.Name.Contains(filter) ||
x.NormalizedName.Contains(filter)) x.NormalizedName.Contains(filter))
.OrderBy(sorting.IsNullOrWhiteSpace() ? nameof(IdentityRole.CreationTime) + " desc" : sorting) .OrderBy(sorting.IsNullOrWhiteSpace() ? nameof(IdentityRole.CreationTime) + " desc" : sorting)
.As<IMongoQueryable<IdentityRole>>() .PageBy(skipCount, maxResultCount)
.PageBy<IdentityRole, IMongoQueryable<IdentityRole>>(skipCount, maxResultCount)
.ToListAsync(GetCancellationToken(cancellationToken)); .ToListAsync(GetCancellationToken(cancellationToken));
} }
} }

10
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) return await query.OrderBy(sorting.IsNullOrWhiteSpace() ? $"{nameof(IdentitySecurityLog.CreationTime)} desc" : sorting)
.As<IMongoQueryable<IdentitySecurityLog>>() .PageBy(skipCount, maxResultCount)
.PageBy<IdentitySecurityLog, IMongoQueryable<IdentitySecurityLog>>(skipCount, maxResultCount)
.ToListAsync(GetCancellationToken(cancellationToken)); .ToListAsync(GetCancellationToken(cancellationToken));
} }
@ -83,15 +82,14 @@ public class MongoIdentitySecurityLogRepository :
cancellationToken cancellationToken
); );
return await query.As<IMongoQueryable<IdentitySecurityLog>>() return await query.LongCountAsync(GetCancellationToken(cancellationToken));
.LongCountAsync(GetCancellationToken(cancellationToken));
} }
public virtual async Task<IdentitySecurityLog> GetByUserIdAsync(Guid id, Guid userId, bool includeDetails = false, public virtual async Task<IdentitySecurityLog> GetByUserIdAsync(Guid id, Guid userId, bool includeDetails = false,
CancellationToken cancellationToken = default) 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)); GetCancellationToken(cancellationToken));
} }
@ -108,7 +106,7 @@ public class MongoIdentitySecurityLogRepository :
string clientIpAddress = null, string clientIpAddress = null,
CancellationToken cancellationToken = default) CancellationToken cancellationToken = default)
{ {
return (await GetMongoQueryableAsync(cancellationToken)) return (await GetQueryableAsync(cancellationToken))
.WhereIf(startTime.HasValue, securityLog => securityLog.CreationTime >= startTime.Value) .WhereIf(startTime.HasValue, securityLog => securityLog.CreationTime >= startTime.Value)
.WhereIf(endTime.HasValue, securityLog => securityLog.CreationTime < endTime.Value.AddDays(1).Date) .WhereIf(endTime.HasValue, securityLog => securityLog.CreationTime < endTime.Value.AddDays(1).Date)
.WhereIf(!applicationName.IsNullOrWhiteSpace(), securityLog => securityLog.ApplicationName == applicationName) .WhereIf(!applicationName.IsNullOrWhiteSpace(), securityLog => securityLog.ApplicationName == applicationName)

15
modules/identity/src/Volo.Abp.Identity.MongoDB/Volo/Abp/Identity/MongoDB/MongoIdentitySessionRepository.cs

@ -23,8 +23,7 @@ public class MongoIdentitySessionRepository : MongoDbRepository<IAbpIdentityMong
public virtual async Task<IdentitySession> FindAsync(string sessionId, CancellationToken cancellationToken = default) public virtual async Task<IdentitySession> FindAsync(string sessionId, CancellationToken cancellationToken = default)
{ {
return await (await GetMongoQueryableAsync(GetCancellationToken(cancellationToken))) return await (await GetQueryableAsync(GetCancellationToken(cancellationToken)))
.As<IMongoQueryable<IdentitySession>>()
.FirstOrDefaultAsync(x => x.SessionId == sessionId, GetCancellationToken(cancellationToken)); .FirstOrDefaultAsync(x => x.SessionId == sessionId, GetCancellationToken(cancellationToken));
} }
@ -41,15 +40,13 @@ public class MongoIdentitySessionRepository : MongoDbRepository<IAbpIdentityMong
public virtual async Task<bool> ExistAsync(Guid id, CancellationToken cancellationToken = default) public virtual async Task<bool> ExistAsync(Guid id, CancellationToken cancellationToken = default)
{ {
return await (await GetMongoQueryableAsync(GetCancellationToken(cancellationToken))) return await (await GetQueryableAsync(GetCancellationToken(cancellationToken)))
.As<IMongoQueryable<IdentitySession>>()
.AnyAsync(x => x.Id == id, GetCancellationToken(cancellationToken)); .AnyAsync(x => x.Id == id, GetCancellationToken(cancellationToken));
} }
public virtual async Task<bool> ExistAsync(string sessionId, CancellationToken cancellationToken = default) public virtual async Task<bool> ExistAsync(string sessionId, CancellationToken cancellationToken = default)
{ {
return await (await GetMongoQueryableAsync(GetCancellationToken(cancellationToken))) return await (await GetQueryableAsync(GetCancellationToken(cancellationToken)))
.As<IMongoQueryable<IdentitySession>>()
.AnyAsync(x => x.SessionId == sessionId, GetCancellationToken(cancellationToken)); .AnyAsync(x => x.SessionId == sessionId, GetCancellationToken(cancellationToken));
} }
@ -62,13 +59,12 @@ public class MongoIdentitySessionRepository : MongoDbRepository<IAbpIdentityMong
string clientId = null, string clientId = null,
CancellationToken cancellationToken = default) CancellationToken cancellationToken = default)
{ {
return await (await GetMongoQueryableAsync(GetCancellationToken(cancellationToken))) return await (await GetQueryableAsync(GetCancellationToken(cancellationToken)))
.WhereIf(userId.HasValue, x => x.UserId == userId) .WhereIf(userId.HasValue, x => x.UserId == userId)
.WhereIf(!device.IsNullOrWhiteSpace(), x => x.Device == device) .WhereIf(!device.IsNullOrWhiteSpace(), x => x.Device == device)
.WhereIf(!clientId.IsNullOrWhiteSpace(), x => x.ClientId == clientId) .WhereIf(!clientId.IsNullOrWhiteSpace(), x => x.ClientId == clientId)
.OrderBy(sorting.IsNullOrWhiteSpace() ? $"{nameof(IdentitySession.LastAccessed)} desc" : sorting) .OrderBy(sorting.IsNullOrWhiteSpace() ? $"{nameof(IdentitySession.LastAccessed)} desc" : sorting)
.PageBy(skipCount, maxResultCount) .PageBy(skipCount, maxResultCount)
.As<IMongoQueryable<IdentitySession>>()
.ToListAsync(GetCancellationToken(cancellationToken)); .ToListAsync(GetCancellationToken(cancellationToken));
} }
@ -78,11 +74,10 @@ public class MongoIdentitySessionRepository : MongoDbRepository<IAbpIdentityMong
string clientId = null, string clientId = null,
CancellationToken cancellationToken = default) CancellationToken cancellationToken = default)
{ {
return await (await GetMongoQueryableAsync(GetCancellationToken(cancellationToken))) return await (await GetQueryableAsync(GetCancellationToken(cancellationToken)))
.WhereIf(userId.HasValue, x => x.UserId == userId) .WhereIf(userId.HasValue, x => x.UserId == userId)
.WhereIf(!device.IsNullOrWhiteSpace(), x => x.Device == device) .WhereIf(!device.IsNullOrWhiteSpace(), x => x.Device == device)
.WhereIf(!clientId.IsNullOrWhiteSpace(), x => x.ClientId == clientId) .WhereIf(!clientId.IsNullOrWhiteSpace(), x => x.ClientId == clientId)
.As<IMongoQueryable<IdentitySession>>()
.LongCountAsync(GetCancellationToken(cancellationToken)); .LongCountAsync(GetCancellationToken(cancellationToken));
} }

8
modules/identity/src/Volo.Abp.Identity.MongoDB/Volo/Abp/Identity/MongoDB/MongoIdentityUserDelegationRepository.cs

@ -24,25 +24,23 @@ public class MongoIdentityUserDelegationRepository : MongoDbRepository<IAbpIdent
public virtual async Task<List<IdentityUserDelegation>> GetListAsync(Guid? sourceUserId, Guid? targetUserId, public virtual async Task<List<IdentityUserDelegation>> GetListAsync(Guid? sourceUserId, Guid? targetUserId,
CancellationToken cancellationToken = default) CancellationToken cancellationToken = default)
{ {
return await (await GetMongoQueryableAsync(cancellationToken)) return await (await GetQueryableAsync(cancellationToken))
.WhereIf(sourceUserId.HasValue, x => x.SourceUserId == sourceUserId) .WhereIf(sourceUserId.HasValue, x => x.SourceUserId == sourceUserId)
.WhereIf(targetUserId.HasValue, x => x.TargetUserId == targetUserId) .WhereIf(targetUserId.HasValue, x => x.TargetUserId == targetUserId)
.As<IMongoQueryable<IdentityUserDelegation>>()
.ToListAsync(cancellationToken: cancellationToken); .ToListAsync(cancellationToken: cancellationToken);
} }
public virtual async Task<List<IdentityUserDelegation>> GetActiveDelegationsAsync(Guid targetUserId, CancellationToken cancellationToken = default) public virtual async Task<List<IdentityUserDelegation>> GetActiveDelegationsAsync(Guid targetUserId, CancellationToken cancellationToken = default)
{ {
return await (await GetMongoQueryableAsync(cancellationToken)) return await (await GetQueryableAsync(cancellationToken))
.Where(x => x.TargetUserId == targetUserId) .Where(x => x.TargetUserId == targetUserId)
.Where(x => x.StartTime <= Clock.Now && x.EndTime >= Clock.Now) .Where(x => x.StartTime <= Clock.Now && x.EndTime >= Clock.Now)
.As<IMongoQueryable<IdentityUserDelegation>>()
.ToListAsync(cancellationToken: cancellationToken); .ToListAsync(cancellationToken: cancellationToken);
} }
public virtual async Task<IdentityUserDelegation> FindActiveDelegationByIdAsync(Guid id, CancellationToken cancellationToken = default) public virtual async Task<IdentityUserDelegation> FindActiveDelegationByIdAsync(Guid id, CancellationToken cancellationToken = default)
{ {
return await (await GetMongoQueryableAsync(cancellationToken)) return await (await GetQueryableAsync(cancellationToken))
.FirstOrDefaultAsync(x => .FirstOrDefaultAsync(x =>
x.Id == id && x.Id == id &&
x.StartTime <= Clock.Now && x.StartTime <= Clock.Now &&

91
modules/identity/src/Volo.Abp.Identity.MongoDB/Volo/Abp/Identity/MongoDB/MongoIdentityUserRepository.cs

@ -25,7 +25,7 @@ public class MongoIdentityUserRepository : MongoDbRepository<IAbpIdentityMongoDb
bool includeDetails = true, bool includeDetails = true,
CancellationToken cancellationToken = default) CancellationToken cancellationToken = default)
{ {
return await (await GetMongoQueryableAsync(cancellationToken)) return await (await GetQueryableAsync(cancellationToken))
.OrderBy(x => x.Id) .OrderBy(x => x.Id)
.FirstOrDefaultAsync( .FirstOrDefaultAsync(
u => u.NormalizedUserName == normalizedUserName, u => u.NormalizedUserName == normalizedUserName,
@ -43,13 +43,13 @@ public class MongoIdentityUserRepository : MongoDbRepository<IAbpIdentityMongoDb
.Select(r => r.OrganizationUnitId) .Select(r => r.OrganizationUnitId)
.ToArray(); .ToArray();
var organizationUnits = await (await GetMongoQueryableAsync<OrganizationUnit>(cancellationToken)) var organizationUnits = await (await GetQueryableAsync<OrganizationUnit>(cancellationToken))
.Where(ou => organizationUnitIds.Contains(ou.Id)) .Where(ou => organizationUnitIds.Contains(ou.Id))
.ToListAsync(cancellationToken: cancellationToken); .ToListAsync(cancellationToken: cancellationToken);
var orgUnitRoleIds = organizationUnits.SelectMany(x => x.Roles.Select(r => r.RoleId)).ToArray(); var orgUnitRoleIds = organizationUnits.SelectMany(x => x.Roles.Select(r => r.RoleId)).ToArray();
var roleIds = user.Roles.Select(r => r.RoleId).ToArray(); var roleIds = user.Roles.Select(r => r.RoleId).ToArray();
var allRoleIds = orgUnitRoleIds.Union(roleIds); var allRoleIds = orgUnitRoleIds.Union(roleIds);
return await (await GetMongoQueryableAsync<IdentityRole>(cancellationToken)).Where(r => allRoleIds.Contains(r.Id)).Select(r => r.Name).ToListAsync(cancellationToken); return await (await GetQueryableAsync<IdentityRole>(cancellationToken)).Where(r => allRoleIds.Contains(r.Id)).Select(r => r.Name).ToListAsync(cancellationToken);
} }
public virtual async Task<List<string>> GetRoleNamesInOrganizationUnitAsync( public virtual async Task<List<string>> GetRoleNamesInOrganizationUnitAsync(
@ -63,13 +63,13 @@ public class MongoIdentityUserRepository : MongoDbRepository<IAbpIdentityMongoDb
.Select(r => r.OrganizationUnitId) .Select(r => r.OrganizationUnitId)
.ToArray(); .ToArray();
var organizationUnits = await (await GetMongoQueryableAsync<OrganizationUnit>(cancellationToken)) var organizationUnits = await (await GetQueryableAsync<OrganizationUnit>(cancellationToken))
.Where(ou => organizationUnitIds.Contains(ou.Id)) .Where(ou => organizationUnitIds.Contains(ou.Id))
.ToListAsync(cancellationToken: cancellationToken); .ToListAsync(cancellationToken: cancellationToken);
var roleIds = organizationUnits.SelectMany(x => x.Roles.Select(r => r.RoleId)).ToArray(); var roleIds = organizationUnits.SelectMany(x => x.Roles.Select(r => r.RoleId)).ToArray();
var queryable = await GetMongoQueryableAsync<IdentityRole>(cancellationToken); var queryable = await GetQueryableAsync<IdentityRole>(cancellationToken);
return await queryable return await queryable
.Where(r => roleIds.Contains(r.Id)) .Where(r => roleIds.Contains(r.Id))
@ -83,7 +83,7 @@ public class MongoIdentityUserRepository : MongoDbRepository<IAbpIdentityMongoDb
bool includeDetails = true, bool includeDetails = true,
CancellationToken cancellationToken = default) CancellationToken cancellationToken = default)
{ {
return await (await GetMongoQueryableAsync(cancellationToken)) return await (await GetQueryableAsync(cancellationToken))
.Where(u => u.Logins.Any(login => login.LoginProvider == loginProvider && login.ProviderKey == providerKey)) .Where(u => u.Logins.Any(login => login.LoginProvider == loginProvider && login.ProviderKey == providerKey))
.OrderBy(x => x.Id) .OrderBy(x => x.Id)
.FirstOrDefaultAsync(GetCancellationToken(cancellationToken)); .FirstOrDefaultAsync(GetCancellationToken(cancellationToken));
@ -94,7 +94,7 @@ public class MongoIdentityUserRepository : MongoDbRepository<IAbpIdentityMongoDb
bool includeDetails = true, bool includeDetails = true,
CancellationToken cancellationToken = default) CancellationToken cancellationToken = default)
{ {
return await (await GetMongoQueryableAsync(cancellationToken)) return await (await GetQueryableAsync(cancellationToken))
.OrderBy(x => x.Id).FirstOrDefaultAsync(u => u.NormalizedEmail == normalizedEmail, GetCancellationToken(cancellationToken)); .OrderBy(x => x.Id).FirstOrDefaultAsync(u => u.NormalizedEmail == normalizedEmail, GetCancellationToken(cancellationToken));
} }
@ -103,14 +103,14 @@ public class MongoIdentityUserRepository : MongoDbRepository<IAbpIdentityMongoDb
bool includeDetails = false, bool includeDetails = false,
CancellationToken cancellationToken = default) CancellationToken cancellationToken = default)
{ {
return await (await GetMongoQueryableAsync(cancellationToken)) return await (await GetQueryableAsync(cancellationToken))
.Where(u => u.Claims.Any(c => c.ClaimType == claim.Type && c.ClaimValue == claim.Value)) .Where(u => u.Claims.Any(c => c.ClaimType == claim.Type && c.ClaimValue == claim.Value))
.ToListAsync(GetCancellationToken(cancellationToken)); .ToListAsync(GetCancellationToken(cancellationToken));
} }
public virtual async Task RemoveClaimFromAllUsersAsync(string claimType, bool autoSave, CancellationToken cancellationToken = default) 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)) .Where(u => u.Claims.Any(c => c.ClaimType == claimType))
.ToListAsync(GetCancellationToken(cancellationToken)); .ToListAsync(GetCancellationToken(cancellationToken));
@ -129,7 +129,7 @@ public class MongoIdentityUserRepository : MongoDbRepository<IAbpIdentityMongoDb
{ {
cancellationToken = GetCancellationToken(cancellationToken); cancellationToken = GetCancellationToken(cancellationToken);
var queryable = await GetMongoQueryableAsync<IdentityRole>(cancellationToken); var queryable = await GetQueryableAsync<IdentityRole>(cancellationToken);
var role = await queryable var role = await queryable
.Where(x => x.NormalizedName == normalizedRoleName) .Where(x => x.NormalizedName == normalizedRoleName)
@ -141,7 +141,7 @@ public class MongoIdentityUserRepository : MongoDbRepository<IAbpIdentityMongoDb
return new List<IdentityUser>(); return new List<IdentityUser>();
} }
return await (await GetMongoQueryableAsync(cancellationToken)) return await (await GetQueryableAsync(cancellationToken))
.Where(u => u.Roles.Any(r => r.RoleId == role.Id)) .Where(u => u.Roles.Any(r => r.RoleId == role.Id))
.ToListAsync(cancellationToken); .ToListAsync(cancellationToken);
} }
@ -150,7 +150,7 @@ public class MongoIdentityUserRepository : MongoDbRepository<IAbpIdentityMongoDb
{ {
cancellationToken = GetCancellationToken(cancellationToken); cancellationToken = GetCancellationToken(cancellationToken);
return await (await GetMongoQueryableAsync(cancellationToken)) return await (await GetQueryableAsync(cancellationToken))
.Where(u => u.Roles.Any(r => r.RoleId == roleId)) .Where(u => u.Roles.Any(r => r.RoleId == roleId))
.Select(x => x.Id) .Select(x => x.Id)
.ToListAsync(cancellationToken); .ToListAsync(cancellationToken);
@ -201,8 +201,7 @@ public class MongoIdentityUserRepository : MongoDbRepository<IAbpIdentityMongoDb
return await query return await query
.OrderBy(sorting.IsNullOrWhiteSpace() ? nameof(IdentityUser.CreationTime) + " desc" : sorting) .OrderBy(sorting.IsNullOrWhiteSpace() ? nameof(IdentityUser.CreationTime) + " desc" : sorting)
.As<IMongoQueryable<IdentityUser>>() .PageBy(skipCount, maxResultCount)
.PageBy<IdentityUser, IMongoQueryable<IdentityUser>>(skipCount, maxResultCount)
.ToListAsync(GetCancellationToken(cancellationToken)); .ToListAsync(GetCancellationToken(cancellationToken));
} }
@ -217,13 +216,13 @@ public class MongoIdentityUserRepository : MongoDbRepository<IAbpIdentityMongoDb
.Select(r => r.OrganizationUnitId) .Select(r => r.OrganizationUnitId)
.ToArray(); .ToArray();
var organizationUnits = await (await GetMongoQueryableAsync<OrganizationUnit>(cancellationToken)) var organizationUnits = await (await GetQueryableAsync<OrganizationUnit>(cancellationToken))
.Where(ou => organizationUnitIds.Contains(ou.Id)) .Where(ou => organizationUnitIds.Contains(ou.Id))
.ToListAsync(cancellationToken: cancellationToken); .ToListAsync(cancellationToken: cancellationToken);
var orgUnitRoleIds = organizationUnits.SelectMany(x => x.Roles.Select(r => r.RoleId)).ToArray(); var orgUnitRoleIds = organizationUnits.SelectMany(x => x.Roles.Select(r => r.RoleId)).ToArray();
var roleIds = user.Roles.Select(r => r.RoleId).ToArray(); var roleIds = user.Roles.Select(r => r.RoleId).ToArray();
var allRoleIds = orgUnitRoleIds.Union(roleIds); var allRoleIds = orgUnitRoleIds.Union(roleIds);
return await (await GetMongoQueryableAsync<IdentityRole>(cancellationToken)).Where(r => allRoleIds.Contains(r.Id)).ToListAsync(cancellationToken); return await (await GetQueryableAsync<IdentityRole>(cancellationToken)).Where(r => allRoleIds.Contains(r.Id)).ToListAsync(cancellationToken);
} }
public virtual async Task<List<OrganizationUnit>> GetOrganizationUnitsAsync( public virtual async Task<List<OrganizationUnit>> GetOrganizationUnitsAsync(
@ -235,7 +234,7 @@ public class MongoIdentityUserRepository : MongoDbRepository<IAbpIdentityMongoDb
var user = await GetAsync(id, cancellationToken: cancellationToken); var user = await GetAsync(id, cancellationToken: cancellationToken);
var organizationUnitIds = user.OrganizationUnits.Select(r => r.OrganizationUnitId); var organizationUnitIds = user.OrganizationUnits.Select(r => r.OrganizationUnitId);
return await (await GetMongoQueryableAsync<OrganizationUnit>(cancellationToken)) return await (await GetQueryableAsync<OrganizationUnit>(cancellationToken))
.Where(ou => organizationUnitIds.Contains(ou.Id)) .Where(ou => organizationUnitIds.Contains(ou.Id))
.ToListAsync(cancellationToken); .ToListAsync(cancellationToken);
} }
@ -286,7 +285,7 @@ public class MongoIdentityUserRepository : MongoDbRepository<IAbpIdentityMongoDb
Guid organizationUnitId, Guid organizationUnitId,
CancellationToken cancellationToken = default) CancellationToken cancellationToken = default)
{ {
var result = await (await GetMongoQueryableAsync(cancellationToken)) var result = await (await GetQueryableAsync(cancellationToken))
.Where(u => u.OrganizationUnits.Any(uou => uou.OrganizationUnitId == organizationUnitId)) .Where(u => u.OrganizationUnits.Any(uou => uou.OrganizationUnitId == organizationUnitId))
.ToListAsync(GetCancellationToken(cancellationToken)); .ToListAsync(GetCancellationToken(cancellationToken));
return result; return result;
@ -296,7 +295,7 @@ public class MongoIdentityUserRepository : MongoDbRepository<IAbpIdentityMongoDb
List<Guid> organizationUnitIds, List<Guid> organizationUnitIds,
CancellationToken cancellationToken = default) 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))) .Where(u => u.OrganizationUnits.Any(uou => organizationUnitIds.Contains(uou.OrganizationUnitId)))
.ToListAsync(GetCancellationToken(cancellationToken)); .ToListAsync(GetCancellationToken(cancellationToken));
return result; return result;
@ -308,12 +307,12 @@ public class MongoIdentityUserRepository : MongoDbRepository<IAbpIdentityMongoDb
{ {
cancellationToken = GetCancellationToken(cancellationToken); cancellationToken = GetCancellationToken(cancellationToken);
var organizationUnitIds = await (await GetMongoQueryableAsync<OrganizationUnit>(cancellationToken)) var organizationUnitIds = await (await GetQueryableAsync<OrganizationUnit>(cancellationToken))
.Where(ou => ou.Code.StartsWith(code)) .Where(ou => ou.Code.StartsWith(code))
.Select(ou => ou.Id) .Select(ou => ou.Id)
.ToListAsync(cancellationToken); .ToListAsync(cancellationToken);
return await (await GetMongoQueryableAsync(cancellationToken)) return await (await GetQueryableAsync(cancellationToken))
.Where(u => u.OrganizationUnits.Any(uou => organizationUnitIds.Contains(uou.OrganizationUnitId))) .Where(u => u.OrganizationUnits.Any(uou => organizationUnitIds.Contains(uou.OrganizationUnitId)))
.ToListAsync(cancellationToken); .ToListAsync(cancellationToken);
} }
@ -324,7 +323,7 @@ public class MongoIdentityUserRepository : MongoDbRepository<IAbpIdentityMongoDb
bool includeDetails = true, bool includeDetails = true,
CancellationToken cancellationToken = default) CancellationToken cancellationToken = default)
{ {
return await (await GetMongoQueryableAsync(cancellationToken)) return await (await GetQueryableAsync(cancellationToken))
.FirstOrDefaultAsync( .FirstOrDefaultAsync(
u => u.TenantId == tenantId && u.UserName == userName, u => u.TenantId == tenantId && u.UserName == userName,
GetCancellationToken(cancellationToken) GetCancellationToken(cancellationToken)
@ -333,14 +332,14 @@ public class MongoIdentityUserRepository : MongoDbRepository<IAbpIdentityMongoDb
public virtual async Task<List<IdentityUser>> GetListByIdsAsync(IEnumerable<Guid> ids, bool includeDetails = false, CancellationToken cancellationToken = default) public virtual async Task<List<IdentityUser>> GetListByIdsAsync(IEnumerable<Guid> ids, bool includeDetails = false, CancellationToken cancellationToken = default)
{ {
return await (await GetMongoQueryableAsync(cancellationToken)) return await (await GetQueryableAsync(cancellationToken))
.Where(x => ids.Contains(x.Id)) .Where(x => ids.Contains(x.Id))
.ToListAsync(GetCancellationToken(cancellationToken)); .ToListAsync(GetCancellationToken(cancellationToken));
} }
public virtual async Task UpdateRoleAsync(Guid sourceRoleId, Guid? targetRoleId, CancellationToken cancellationToken = default) 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)) .Where(x => x.Roles.Any(r => r.RoleId == sourceRoleId))
.ToListAsync(GetCancellationToken(cancellationToken)); .ToListAsync(GetCancellationToken(cancellationToken));
@ -358,7 +357,7 @@ public class MongoIdentityUserRepository : MongoDbRepository<IAbpIdentityMongoDb
public virtual async Task UpdateOrganizationAsync(Guid sourceOrganizationId, Guid? targetOrganizationId, CancellationToken cancellationToken = default) public virtual async Task UpdateOrganizationAsync(Guid sourceOrganizationId, Guid? targetOrganizationId, CancellationToken cancellationToken = default)
{ {
var users = await (await GetMongoQueryableAsync(cancellationToken)) var users = await (await GetQueryableAsync(cancellationToken))
.Where(x => x.OrganizationUnits.Any(r => r.OrganizationUnitId == sourceOrganizationId)) .Where(x => x.OrganizationUnits.Any(r => r.OrganizationUnitId == sourceOrganizationId))
.ToListAsync(GetCancellationToken(cancellationToken)); .ToListAsync(GetCancellationToken(cancellationToken));
@ -390,7 +389,7 @@ public class MongoIdentityUserRepository : MongoDbRepository<IAbpIdentityMongoDb
var organizationUnitIds = userAndOrganizationUnitIds.SelectMany(x => x.Value); var organizationUnitIds = userAndOrganizationUnitIds.SelectMany(x => x.Value);
var roleIds = userAndRoleIds.SelectMany(x => x.Value); var roleIds = userAndRoleIds.SelectMany(x => x.Value);
var organizationUnitAndRoleIds = await (await GetMongoQueryableAsync<OrganizationUnit>(cancellationToken)).Where(ou => organizationUnitIds.Contains(ou.Id)) var organizationUnitAndRoleIds = await (await GetQueryableAsync<OrganizationUnit>(cancellationToken)).Where(ou => organizationUnitIds.Contains(ou.Id))
.Select(userOrganizationUnit => new .Select(userOrganizationUnit => new
{ {
userOrganizationUnit.Id, userOrganizationUnit.Id,
@ -399,7 +398,7 @@ public class MongoIdentityUserRepository : MongoDbRepository<IAbpIdentityMongoDb
var allOrganizationUnitRoleIds = organizationUnitAndRoleIds.SelectMany(x => x.Roles.Select(r => r.RoleId)).ToList(); var allOrganizationUnitRoleIds = organizationUnitAndRoleIds.SelectMany(x => x.Roles.Select(r => r.RoleId)).ToList();
var allRoleIds = roleIds.Union(allOrganizationUnitRoleIds); var allRoleIds = roleIds.Union(allOrganizationUnitRoleIds);
var roles = await (await GetMongoQueryableAsync<IdentityRole>(cancellationToken)).Where(r => allRoleIds.Contains(r.Id)).Select(r => new{ r.Id, r.Name }).ToListAsync(cancellationToken); var roles = await (await GetQueryableAsync<IdentityRole>(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 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(); var result = userRoles.Select(x => new IdentityUserIdWithRoleNames { Id = x.Key, RoleNames = x.Value }).ToList();
@ -422,7 +421,7 @@ public class MongoIdentityUserRepository : MongoDbRepository<IAbpIdentityMongoDb
return result; return result;
} }
protected virtual async Task<IMongoQueryable<IdentityUser>> GetFilteredQueryableAsync( protected virtual async Task<IQueryable<IdentityUser>> GetFilteredQueryableAsync(
string filter = null, string filter = null,
Guid? roleId = null, Guid? roleId = null,
Guid? organizationUnitId = null, Guid? organizationUnitId = null,
@ -442,11 +441,11 @@ public class MongoIdentityUserRepository : MongoDbRepository<IAbpIdentityMongoDb
CancellationToken cancellationToken = default) CancellationToken cancellationToken = default)
{ {
var upperFilter = filter?.ToUpperInvariant(); var upperFilter = filter?.ToUpperInvariant();
var query = await GetMongoQueryableAsync(cancellationToken); var query = await GetQueryableAsync(cancellationToken);
if (roleId.HasValue) if (roleId.HasValue)
{ {
var organizationUnitIds = (await GetMongoQueryableAsync<OrganizationUnit>(cancellationToken)) var organizationUnitIds = (await GetQueryableAsync<OrganizationUnit>(cancellationToken))
.Where(ou => ou.Roles.Any(r => r.RoleId == roleId.Value)) .Where(ou => ou.Roles.Any(r => r.RoleId == roleId.Value))
.Select(userOrganizationUnit => userOrganizationUnit.Id) .Select(userOrganizationUnit => userOrganizationUnit.Id)
.ToArray(); .ToArray();
@ -455,7 +454,7 @@ public class MongoIdentityUserRepository : MongoDbRepository<IAbpIdentityMongoDb
} }
return query return query
.WhereIf<IdentityUser, IMongoQueryable<IdentityUser>>( .WhereIf(
!filter.IsNullOrWhiteSpace(), !filter.IsNullOrWhiteSpace(),
u => u =>
u.NormalizedUserName.Contains(upperFilter) || u.NormalizedUserName.Contains(upperFilter) ||
@ -464,20 +463,20 @@ public class MongoIdentityUserRepository : MongoDbRepository<IAbpIdentityMongoDb
(u.Surname != null && u.Surname.Contains(filter)) || (u.Surname != null && u.Surname.Contains(filter)) ||
(u.PhoneNumber != null && u.PhoneNumber.Contains(filter)) (u.PhoneNumber != null && u.PhoneNumber.Contains(filter))
) )
.WhereIf<IdentityUser, IMongoQueryable<IdentityUser>>(organizationUnitId.HasValue, identityUser => identityUser.OrganizationUnits.Any(x => x.OrganizationUnitId == organizationUnitId.Value)) .WhereIf(organizationUnitId.HasValue, identityUser => identityUser.OrganizationUnits.Any(x => x.OrganizationUnitId == organizationUnitId.Value))
.WhereIf<IdentityUser, IMongoQueryable<IdentityUser>>(!string.IsNullOrWhiteSpace(userName), x => x.UserName == userName) .WhereIf(!string.IsNullOrWhiteSpace(userName), x => x.UserName == userName)
.WhereIf<IdentityUser, IMongoQueryable<IdentityUser>>(!string.IsNullOrWhiteSpace(phoneNumber), x => x.PhoneNumber == phoneNumber) .WhereIf(!string.IsNullOrWhiteSpace(phoneNumber), x => x.PhoneNumber == phoneNumber)
.WhereIf<IdentityUser, IMongoQueryable<IdentityUser>>(!string.IsNullOrWhiteSpace(emailAddress), x => x.Email == emailAddress) .WhereIf(!string.IsNullOrWhiteSpace(emailAddress), x => x.Email == emailAddress)
.WhereIf<IdentityUser, IMongoQueryable<IdentityUser>>(!string.IsNullOrWhiteSpace(name), x => x.Name == name) .WhereIf(!string.IsNullOrWhiteSpace(name), x => x.Name == name)
.WhereIf<IdentityUser, IMongoQueryable<IdentityUser>>(!string.IsNullOrWhiteSpace(surname), x => x.Surname == surname) .WhereIf(!string.IsNullOrWhiteSpace(surname), x => x.Surname == surname)
.WhereIf<IdentityUser, IMongoQueryable<IdentityUser>>(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<IdentityUser, IMongoQueryable<IdentityUser>>(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<IdentityUser, IMongoQueryable<IdentityUser>>(notActive.HasValue, x => x.IsActive == !notActive.Value) .WhereIf(notActive.HasValue, x => x.IsActive == !notActive.Value)
.WhereIf<IdentityUser, IMongoQueryable<IdentityUser>>(emailConfirmed.HasValue, x => x.EmailConfirmed == emailConfirmed.Value) .WhereIf(emailConfirmed.HasValue, x => x.EmailConfirmed == emailConfirmed.Value)
.WhereIf<IdentityUser, IMongoQueryable<IdentityUser>>(isExternal.HasValue, x => x.IsExternal == isExternal.Value) .WhereIf(isExternal.HasValue, x => x.IsExternal == isExternal.Value)
.WhereIf<IdentityUser, IMongoQueryable<IdentityUser>>(maxCreationTime != null, p => p.CreationTime <= maxCreationTime) .WhereIf(maxCreationTime != null, p => p.CreationTime <= maxCreationTime)
.WhereIf<IdentityUser, IMongoQueryable<IdentityUser>>(minCreationTime != null, p => p.CreationTime >= minCreationTime) .WhereIf(minCreationTime != null, p => p.CreationTime >= minCreationTime)
.WhereIf<IdentityUser, IMongoQueryable<IdentityUser>>(maxModifitionTime != null, p => p.LastModificationTime <= maxModifitionTime) .WhereIf(maxModifitionTime != null, p => p.LastModificationTime <= maxModifitionTime)
.WhereIf<IdentityUser, IMongoQueryable<IdentityUser>>(minModifitionTime != null, p => p.LastModificationTime >= minModifitionTime); .WhereIf(minModifitionTime != null, p => p.LastModificationTime >= minModifitionTime);
} }
} }

65
modules/identity/src/Volo.Abp.Identity.MongoDB/Volo/Abp/Identity/MongoDB/MongoOrganizationUnitRepository.cs

@ -27,7 +27,7 @@ public class MongoOrganizationUnitRepository
bool includeDetails = false, bool includeDetails = false,
CancellationToken cancellationToken = default) CancellationToken cancellationToken = default)
{ {
return await (await GetMongoQueryableAsync(cancellationToken)) return await (await GetQueryableAsync(cancellationToken))
.Where(ou => ou.ParentId == parentId) .Where(ou => ou.ParentId == parentId)
.ToListAsync(GetCancellationToken(cancellationToken)); .ToListAsync(GetCancellationToken(cancellationToken));
} }
@ -38,7 +38,7 @@ public class MongoOrganizationUnitRepository
bool includeDetails = false, bool includeDetails = false,
CancellationToken cancellationToken = default) CancellationToken cancellationToken = default)
{ {
return await (await GetMongoQueryableAsync(cancellationToken)) return await (await GetQueryableAsync(cancellationToken))
.Where(ou => ou.Code.StartsWith(code) && ou.Id != parentId) .Where(ou => ou.Code.StartsWith(code) && ou.Id != parentId)
.ToListAsync(GetCancellationToken(cancellationToken)); .ToListAsync(GetCancellationToken(cancellationToken));
} }
@ -48,7 +48,7 @@ public class MongoOrganizationUnitRepository
bool includeDetails = false, bool includeDetails = false,
CancellationToken cancellationToken = default) CancellationToken cancellationToken = default)
{ {
return await (await GetMongoQueryableAsync(cancellationToken)) return await (await GetQueryableAsync(cancellationToken))
.Where(t => ids.Contains(t.Id)) .Where(t => ids.Contains(t.Id))
.ToListAsync(GetCancellationToken(cancellationToken)); .ToListAsync(GetCancellationToken(cancellationToken));
} }
@ -58,7 +58,7 @@ public class MongoOrganizationUnitRepository
bool includeDetails = false, bool includeDetails = false,
CancellationToken cancellationToken = default) CancellationToken cancellationToken = default)
{ {
return await (await GetMongoQueryableAsync(cancellationToken)) return await (await GetQueryableAsync(cancellationToken))
.Where(x => x.Roles.Any(r => r.RoleId == roleId)) .Where(x => x.Roles.Any(r => r.RoleId == roleId))
.ToListAsync(GetCancellationToken(cancellationToken)); .ToListAsync(GetCancellationToken(cancellationToken));
} }
@ -68,7 +68,7 @@ public class MongoOrganizationUnitRepository
bool includeDetails = false, bool includeDetails = false,
CancellationToken cancellationToken = default) CancellationToken cancellationToken = default)
{ {
return await (await GetMongoQueryableAsync(cancellationToken)) return await (await GetQueryableAsync(cancellationToken))
.Where(x => displayNames.Contains(x.DisplayName)) .Where(x => displayNames.Contains(x.DisplayName))
.ToListAsync(GetCancellationToken(cancellationToken)); .ToListAsync(GetCancellationToken(cancellationToken));
} }
@ -80,10 +80,9 @@ public class MongoOrganizationUnitRepository
bool includeDetails = false, bool includeDetails = false,
CancellationToken cancellationToken = default) CancellationToken cancellationToken = default)
{ {
return await (await GetMongoQueryableAsync(cancellationToken)) return await (await GetQueryableAsync(cancellationToken))
.OrderBy(sorting.IsNullOrEmpty() ? nameof(OrganizationUnit.CreationTime) + " desc" : sorting) .OrderBy(sorting.IsNullOrEmpty() ? nameof(OrganizationUnit.CreationTime) + " desc" : sorting)
.As<IMongoQueryable<OrganizationUnit>>() .PageBy(skipCount, maxResultCount)
.PageBy<OrganizationUnit, IMongoQueryable<OrganizationUnit>>(skipCount, maxResultCount)
.ToListAsync(GetCancellationToken(cancellationToken)); .ToListAsync(GetCancellationToken(cancellationToken));
} }
@ -92,7 +91,7 @@ public class MongoOrganizationUnitRepository
bool includeDetails = true, bool includeDetails = true,
CancellationToken cancellationToken = default) CancellationToken cancellationToken = default)
{ {
return await (await GetMongoQueryableAsync(cancellationToken)) return await (await GetQueryableAsync(cancellationToken))
.OrderBy(x => x.Id) .OrderBy(x => x.Id)
.FirstOrDefaultAsync( .FirstOrDefaultAsync(
ou => ou.DisplayName == displayName, ou => ou.DisplayName == displayName,
@ -110,11 +109,10 @@ public class MongoOrganizationUnitRepository
{ {
var roleIds = organizationUnit.Roles.Select(r => r.RoleId).ToArray(); var roleIds = organizationUnit.Roles.Select(r => r.RoleId).ToArray();
return await (await GetMongoQueryableAsync<IdentityRole>(cancellationToken)) return await (await GetQueryableAsync<IdentityRole>(cancellationToken))
.Where(r => roleIds.Contains(r.Id)) .Where(r => roleIds.Contains(r.Id))
.OrderBy(sorting.IsNullOrEmpty() ? nameof(IdentityRole.Name) : sorting) .OrderBy(sorting.IsNullOrEmpty() ? nameof(IdentityRole.Name) : sorting)
.As<IMongoQueryable<IdentityRole>>() .PageBy(skipCount, maxResultCount)
.PageBy<IdentityRole, IMongoQueryable<IdentityRole>>(skipCount, maxResultCount)
.ToListAsync(GetCancellationToken(cancellationToken)); .ToListAsync(GetCancellationToken(cancellationToken));
} }
@ -126,17 +124,16 @@ public class MongoOrganizationUnitRepository
bool includeDetails = false, bool includeDetails = false,
CancellationToken cancellationToken = default) CancellationToken cancellationToken = default)
{ {
var organizationUnits = await (await GetMongoQueryableAsync(cancellationToken)) var organizationUnits = await (await GetQueryableAsync(cancellationToken))
.Where(ou => organizationUnitIds.Contains(ou.Id)) .Where(ou => organizationUnitIds.Contains(ou.Id))
.ToListAsync(GetCancellationToken(cancellationToken)); .ToListAsync(GetCancellationToken(cancellationToken));
var roleIds = organizationUnits.SelectMany(ou => ou.Roles.Select(r => r.RoleId)).ToArray(); var roleIds = organizationUnits.SelectMany(ou => ou.Roles.Select(r => r.RoleId)).ToArray();
return await (await GetMongoQueryableAsync<IdentityRole>(cancellationToken)) return await (await GetQueryableAsync<IdentityRole>(cancellationToken))
.Where(r => roleIds.Contains(r.Id)) .Where(r => roleIds.Contains(r.Id))
.OrderBy(sorting.IsNullOrEmpty() ? nameof(IdentityRole.Name) : sorting) .OrderBy(sorting.IsNullOrEmpty() ? nameof(IdentityRole.Name) : sorting)
.As<IMongoQueryable<IdentityRole>>() .PageBy(skipCount, maxResultCount)
.PageBy<IdentityRole, IMongoQueryable<IdentityRole>>(skipCount, maxResultCount)
.ToListAsync(GetCancellationToken(cancellationToken)); .ToListAsync(GetCancellationToken(cancellationToken));
} }
@ -146,7 +143,7 @@ public class MongoOrganizationUnitRepository
{ {
var roleIds = organizationUnit.Roles.Select(r => r.RoleId).ToArray(); var roleIds = organizationUnit.Roles.Select(r => r.RoleId).ToArray();
return await (await GetMongoQueryableAsync<IdentityRole>(cancellationToken)).Where(r => roleIds.Contains(r.Id)).CountAsync(GetCancellationToken(cancellationToken)); return await (await GetQueryableAsync<IdentityRole>(cancellationToken)).Where(r => roleIds.Contains(r.Id)).CountAsync(GetCancellationToken(cancellationToken));
} }
public virtual async Task<List<IdentityRole>> GetUnaddedRolesAsync( public virtual async Task<List<IdentityRole>> GetUnaddedRolesAsync(
@ -160,12 +157,11 @@ public class MongoOrganizationUnitRepository
{ {
var roleIds = organizationUnit.Roles.Select(r => r.RoleId).ToArray(); var roleIds = organizationUnit.Roles.Select(r => r.RoleId).ToArray();
return await (await GetMongoQueryableAsync<IdentityRole>(cancellationToken)) return await (await GetQueryableAsync<IdentityRole>(cancellationToken))
.Where(r => !roleIds.Contains(r.Id)) .Where(r => !roleIds.Contains(r.Id))
.WhereIf(!filter.IsNullOrWhiteSpace(), r => r.Name.Contains(filter)) .WhereIf(!filter.IsNullOrWhiteSpace(), r => r.Name.Contains(filter))
.OrderBy(sorting.IsNullOrEmpty() ? nameof(IdentityRole.Name) : sorting) .OrderBy(sorting.IsNullOrEmpty() ? nameof(IdentityRole.Name) : sorting)
.As<IMongoQueryable<IdentityRole>>() .PageBy(skipCount, maxResultCount)
.PageBy<IdentityRole, IMongoQueryable<IdentityRole>>(skipCount, maxResultCount)
.ToListAsync(GetCancellationToken(cancellationToken)); .ToListAsync(GetCancellationToken(cancellationToken));
} }
@ -176,10 +172,9 @@ public class MongoOrganizationUnitRepository
{ {
var roleIds = organizationUnit.Roles.Select(r => r.RoleId).ToArray(); var roleIds = organizationUnit.Roles.Select(r => r.RoleId).ToArray();
return await (await GetMongoQueryableAsync<IdentityRole>(cancellationToken)) return await (await GetQueryableAsync<IdentityRole>(cancellationToken))
.Where(r => !roleIds.Contains(r.Id)) .Where(r => !roleIds.Contains(r.Id))
.WhereIf(!filter.IsNullOrWhiteSpace(), r => r.Name.Contains(filter)) .WhereIf(!filter.IsNullOrWhiteSpace(), r => r.Name.Contains(filter))
.As<IMongoQueryable<IdentityRole>>()
.CountAsync(GetCancellationToken(cancellationToken)); .CountAsync(GetCancellationToken(cancellationToken));
} }
@ -196,15 +191,14 @@ public class MongoOrganizationUnitRepository
var query = await CreateGetMembersFilteredQueryAsync(organizationUnit, filter, cancellationToken); var query = await CreateGetMembersFilteredQueryAsync(organizationUnit, filter, cancellationToken);
return await query return await query
.OrderBy(sorting.IsNullOrEmpty() ? nameof(IdentityUser.UserName) : sorting) .OrderBy(sorting.IsNullOrEmpty() ? nameof(IdentityUser.UserName) : sorting)
.As<IMongoQueryable<IdentityUser>>() .PageBy(skipCount, maxResultCount)
.PageBy<IdentityUser, IMongoQueryable<IdentityUser>>(skipCount, maxResultCount)
.ToListAsync(cancellationToken); .ToListAsync(cancellationToken);
} }
public virtual async Task<List<Guid>> GetMemberIdsAsync(Guid id, CancellationToken cancellationToken = default) public virtual async Task<List<Guid>> GetMemberIdsAsync(Guid id, CancellationToken cancellationToken = default)
{ {
cancellationToken = GetCancellationToken(cancellationToken); cancellationToken = GetCancellationToken(cancellationToken);
return await (await GetMongoQueryableAsync<IdentityUser>(cancellationToken)) return await (await GetQueryableAsync<IdentityUser>(cancellationToken))
.Where(u => u.OrganizationUnits.Any(uou => uou.OrganizationUnitId == id)).Select(x => x.Id) .Where(u => u.OrganizationUnits.Any(uou => uou.OrganizationUnitId == id)).Select(x => x.Id)
.ToListAsync(cancellationToken); .ToListAsync(cancellationToken);
} }
@ -229,9 +223,9 @@ public class MongoOrganizationUnitRepository
CancellationToken cancellationToken = default) CancellationToken cancellationToken = default)
{ {
return await return await
(await GetMongoQueryableAsync<IdentityUser>(cancellationToken)) (await GetQueryableAsync<IdentityUser>(cancellationToken))
.Where(u => !u.OrganizationUnits.Any(uou => uou.OrganizationUnitId == organizationUnit.Id)) .Where(u => !u.OrganizationUnits.Any(uou => uou.OrganizationUnitId == organizationUnit.Id))
.WhereIf<IdentityUser, IMongoQueryable<IdentityUser>>( .WhereIf(
!filter.IsNullOrWhiteSpace(), !filter.IsNullOrWhiteSpace(),
u => u =>
u.UserName.Contains(filter) || u.UserName.Contains(filter) ||
@ -239,24 +233,22 @@ public class MongoOrganizationUnitRepository
(u.PhoneNumber != null && u.PhoneNumber.Contains(filter)) (u.PhoneNumber != null && u.PhoneNumber.Contains(filter))
) )
.OrderBy(sorting.IsNullOrEmpty() ? nameof(IdentityUser.UserName) : sorting) .OrderBy(sorting.IsNullOrEmpty() ? nameof(IdentityUser.UserName) : sorting)
.As<IMongoQueryable<IdentityUser>>() .PageBy(skipCount, maxResultCount)
.PageBy<IdentityUser, IMongoQueryable<IdentityUser>>(skipCount, maxResultCount)
.ToListAsync(GetCancellationToken(cancellationToken)); .ToListAsync(GetCancellationToken(cancellationToken));
} }
public virtual async Task<int> GetUnaddedUsersCountAsync(OrganizationUnit organizationUnit, string filter = null, public virtual async Task<int> GetUnaddedUsersCountAsync(OrganizationUnit organizationUnit, string filter = null,
CancellationToken cancellationToken = default) CancellationToken cancellationToken = default)
{ {
return await (await GetMongoQueryableAsync<IdentityUser>(cancellationToken)) return await (await GetQueryableAsync<IdentityUser>(cancellationToken))
.Where(u => !u.OrganizationUnits.Any(uou => uou.OrganizationUnitId == organizationUnit.Id)) .Where(u => !u.OrganizationUnits.Any(uou => uou.OrganizationUnitId == organizationUnit.Id))
.WhereIf<IdentityUser, IMongoQueryable<IdentityUser>>( .WhereIf(
!filter.IsNullOrWhiteSpace(), !filter.IsNullOrWhiteSpace(),
u => u =>
u.UserName.Contains(filter) || u.UserName.Contains(filter) ||
u.Email.Contains(filter) || u.Email.Contains(filter) ||
(u.PhoneNumber != null && u.PhoneNumber.Contains(filter)) (u.PhoneNumber != null && u.PhoneNumber.Contains(filter))
) )
.As<IMongoQueryable<IdentityUser>>()
.CountAsync(GetCancellationToken(cancellationToken)); .CountAsync(GetCancellationToken(cancellationToken));
} }
@ -269,11 +261,10 @@ public class MongoOrganizationUnitRepository
public virtual async Task RemoveAllMembersAsync(OrganizationUnit organizationUnit, CancellationToken cancellationToken = default) public virtual async Task RemoveAllMembersAsync(OrganizationUnit organizationUnit, CancellationToken cancellationToken = default)
{ {
cancellationToken = GetCancellationToken(cancellationToken); cancellationToken = GetCancellationToken(cancellationToken);
var userQueryable = await GetMongoQueryableAsync<IdentityUser>(cancellationToken); var userQueryable = await GetQueryableAsync<IdentityUser>(cancellationToken);
var dbContext = await GetDbContextAsync(cancellationToken); var dbContext = await GetDbContextAsync(cancellationToken);
var users = await userQueryable var users = await userQueryable
.Where(u => u.OrganizationUnits.Any(uou => uou.OrganizationUnitId == organizationUnit.Id)) .Where(u => u.OrganizationUnits.Any(uou => uou.OrganizationUnitId == organizationUnit.Id))
.As<IMongoQueryable<IdentityUser>>()
.ToListAsync(cancellationToken); .ToListAsync(cancellationToken);
foreach (var user in users) foreach (var user in users)
@ -283,14 +274,14 @@ public class MongoOrganizationUnitRepository
} }
} }
protected virtual async Task<IMongoQueryable<IdentityUser>> CreateGetMembersFilteredQueryAsync( protected virtual async Task<IQueryable<IdentityUser>> CreateGetMembersFilteredQueryAsync(
OrganizationUnit organizationUnit, OrganizationUnit organizationUnit,
string filter = null, string filter = null,
CancellationToken cancellationToken = default) CancellationToken cancellationToken = default)
{ {
return (await GetMongoQueryableAsync<IdentityUser>(cancellationToken)) return (await GetQueryableAsync<IdentityUser>(cancellationToken))
.Where(u => u.OrganizationUnits.Any(uou => uou.OrganizationUnitId == organizationUnit.Id)) .Where(u => u.OrganizationUnits.Any(uou => uou.OrganizationUnitId == organizationUnit.Id))
.WhereIf<IdentityUser, IMongoQueryable<IdentityUser>>( .WhereIf(
!filter.IsNullOrWhiteSpace(), !filter.IsNullOrWhiteSpace(),
u => u =>
u.UserName.Contains(filter) || u.UserName.Contains(filter) ||

8
modules/identity/test/Volo.Abp.Identity.MongoDB.Tests/Volo.Abp.Identity.MongoDB.Tests.csproj

@ -20,10 +20,10 @@
<ItemGroup> <ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" /> <PackageReference Include="Microsoft.NET.Test.Sdk" />
<PackageReference Include="EphemeralMongo.Core" /> <PackageReference Include="MongoSandbox.Core" />
<PackageReference Include="EphemeralMongo6.runtime.linux-x64" Condition="$([MSBuild]::IsOSPlatform('Linux'))" /> <PackageReference Include="MongoSandbox6.runtime.linux-x64" Condition="$([MSBuild]::IsOSPlatform('Linux'))" />
<PackageReference Include="EphemeralMongo6.runtime.osx-x64" Condition="$([MSBuild]::IsOSPlatform('OSX'))" /> <PackageReference Include="MongoSandbox6.runtime.osx-x64" Condition="$([MSBuild]::IsOSPlatform('OSX'))" />
<PackageReference Include="EphemeralMongo6.runtime.win-x64" Condition="$([MSBuild]::IsOSPlatform('Windows'))" /> <PackageReference Include="MongoSandbox6.runtime.win-x64" Condition="$([MSBuild]::IsOSPlatform('Windows'))" />
</ItemGroup> </ItemGroup>
</Project> </Project>

2
modules/identity/test/Volo.Abp.Identity.MongoDB.Tests/Volo/Abp/Identity/MongoDB/MongoDbFixture.cs

@ -1,5 +1,5 @@
using System; using System;
using EphemeralMongo; using MongoSandbox;
namespace Volo.Abp.Identity.MongoDB; namespace Volo.Abp.Identity.MongoDB;

17
modules/identityserver/src/Volo.Abp.IdentityServer.MongoDB/Volo/Abp/IdentityServer/MongoDB/MongoApiResourceRepository.cs

@ -20,7 +20,7 @@ public class MongoApiResourceRepository : MongoDbRepository<IAbpIdentityServerMo
public virtual async Task<ApiResource> FindByNameAsync(string apiResourceName, bool includeDetails = true, CancellationToken cancellationToken = default) public virtual async Task<ApiResource> FindByNameAsync(string apiResourceName, bool includeDetails = true, CancellationToken cancellationToken = default)
{ {
return await (await GetMongoQueryableAsync(cancellationToken)) return await (await GetQueryableAsync(cancellationToken))
.OrderBy(ar => ar.Id) .OrderBy(ar => ar.Id)
.FirstOrDefaultAsync(ar => ar.Name == apiResourceName, GetCancellationToken(cancellationToken)); .FirstOrDefaultAsync(ar => ar.Name == apiResourceName, GetCancellationToken(cancellationToken));
} }
@ -28,7 +28,7 @@ public class MongoApiResourceRepository : MongoDbRepository<IAbpIdentityServerMo
public virtual async Task<List<ApiResource>> FindByNameAsync(string[] apiResourceNames, bool includeDetails = true, public virtual async Task<List<ApiResource>> FindByNameAsync(string[] apiResourceNames, bool includeDetails = true,
CancellationToken cancellationToken = default) CancellationToken cancellationToken = default)
{ {
return await (await GetMongoQueryableAsync(cancellationToken)) return await (await GetQueryableAsync(cancellationToken))
.Where(ar => apiResourceNames.Contains(ar.Name)) .Where(ar => apiResourceNames.Contains(ar.Name))
.ToListAsync(GetCancellationToken(cancellationToken)); .ToListAsync(GetCancellationToken(cancellationToken));
} }
@ -36,7 +36,7 @@ public class MongoApiResourceRepository : MongoDbRepository<IAbpIdentityServerMo
public virtual async Task<List<ApiResource>> GetListByScopesAsync(string[] scopeNames, bool includeDetails = false, public virtual async Task<List<ApiResource>> GetListByScopesAsync(string[] scopeNames, bool includeDetails = false,
CancellationToken cancellationToken = default) CancellationToken cancellationToken = default)
{ {
return await (await GetMongoQueryableAsync(cancellationToken)) return await (await GetQueryableAsync(cancellationToken))
.Where(ar => ar.Scopes.Any(x => scopeNames.Contains(x.Scope))) .Where(ar => ar.Scopes.Any(x => scopeNames.Contains(x.Scope)))
.ToListAsync(GetCancellationToken(cancellationToken)); .ToListAsync(GetCancellationToken(cancellationToken));
} }
@ -44,21 +44,20 @@ public class MongoApiResourceRepository : MongoDbRepository<IAbpIdentityServerMo
public virtual async Task<List<ApiResource>> GetListAsync(string sorting, int skipCount, int maxResultCount, string filter, bool includeDetails = false, public virtual async Task<List<ApiResource>> GetListAsync(string sorting, int skipCount, int maxResultCount, string filter, bool includeDetails = false,
CancellationToken cancellationToken = default) CancellationToken cancellationToken = default)
{ {
return await (await GetMongoQueryableAsync(cancellationToken)) return await (await GetQueryableAsync(cancellationToken))
.WhereIf(!filter.IsNullOrWhiteSpace(), .WhereIf(!filter.IsNullOrWhiteSpace(),
x => x.Name.Contains(filter) || x => x.Name.Contains(filter) ||
x.Description.Contains(filter) || x.Description.Contains(filter) ||
x.DisplayName.Contains(filter)) x.DisplayName.Contains(filter))
.OrderBy(sorting.IsNullOrWhiteSpace() ? nameof(ApiResource.Name) : sorting) .OrderBy(sorting.IsNullOrWhiteSpace() ? nameof(ApiResource.Name) : sorting)
.As<IMongoQueryable<ApiResource>>() .PageBy(skipCount, maxResultCount)
.PageBy<ApiResource, IMongoQueryable<ApiResource>>(skipCount, maxResultCount)
.ToListAsync(GetCancellationToken(cancellationToken)); .ToListAsync(GetCancellationToken(cancellationToken));
} }
public virtual async Task<long> GetCountAsync(string filter = null, CancellationToken cancellationToken = default) public virtual async Task<long> GetCountAsync(string filter = null, CancellationToken cancellationToken = default)
{ {
return await (await GetMongoQueryableAsync(cancellationToken)) return await (await GetQueryableAsync(cancellationToken))
.WhereIf<ApiResource, IMongoQueryable<ApiResource>>(!filter.IsNullOrWhiteSpace(), .WhereIf(!filter.IsNullOrWhiteSpace(),
x => x.Name.Contains(filter) || x => x.Name.Contains(filter) ||
x.Description.Contains(filter) || x.Description.Contains(filter) ||
x.DisplayName.Contains(filter)) x.DisplayName.Contains(filter))
@ -67,7 +66,7 @@ public class MongoApiResourceRepository : MongoDbRepository<IAbpIdentityServerMo
public virtual async Task<bool> CheckNameExistAsync(string name, Guid? expectedId = null, CancellationToken cancellationToken = default) public virtual async Task<bool> 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)); .AnyAsync(ar => ar.Id != expectedId && ar.Name == name, GetCancellationToken(cancellationToken));
} }
} }

15
modules/identityserver/src/Volo.Abp.IdentityServer.MongoDB/Volo/Abp/IdentityServer/MongoDB/MongoApiScopeRepository.cs

@ -22,7 +22,7 @@ public class MongoApiScopeRepository : MongoDbRepository<IAbpIdentityServerMongo
public virtual async Task<ApiScope> FindByNameAsync(string scopeName, bool includeDetails = true, CancellationToken cancellationToken = default) public virtual async Task<ApiScope> FindByNameAsync(string scopeName, bool includeDetails = true, CancellationToken cancellationToken = default)
{ {
return await (await GetMongoQueryableAsync(cancellationToken)) return await (await GetQueryableAsync(cancellationToken))
.OrderBy(x => x.Id) .OrderBy(x => x.Id)
.FirstOrDefaultAsync(x => x.Name == scopeName, GetCancellationToken(cancellationToken)); .FirstOrDefaultAsync(x => x.Name == scopeName, GetCancellationToken(cancellationToken));
} }
@ -30,7 +30,7 @@ public class MongoApiScopeRepository : MongoDbRepository<IAbpIdentityServerMongo
public virtual async Task<List<ApiScope>> GetListByNameAsync(string[] scopeNames, bool includeDetails = false, public virtual async Task<List<ApiScope>> GetListByNameAsync(string[] scopeNames, bool includeDetails = false,
CancellationToken cancellationToken = default) CancellationToken cancellationToken = default)
{ {
return await (await GetMongoQueryableAsync(cancellationToken)) return await (await GetQueryableAsync(cancellationToken))
.Where(scope => scopeNames.Contains(scope.Name)) .Where(scope => scopeNames.Contains(scope.Name))
.OrderBy(scope => scope.Id) .OrderBy(scope => scope.Id)
.ToListAsync(GetCancellationToken(cancellationToken)); .ToListAsync(GetCancellationToken(cancellationToken));
@ -39,21 +39,20 @@ public class MongoApiScopeRepository : MongoDbRepository<IAbpIdentityServerMongo
public virtual async Task<List<ApiScope>> GetListAsync(string sorting, int skipCount, int maxResultCount, string filter = null, bool includeDetails = false, public virtual async Task<List<ApiScope>> GetListAsync(string sorting, int skipCount, int maxResultCount, string filter = null, bool includeDetails = false,
CancellationToken cancellationToken = default) CancellationToken cancellationToken = default)
{ {
return await (await GetMongoQueryableAsync(cancellationToken)) return await (await GetQueryableAsync(cancellationToken))
.WhereIf(!filter.IsNullOrWhiteSpace(), .WhereIf(!filter.IsNullOrWhiteSpace(),
x => x.Name.Contains(filter) || x => x.Name.Contains(filter) ||
x.Description.Contains(filter) || x.Description.Contains(filter) ||
x.DisplayName.Contains(filter)) x.DisplayName.Contains(filter))
.OrderBy(sorting.IsNullOrWhiteSpace() ? nameof(ApiScope.Name) : sorting) .OrderBy(sorting.IsNullOrWhiteSpace() ? nameof(ApiScope.Name) : sorting)
.As<IMongoQueryable<ApiScope>>() .PageBy(skipCount, maxResultCount)
.PageBy<ApiScope, IMongoQueryable<ApiScope>>(skipCount, maxResultCount)
.ToListAsync(GetCancellationToken(cancellationToken)); .ToListAsync(GetCancellationToken(cancellationToken));
} }
public virtual async Task<long> GetCountAsync(string filter = null, CancellationToken cancellationToken = default) public virtual async Task<long> GetCountAsync(string filter = null, CancellationToken cancellationToken = default)
{ {
return await (await GetMongoQueryableAsync(cancellationToken)) return await (await GetQueryableAsync(cancellationToken))
.WhereIf<ApiScope, IMongoQueryable<ApiScope>>(!filter.IsNullOrWhiteSpace(), .WhereIf(!filter.IsNullOrWhiteSpace(),
x => x.Name.Contains(filter) || x => x.Name.Contains(filter) ||
x.Description.Contains(filter) || x.Description.Contains(filter) ||
x.DisplayName.Contains(filter)) x.DisplayName.Contains(filter))
@ -62,7 +61,7 @@ public class MongoApiScopeRepository : MongoDbRepository<IAbpIdentityServerMongo
public virtual async Task<bool> CheckNameExistAsync(string name, Guid? expectedId = null, CancellationToken cancellationToken = default) public virtual async Task<bool> 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)); .AnyAsync(x => x.Id != expectedId && x.Name == name, GetCancellationToken(cancellationToken));
} }
} }

15
modules/identityserver/src/Volo.Abp.IdentityServer.MongoDB/Volo/Abp/IdentityServer/MongoDB/MongoClientRepository.cs

@ -26,7 +26,7 @@ public class MongoClientRepository : MongoDbRepository<IAbpIdentityServerMongoDb
bool includeDetails = true, bool includeDetails = true,
CancellationToken cancellationToken = default) CancellationToken cancellationToken = default)
{ {
return await (await GetMongoQueryableAsync(cancellationToken)) return await (await GetQueryableAsync(cancellationToken))
.OrderBy(x => x.Id) .OrderBy(x => x.Id)
.FirstOrDefaultAsync(x => x.ClientId == clientId, GetCancellationToken(cancellationToken)); .FirstOrDefaultAsync(x => x.ClientId == clientId, GetCancellationToken(cancellationToken));
} }
@ -39,18 +39,17 @@ public class MongoClientRepository : MongoDbRepository<IAbpIdentityServerMongoDb
bool includeDetails = false, bool includeDetails = false,
CancellationToken cancellationToken = default) CancellationToken cancellationToken = default)
{ {
return await (await GetMongoQueryableAsync(cancellationToken)) return await (await GetQueryableAsync(cancellationToken))
.WhereIf(!filter.IsNullOrWhiteSpace(), x => x.ClientId.Contains(filter)) .WhereIf(!filter.IsNullOrWhiteSpace(), x => x.ClientId.Contains(filter))
.OrderBy(sorting.IsNullOrWhiteSpace() ? nameof(Client.ClientName) : sorting) .OrderBy(sorting.IsNullOrWhiteSpace() ? nameof(Client.ClientName) : sorting)
.As<IMongoQueryable<Client>>() .PageBy(skipCount, maxResultCount)
.PageBy<Client, IMongoQueryable<Client>>(skipCount, maxResultCount)
.ToListAsync(GetCancellationToken(cancellationToken)); .ToListAsync(GetCancellationToken(cancellationToken));
} }
public virtual async Task<long> GetCountAsync(string filter = null, CancellationToken cancellationToken = default) public virtual async Task<long> GetCountAsync(string filter = null, CancellationToken cancellationToken = default)
{ {
return await (await GetMongoQueryableAsync(cancellationToken)) return await (await GetQueryableAsync(cancellationToken))
.WhereIf<Client, IMongoQueryable<Client>>(!filter.IsNullOrWhiteSpace(), .WhereIf(!filter.IsNullOrWhiteSpace(),
x => x.ClientId.Contains(filter)) x => x.ClientId.Contains(filter))
.LongCountAsync(GetCancellationToken(cancellationToken)); .LongCountAsync(GetCancellationToken(cancellationToken));
} }
@ -58,7 +57,7 @@ public class MongoClientRepository : MongoDbRepository<IAbpIdentityServerMongoDb
public virtual async Task<List<string>> GetAllDistinctAllowedCorsOriginsAsync( public virtual async Task<List<string>> GetAllDistinctAllowedCorsOriginsAsync(
CancellationToken cancellationToken = default) CancellationToken cancellationToken = default)
{ {
return await (await GetMongoQueryableAsync(cancellationToken)) return await (await GetQueryableAsync(cancellationToken))
.SelectMany(x => x.AllowedCorsOrigins) .SelectMany(x => x.AllowedCorsOrigins)
.Select(y => y.Origin) .Select(y => y.Origin)
.Distinct() .Distinct()
@ -67,7 +66,7 @@ public class MongoClientRepository : MongoDbRepository<IAbpIdentityServerMongoDb
public virtual async Task<bool> CheckClientIdExistAsync(string clientId, Guid? expectedId = null, CancellationToken cancellationToken = default) public virtual async Task<bool> 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)); .AnyAsync(c => c.Id != expectedId && c.ClientId == clientId, GetCancellationToken(cancellationToken));
} }
} }

7
modules/identityserver/src/Volo.Abp.IdentityServer.MongoDB/Volo/Abp/IdentityServer/MongoDB/MongoDeviceFlowCodesRepository.cs

@ -2,6 +2,7 @@
using System.Collections.Generic; using System.Collections.Generic;
using System.Threading; using System.Threading;
using System.Threading.Tasks; using System.Threading.Tasks;
using System.Linq;
using MongoDB.Driver; using MongoDB.Driver;
using MongoDB.Driver.Linq; using MongoDB.Driver.Linq;
using Volo.Abp.Domain.Repositories.MongoDB; using Volo.Abp.Domain.Repositories.MongoDB;
@ -23,7 +24,7 @@ public class MongoDeviceFlowCodesRepository :
string userCode, string userCode,
CancellationToken cancellationToken = default) CancellationToken cancellationToken = default)
{ {
return await (await GetMongoQueryableAsync(cancellationToken)) return await (await GetQueryableAsync(cancellationToken))
.Where(d => d.UserCode == userCode) .Where(d => d.UserCode == userCode)
.OrderBy(x => x.Id) .OrderBy(x => x.Id)
.FirstOrDefaultAsync(GetCancellationToken(cancellationToken)); .FirstOrDefaultAsync(GetCancellationToken(cancellationToken));
@ -31,7 +32,7 @@ public class MongoDeviceFlowCodesRepository :
public virtual async Task<DeviceFlowCodes> FindByDeviceCodeAsync(string deviceCode, CancellationToken cancellationToken = default) public virtual async Task<DeviceFlowCodes> FindByDeviceCodeAsync(string deviceCode, CancellationToken cancellationToken = default)
{ {
return await (await GetMongoQueryableAsync(cancellationToken)) return await (await GetQueryableAsync(cancellationToken))
.Where(d => d.DeviceCode == deviceCode) .Where(d => d.DeviceCode == deviceCode)
.OrderBy(x => x.Id) .OrderBy(x => x.Id)
.FirstOrDefaultAsync(GetCancellationToken(cancellationToken)); .FirstOrDefaultAsync(GetCancellationToken(cancellationToken));
@ -42,7 +43,7 @@ public class MongoDeviceFlowCodesRepository :
int maxResultCount, int maxResultCount,
CancellationToken cancellationToken = default) CancellationToken cancellationToken = default)
{ {
return await (await GetMongoQueryableAsync(cancellationToken)) return await (await GetQueryableAsync(cancellationToken))
.Where(x => x.Expiration != null && x.Expiration < maxExpirationDate) .Where(x => x.Expiration != null && x.Expiration < maxExpirationDate)
.OrderBy(x => x.ClientId) .OrderBy(x => x.ClientId)
.Take(maxResultCount) .Take(maxResultCount)

15
modules/identityserver/src/Volo.Abp.IdentityServer.MongoDB/Volo/Abp/IdentityServer/MongoDB/MongoIdentityResourceRepository.cs

@ -20,20 +20,19 @@ public class MongoIdentityResourceRepository : MongoDbRepository<IAbpIdentitySer
public virtual async Task<List<IdentityResource>> GetListAsync(string sorting, int skipCount, int maxResultCount, string filter, bool includeDetails = false, CancellationToken cancellationToken = default) public virtual async Task<List<IdentityResource>> 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) || .WhereIf(!filter.IsNullOrWhiteSpace(), x => x.Name.Contains(filter) ||
x.Description.Contains(filter) || x.Description.Contains(filter) ||
x.DisplayName.Contains(filter)) x.DisplayName.Contains(filter))
.OrderBy(sorting.IsNullOrWhiteSpace() ? nameof(IdentityResource.Name) : sorting) .OrderBy(sorting.IsNullOrWhiteSpace() ? nameof(IdentityResource.Name) : sorting)
.As<IMongoQueryable<IdentityResource>>() .PageBy(skipCount, maxResultCount)
.PageBy<IdentityResource, IMongoQueryable<IdentityResource>>(skipCount, maxResultCount)
.ToListAsync(GetCancellationToken(cancellationToken)); .ToListAsync(GetCancellationToken(cancellationToken));
} }
public virtual async Task<long> GetCountAsync(string filter = null, CancellationToken cancellationToken = default) public virtual async Task<long> GetCountAsync(string filter = null, CancellationToken cancellationToken = default)
{ {
return await (await GetMongoQueryableAsync(cancellationToken)) return await (await GetQueryableAsync(cancellationToken))
.WhereIf<IdentityResource, IMongoQueryable<IdentityResource>>(!filter.IsNullOrWhiteSpace(), .WhereIf(!filter.IsNullOrWhiteSpace(),
x => x.Name.Contains(filter) || x => x.Name.Contains(filter) ||
x.Description.Contains(filter) || x.Description.Contains(filter) ||
x.DisplayName.Contains(filter)) x.DisplayName.Contains(filter))
@ -45,7 +44,7 @@ public class MongoIdentityResourceRepository : MongoDbRepository<IAbpIdentitySer
bool includeDetails = true, bool includeDetails = true,
CancellationToken cancellationToken = default) CancellationToken cancellationToken = default)
{ {
return await (await GetMongoQueryableAsync(cancellationToken)) return await (await GetQueryableAsync(cancellationToken))
.Where(x => x.Name == name) .Where(x => x.Name == name)
.OrderBy(x => x.Id) .OrderBy(x => x.Id)
.FirstOrDefaultAsync(GetCancellationToken(cancellationToken)); .FirstOrDefaultAsync(GetCancellationToken(cancellationToken));
@ -54,14 +53,14 @@ public class MongoIdentityResourceRepository : MongoDbRepository<IAbpIdentitySer
public virtual async Task<List<IdentityResource>> GetListByScopeNameAsync(string[] scopeNames, bool includeDetails = false, public virtual async Task<List<IdentityResource>> GetListByScopeNameAsync(string[] scopeNames, bool includeDetails = false,
CancellationToken cancellationToken = default) CancellationToken cancellationToken = default)
{ {
return await (await GetMongoQueryableAsync(cancellationToken)) return await (await GetQueryableAsync(cancellationToken))
.Where(ar => scopeNames.Contains(ar.Name)) .Where(ar => scopeNames.Contains(ar.Name))
.ToListAsync(GetCancellationToken(cancellationToken)); .ToListAsync(GetCancellationToken(cancellationToken));
} }
public virtual async Task<bool> CheckNameExistAsync(string name, Guid? expectedId = null, CancellationToken cancellationToken = default) public virtual async Task<bool> 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)); .AnyAsync(ir => ir.Id != expectedId && ir.Name == name, GetCancellationToken(cancellationToken));
} }
} }

19
modules/identityserver/src/Volo.Abp.IdentityServer.MongoDB/Volo/Abp/IdentityServer/MongoDB/MongoPersistentGrantRepository.cs

@ -27,7 +27,7 @@ public class MongoPersistentGrantRepository : MongoDbRepository<IAbpIdentityServ
public virtual async Task<PersistedGrant> FindByKeyAsync(string key, CancellationToken cancellationToken = default) public virtual async Task<PersistedGrant> FindByKeyAsync(string key, CancellationToken cancellationToken = default)
{ {
return await (await GetMongoQueryableAsync(cancellationToken)) return await (await GetQueryableAsync(cancellationToken))
.Where(x => x.Key == key) .Where(x => x.Key == key)
.OrderBy(x => x.Id) .OrderBy(x => x.Id)
.FirstOrDefaultAsync(GetCancellationToken(cancellationToken)); .FirstOrDefaultAsync(GetCancellationToken(cancellationToken));
@ -35,7 +35,7 @@ public class MongoPersistentGrantRepository : MongoDbRepository<IAbpIdentityServ
public virtual async Task<List<PersistedGrant>> GetListBySubjectIdAsync(string subjectId, CancellationToken cancellationToken = default) public virtual async Task<List<PersistedGrant>> GetListBySubjectIdAsync(string subjectId, CancellationToken cancellationToken = default)
{ {
return await (await GetMongoQueryableAsync(cancellationToken)) return await (await GetQueryableAsync(cancellationToken))
.Where(x => x.SubjectId == subjectId) .Where(x => x.SubjectId == subjectId)
.ToListAsync(GetCancellationToken(cancellationToken)); .ToListAsync(GetCancellationToken(cancellationToken));
} }
@ -43,7 +43,7 @@ public class MongoPersistentGrantRepository : MongoDbRepository<IAbpIdentityServ
public virtual async Task<List<PersistedGrant>> GetListByExpirationAsync(DateTime maxExpirationDate, int maxResultCount, public virtual async Task<List<PersistedGrant>> GetListByExpirationAsync(DateTime maxExpirationDate, int maxResultCount,
CancellationToken cancellationToken = default) CancellationToken cancellationToken = default)
{ {
return await (await GetMongoQueryableAsync(cancellationToken)) return await (await GetQueryableAsync(cancellationToken))
.Where(x => x.Expiration != null && x.Expiration < maxExpirationDate) .Where(x => x.Expiration != null && x.Expiration < maxExpirationDate)
.OrderBy(x => x.ClientId) .OrderBy(x => x.ClientId)
.Take(maxResultCount) .Take(maxResultCount)
@ -87,18 +87,17 @@ public class MongoPersistentGrantRepository : MongoDbRepository<IAbpIdentityServ
); );
} }
private async Task<IMongoQueryable<PersistedGrant>> FilterAsync( private async Task<IQueryable<PersistedGrant>> FilterAsync(
string subjectId, string subjectId,
string sessionId, string sessionId,
string clientId, string clientId,
string type, string type,
CancellationToken cancellationToken = default) CancellationToken cancellationToken = default)
{ {
return (await GetMongoQueryableAsync(cancellationToken)) return (await GetQueryableAsync(cancellationToken))
.WhereIf<PersistedGrant, IMongoQueryable<PersistedGrant>>(!subjectId.IsNullOrWhiteSpace(), x => x.SubjectId == subjectId) .WhereIf(!subjectId.IsNullOrWhiteSpace(), x => x.SubjectId == subjectId)
.WhereIf<PersistedGrant, IMongoQueryable<PersistedGrant>>(!sessionId.IsNullOrWhiteSpace(), x => x.SessionId == sessionId) .WhereIf(!sessionId.IsNullOrWhiteSpace(), x => x.SessionId == sessionId)
.WhereIf<PersistedGrant, IMongoQueryable<PersistedGrant>>(!clientId.IsNullOrWhiteSpace(), x => x.ClientId == clientId) .WhereIf(!clientId.IsNullOrWhiteSpace(), x => x.ClientId == clientId)
.WhereIf<PersistedGrant, IMongoQueryable<PersistedGrant>>(!type.IsNullOrWhiteSpace(), x => x.Type == type) .WhereIf(!type.IsNullOrWhiteSpace(), x => x.Type == type);
.As<IMongoQueryable<PersistedGrant>>();
} }
} }

8
modules/identityserver/test/Volo.Abp.IdentityServer.MongoDB.Tests/Volo.Abp.IdentityServer.MongoDB.Tests.csproj

@ -20,10 +20,10 @@
<ItemGroup> <ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" /> <PackageReference Include="Microsoft.NET.Test.Sdk" />
<PackageReference Include="EphemeralMongo.Core" /> <PackageReference Include="MongoSandbox.Core" />
<PackageReference Include="EphemeralMongo6.runtime.linux-x64" Condition="$([MSBuild]::IsOSPlatform('Linux'))" /> <PackageReference Include="MongoSandbox6.runtime.linux-x64" Condition="$([MSBuild]::IsOSPlatform('Linux'))" />
<PackageReference Include="EphemeralMongo6.runtime.osx-x64" Condition="$([MSBuild]::IsOSPlatform('OSX'))" /> <PackageReference Include="MongoSandbox6.runtime.osx-x64" Condition="$([MSBuild]::IsOSPlatform('OSX'))" />
<PackageReference Include="EphemeralMongo6.runtime.win-x64" Condition="$([MSBuild]::IsOSPlatform('Windows'))" /> <PackageReference Include="MongoSandbox6.runtime.win-x64" Condition="$([MSBuild]::IsOSPlatform('Windows'))" />
</ItemGroup> </ItemGroup>
</Project> </Project>

2
modules/identityserver/test/Volo.Abp.IdentityServer.MongoDB.Tests/Volo/Abp/IdentityServer/MongoDbFixture.cs

@ -1,5 +1,5 @@
using System; using System;
using EphemeralMongo; using MongoSandbox;
namespace Volo.Abp.IdentityServer; namespace Volo.Abp.IdentityServer;

17
modules/openiddict/src/Volo.Abp.OpenIddict.MongoDB/Volo/Abp/OpenIddict/Applications/MongoOpenIddictApplicationRepository.cs

@ -21,50 +21,47 @@ public class MongoOpenIddictApplicationRepository : MongoDbRepository<OpenIddict
public virtual async Task<List<OpenIddictApplication>> GetListAsync(string sorting, int skipCount, int maxResultCount, string filter = null, public virtual async Task<List<OpenIddictApplication>> GetListAsync(string sorting, int skipCount, int maxResultCount, string filter = null,
CancellationToken cancellationToken = default) CancellationToken cancellationToken = default)
{ {
return await ((await GetMongoQueryableAsync(cancellationToken))) return await ((await GetQueryableAsync(cancellationToken)))
.WhereIf(!filter.IsNullOrWhiteSpace(), x => x.ClientId.Contains(filter)) .WhereIf(!filter.IsNullOrWhiteSpace(), x => x.ClientId.Contains(filter))
.OrderBy(sorting.IsNullOrWhiteSpace() ? nameof(OpenIddictApplication.CreationTime) + " desc" : sorting) .OrderBy(sorting.IsNullOrWhiteSpace() ? nameof(OpenIddictApplication.CreationTime) + " desc" : sorting)
.PageBy(skipCount, maxResultCount) .PageBy(skipCount, maxResultCount)
.As<IMongoQueryable<OpenIddictApplication>>()
.ToListAsync(GetCancellationToken(cancellationToken)); .ToListAsync(GetCancellationToken(cancellationToken));
} }
public virtual async Task<long> GetCountAsync(string filter = null, CancellationToken cancellationToken = default) public virtual async Task<long> 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)) .WhereIf(!filter.IsNullOrWhiteSpace(), x => x.ClientId.Contains(filter))
.As<IMongoQueryable<OpenIddictApplication>>()
.LongCountAsync(GetCancellationToken(cancellationToken)); .LongCountAsync(GetCancellationToken(cancellationToken));
} }
public virtual async Task<OpenIddictApplication> FindByClientIdAsync(string clientId, CancellationToken cancellationToken = default) public virtual async Task<OpenIddictApplication> FindByClientIdAsync(string clientId, CancellationToken cancellationToken = default)
{ {
return await (await GetMongoQueryableAsync(cancellationToken)) return await (await GetQueryableAsync(cancellationToken))
.FirstOrDefaultAsync(x => x.ClientId == clientId, cancellationToken); .FirstOrDefaultAsync(x => x.ClientId == clientId, cancellationToken);
} }
public virtual async Task<List<OpenIddictApplication>> FindByPostLogoutRedirectUriAsync(string address, CancellationToken cancellationToken = default) public virtual async Task<List<OpenIddictApplication>> 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<List<OpenIddictApplication>> FindByRedirectUriAsync(string address, CancellationToken cancellationToken = default) public virtual async Task<List<OpenIddictApplication>> 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<TResult> GetAsync<TState, TResult>(Func<IQueryable<OpenIddictApplication>, TState, IQueryable<TResult>> query, TState state, CancellationToken cancellationToken = default) public virtual async Task<TResult> GetAsync<TState, TResult>(Func<IQueryable<OpenIddictApplication>, TState, IQueryable<TResult>> query, TState state, CancellationToken cancellationToken = default)
{ {
return await query(await GetMongoQueryableAsync(cancellationToken), state).As<IMongoQueryable<TResult>>().FirstOrDefaultAsync(GetCancellationToken(cancellationToken)); return await query(await GetQueryableAsync(cancellationToken), state).FirstOrDefaultAsync(GetCancellationToken(cancellationToken));
} }
public virtual async Task<List<OpenIddictApplication>> ListAsync(int? count, int? offset, CancellationToken cancellationToken = default) public virtual async Task<List<OpenIddictApplication>> ListAsync(int? count, int? offset, CancellationToken cancellationToken = default)
{ {
return await (await GetMongoQueryableAsync(cancellationToken)) return await (await GetQueryableAsync(cancellationToken))
.OrderBy(x => x.Id) .OrderBy(x => x.Id)
.SkipIf<OpenIddictApplication, IQueryable<OpenIddictApplication>>(offset.HasValue, offset) .SkipIf<OpenIddictApplication, IQueryable<OpenIddictApplication>>(offset.HasValue, offset)
.TakeIf<OpenIddictApplication, IQueryable<OpenIddictApplication>>(count.HasValue, count) .TakeIf<OpenIddictApplication, IQueryable<OpenIddictApplication>>(count.HasValue, count)
.As<IMongoQueryable<OpenIddictApplication>>()
.ToListAsync(GetCancellationToken(cancellationToken)); .ToListAsync(GetCancellationToken(cancellationToken));
} }
} }

19
modules/openiddict/src/Volo.Abp.OpenIddict.MongoDB/Volo/Abp/OpenIddict/Authorizations/MongoOpenIddictAuthorizationRepository.cs

@ -29,53 +29,52 @@ public class MongoOpenIddictAuthorizationRepository : MongoDbRepository<OpenIddi
public virtual async Task<List<OpenIddictAuthorization>> FindAsync(string subject, Guid? client, string status, string type, CancellationToken cancellationToken = default) public virtual async Task<List<OpenIddictAuthorization>> 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(!subject.IsNullOrWhiteSpace(), x => x.Subject == subject)
.WhereIf(client.HasValue, x => x.ApplicationId == client) .WhereIf(client.HasValue, x => x.ApplicationId == client)
.WhereIf(!status.IsNullOrWhiteSpace(), x => x.Status == status) .WhereIf(!status.IsNullOrWhiteSpace(), x => x.Status == status)
.WhereIf(!type.IsNullOrWhiteSpace(), x => x.Type == type) .WhereIf(!type.IsNullOrWhiteSpace(), x => x.Type == type)
.As<IMongoQueryable<OpenIddictAuthorization>>()
.ToListAsync(GetCancellationToken(cancellationToken)); .ToListAsync(GetCancellationToken(cancellationToken));
} }
public virtual async Task<List<OpenIddictAuthorization>> FindByApplicationIdAsync(Guid applicationId, CancellationToken cancellationToken = default) public virtual async Task<List<OpenIddictAuthorization>> 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<OpenIddictAuthorization> FindByIdAsync(Guid id, CancellationToken cancellationToken = default) public virtual async Task<OpenIddictAuthorization> 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<List<OpenIddictAuthorization>> FindBySubjectAsync(string subject, CancellationToken cancellationToken = default) public virtual async Task<List<OpenIddictAuthorization>> 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<List<OpenIddictAuthorization>> ListAsync(int? count, int? offset, CancellationToken cancellationToken = default) public virtual async Task<List<OpenIddictAuthorization>> ListAsync(int? count, int? offset, CancellationToken cancellationToken = default)
{ {
return await (await GetMongoQueryableAsync(GetCancellationToken(cancellationToken))) return await (await GetQueryableAsync(GetCancellationToken(cancellationToken)))
.OrderBy(authorization => authorization.Id!) .OrderBy(authorization => authorization.Id!)
.SkipIf<OpenIddictAuthorization, IQueryable<OpenIddictAuthorization>>(offset.HasValue, offset) .SkipIf<OpenIddictAuthorization, IQueryable<OpenIddictAuthorization>>(offset.HasValue, offset)
.TakeIf<OpenIddictAuthorization, IQueryable<OpenIddictAuthorization>>(count.HasValue, count) .TakeIf<OpenIddictAuthorization, IQueryable<OpenIddictAuthorization>>(count.HasValue, count)
.As<IMongoQueryable<OpenIddictAuthorization>>().ToListAsync(GetCancellationToken(cancellationToken)); .ToListAsync(GetCancellationToken(cancellationToken));
} }
public virtual async Task<long> PruneAsync(DateTime date, CancellationToken cancellationToken = default) public virtual async Task<long> PruneAsync(DateTime date, CancellationToken cancellationToken = default)
{ {
var tokenIds = await (await GetMongoQueryableAsync<OpenIddictToken>(cancellationToken)) var tokenIds = await (await GetQueryableAsync<OpenIddictToken>(cancellationToken))
.Where(x => x.AuthorizationId != null) .Where(x => x.AuthorizationId != null)
.Select(x => x.AuthorizationId.Value) .Select(x => x.AuthorizationId.Value)
.ToListAsync(GetCancellationToken(cancellationToken)); .ToListAsync(GetCancellationToken(cancellationToken));
var authorizations = await (await GetMongoQueryableAsync(cancellationToken)) var authorizations = await (await GetQueryableAsync(cancellationToken))
.Where(x => x.CreationDate < date) .Where(x => x.CreationDate < date)
.Where(x => x.Status != OpenIddictConstants.Statuses.Valid || (x.Type == OpenIddictConstants.AuthorizationTypes.AdHoc && !tokenIds.Contains(x.Id))) .Where(x => x.Status != OpenIddictConstants.Statuses.Valid || (x.Type == OpenIddictConstants.AuthorizationTypes.AdHoc && !tokenIds.Contains(x.Id)))
.Select(x => x.Id) .Select(x => x.Id)
.ToListAsync(cancellationToken: cancellationToken); .ToListAsync(cancellationToken: cancellationToken);
var tokens = await (await GetMongoQueryableAsync<OpenIddictToken>(cancellationToken)) var tokens = await (await GetQueryableAsync<OpenIddictToken>(cancellationToken))
.Where(x => x.AuthorizationId != null && authorizations.Contains(x.AuthorizationId.Value)) .Where(x => x.AuthorizationId != null && authorizations.Contains(x.AuthorizationId.Value))
.ToListAsync(cancellationToken: cancellationToken); .ToListAsync(cancellationToken: cancellationToken);

19
modules/openiddict/src/Volo.Abp.OpenIddict.MongoDB/Volo/Abp/OpenIddict/Scopes/MongoOpenIddictScopeRepository.cs

@ -21,61 +21,56 @@ public class MongoOpenIddictScopeRepository : MongoDbRepository<OpenIddictMongoD
public virtual async Task<List<OpenIddictScope>> GetListAsync(string sorting, int skipCount, int maxResultCount, string filter = null, public virtual async Task<List<OpenIddictScope>> GetListAsync(string sorting, int skipCount, int maxResultCount, string filter = null,
CancellationToken cancellationToken = default) CancellationToken cancellationToken = default)
{ {
return await (await GetMongoQueryableAsync(cancellationToken)) return await (await GetQueryableAsync(cancellationToken))
.WhereIf(!filter.IsNullOrWhiteSpace(), x => .WhereIf(!filter.IsNullOrWhiteSpace(), x =>
x.Name.Contains(filter) || x.Name.Contains(filter) ||
x.DisplayName.Contains(filter) || x.DisplayName.Contains(filter) ||
x.Description.Contains(filter)) x.Description.Contains(filter))
.OrderBy(sorting.IsNullOrWhiteSpace() ? nameof(OpenIddictScope.CreationTime) + " desc" : sorting) .OrderBy(sorting.IsNullOrWhiteSpace() ? nameof(OpenIddictScope.CreationTime) + " desc" : sorting)
.PageBy(skipCount, maxResultCount) .PageBy(skipCount, maxResultCount)
.As<IMongoQueryable<OpenIddictScope>>()
.ToListAsync(GetCancellationToken(cancellationToken)); .ToListAsync(GetCancellationToken(cancellationToken));
} }
public virtual async Task<long> GetCountAsync(string filter = null, CancellationToken cancellationToken = default) public virtual async Task<long> GetCountAsync(string filter = null, CancellationToken cancellationToken = default)
{ {
return await (await GetMongoQueryableAsync(cancellationToken)) return await (await GetQueryableAsync(cancellationToken))
.WhereIf(!filter.IsNullOrWhiteSpace(), x => .WhereIf(!filter.IsNullOrWhiteSpace(), x =>
x.Name.Contains(filter) || x.Name.Contains(filter) ||
x.DisplayName.Contains(filter) || x.DisplayName.Contains(filter) ||
x.Description.Contains(filter)) x.Description.Contains(filter))
.As<IMongoQueryable<OpenIddictScope>>()
.LongCountAsync(GetCancellationToken(cancellationToken)); .LongCountAsync(GetCancellationToken(cancellationToken));
} }
public virtual async Task<OpenIddictScope> FindByIdAsync(Guid id, CancellationToken cancellationToken = default) public virtual async Task<OpenIddictScope> 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<OpenIddictScope> FindByNameAsync(string name, CancellationToken cancellationToken = default) public virtual async Task<OpenIddictScope> 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<List<OpenIddictScope>> FindByNamesAsync(string[] names, CancellationToken cancellationToken = default) public virtual async Task<List<OpenIddictScope>> FindByNamesAsync(string[] names, CancellationToken cancellationToken = default)
{ {
return await (await GetMongoQueryableAsync(GetCancellationToken(cancellationToken))) return await (await GetQueryableAsync(GetCancellationToken(cancellationToken)))
.Where(x => names.Contains(x.Name)) .Where(x => names.Contains(x.Name))
.As<IMongoQueryable<OpenIddictScope>>()
.ToListAsync(GetCancellationToken(cancellationToken)); .ToListAsync(GetCancellationToken(cancellationToken));
} }
public virtual async Task<List<OpenIddictScope>> FindByResourceAsync(string resource, CancellationToken cancellationToken = default) public virtual async Task<List<OpenIddictScope>> FindByResourceAsync(string resource, CancellationToken cancellationToken = default)
{ {
return await (await GetMongoQueryableAsync(GetCancellationToken(cancellationToken))) return await (await GetQueryableAsync(GetCancellationToken(cancellationToken)))
.Where(x => x.Resources.Contains(resource)) .Where(x => x.Resources.Contains(resource))
.As<IMongoQueryable<OpenIddictScope>>()
.ToListAsync(GetCancellationToken(cancellationToken)); .ToListAsync(GetCancellationToken(cancellationToken));
} }
public virtual async Task<List<OpenIddictScope>> ListAsync(int? count, int? offset, CancellationToken cancellationToken = default) public virtual async Task<List<OpenIddictScope>> ListAsync(int? count, int? offset, CancellationToken cancellationToken = default)
{ {
return await (await GetMongoQueryableAsync(GetCancellationToken(cancellationToken))) return await (await GetQueryableAsync(GetCancellationToken(cancellationToken)))
.OrderBy(x => x.Id) .OrderBy(x => x.Id)
.SkipIf<OpenIddictScope, IQueryable<OpenIddictScope>>(offset.HasValue, offset) .SkipIf<OpenIddictScope, IQueryable<OpenIddictScope>>(offset.HasValue, offset)
.TakeIf<OpenIddictScope, IQueryable<OpenIddictScope>>(count.HasValue, count) .TakeIf<OpenIddictScope, IQueryable<OpenIddictScope>>(count.HasValue, count)
.As<IMongoQueryable<OpenIddictScope>>()
.ToListAsync(GetCancellationToken(cancellationToken)); .ToListAsync(GetCancellationToken(cancellationToken));
} }
} }

29
modules/openiddict/src/Volo.Abp.OpenIddict.MongoDB/Volo/Abp/OpenIddict/Tokens/MongoOpenIddictTokenRepository.cs

@ -21,7 +21,7 @@ public class MongoOpenIddictTokenRepository : MongoDbRepository<OpenIddictMongoD
public virtual async Task DeleteManyByApplicationIdAsync(Guid applicationId, bool autoSave = false, CancellationToken cancellationToken = default) public virtual async Task DeleteManyByApplicationIdAsync(Guid applicationId, bool autoSave = false, CancellationToken cancellationToken = default)
{ {
var tokens = await (await GetMongoQueryableAsync(GetCancellationToken(cancellationToken))) var tokens = await (await GetQueryableAsync(GetCancellationToken(cancellationToken)))
.Where(x => x.ApplicationId == applicationId) .Where(x => x.ApplicationId == applicationId)
.ToListAsync(GetCancellationToken(cancellationToken)); .ToListAsync(GetCancellationToken(cancellationToken));
@ -31,7 +31,7 @@ public class MongoOpenIddictTokenRepository : MongoDbRepository<OpenIddictMongoD
public virtual async Task DeleteManyByAuthorizationIdAsync(Guid authorizationId, bool autoSave = false, public virtual async Task DeleteManyByAuthorizationIdAsync(Guid authorizationId, bool autoSave = false,
CancellationToken cancellationToken = default) CancellationToken cancellationToken = default)
{ {
var tokens = await (await GetMongoQueryableAsync(GetCancellationToken(cancellationToken))) var tokens = await (await GetQueryableAsync(GetCancellationToken(cancellationToken)))
.Where(x => x.AuthorizationId == authorizationId) .Where(x => x.AuthorizationId == authorizationId)
.ToListAsync(GetCancellationToken(cancellationToken)); .ToListAsync(GetCancellationToken(cancellationToken));
@ -40,7 +40,7 @@ public class MongoOpenIddictTokenRepository : MongoDbRepository<OpenIddictMongoD
public virtual async Task DeleteManyByAuthorizationIdsAsync(Guid[] authorizationIds, bool autoSave = false, CancellationToken cancellationToken = default) public virtual async Task DeleteManyByAuthorizationIdsAsync(Guid[] authorizationIds, bool autoSave = false, CancellationToken cancellationToken = default)
{ {
var tokens = await (await GetMongoQueryableAsync(GetCancellationToken(cancellationToken))) var tokens = await (await GetQueryableAsync(GetCancellationToken(cancellationToken)))
.Where(x => x.AuthorizationId != null && authorizationIds.Contains(x.AuthorizationId.Value)) .Where(x => x.AuthorizationId != null && authorizationIds.Contains(x.AuthorizationId.Value))
.ToListAsync(GetCancellationToken(cancellationToken)); .ToListAsync(GetCancellationToken(cancellationToken));
@ -49,67 +49,62 @@ public class MongoOpenIddictTokenRepository : MongoDbRepository<OpenIddictMongoD
public virtual async Task<List<OpenIddictToken>> FindAsync(string subject, Guid? client, string status, string type, CancellationToken cancellationToken = default) public virtual async Task<List<OpenIddictToken>> 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(!subject.IsNullOrWhiteSpace(), x => x.Subject == subject)
.WhereIf(client.HasValue, x => x.ApplicationId == client) .WhereIf(client.HasValue, x => x.ApplicationId == client)
.WhereIf(!status.IsNullOrWhiteSpace(), x => x.Status == status) .WhereIf(!status.IsNullOrWhiteSpace(), x => x.Status == status)
.WhereIf(!type.IsNullOrWhiteSpace(), x => x.Type == type) .WhereIf(!type.IsNullOrWhiteSpace(), x => x.Type == type)
.As<IMongoQueryable<OpenIddictToken>>()
.ToListAsync(GetCancellationToken(cancellationToken)); .ToListAsync(GetCancellationToken(cancellationToken));
} }
public virtual async Task<List<OpenIddictToken>> FindByApplicationIdAsync(Guid applicationId, CancellationToken cancellationToken = default) public virtual async Task<List<OpenIddictToken>> FindByApplicationIdAsync(Guid applicationId, CancellationToken cancellationToken = default)
{ {
return await (await GetMongoQueryableAsync(GetCancellationToken(cancellationToken))) return await (await GetQueryableAsync(GetCancellationToken(cancellationToken)))
.Where(x => x.ApplicationId == applicationId) .Where(x => x.ApplicationId == applicationId)
.As<IMongoQueryable<OpenIddictToken>>()
.ToListAsync(GetCancellationToken(cancellationToken)); .ToListAsync(GetCancellationToken(cancellationToken));
} }
public virtual async Task<List<OpenIddictToken>> FindByAuthorizationIdAsync(Guid authorizationId, CancellationToken cancellationToken = default) public virtual async Task<List<OpenIddictToken>> FindByAuthorizationIdAsync(Guid authorizationId, CancellationToken cancellationToken = default)
{ {
return await (await GetMongoQueryableAsync(GetCancellationToken(cancellationToken))) return await (await GetQueryableAsync(GetCancellationToken(cancellationToken)))
.Where(x => x.AuthorizationId == authorizationId) .Where(x => x.AuthorizationId == authorizationId)
.As<IMongoQueryable<OpenIddictToken>>()
.ToListAsync(GetCancellationToken(cancellationToken)); .ToListAsync(GetCancellationToken(cancellationToken));
} }
public virtual async Task<OpenIddictToken> FindByIdAsync(Guid id, CancellationToken cancellationToken = default) public virtual async Task<OpenIddictToken> 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<OpenIddictToken> FindByReferenceIdAsync(string referenceId, CancellationToken cancellationToken = default) public virtual async Task<OpenIddictToken> 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<List<OpenIddictToken>> FindBySubjectAsync(string subject, CancellationToken cancellationToken = default) public virtual async Task<List<OpenIddictToken>> FindBySubjectAsync(string subject, CancellationToken cancellationToken = default)
{ {
return await (await GetMongoQueryableAsync(GetCancellationToken(cancellationToken))) return await (await GetQueryableAsync(GetCancellationToken(cancellationToken)))
.Where(x => x.Subject == subject) .Where(x => x.Subject == subject)
.As<IMongoQueryable<OpenIddictToken>>()
.ToListAsync(GetCancellationToken(cancellationToken)); .ToListAsync(GetCancellationToken(cancellationToken));
} }
public virtual async Task<List<OpenIddictToken>> ListAsync(int? count, int? offset, CancellationToken cancellationToken = default) public virtual async Task<List<OpenIddictToken>> ListAsync(int? count, int? offset, CancellationToken cancellationToken = default)
{ {
return await (await GetMongoQueryableAsync(GetCancellationToken(cancellationToken))) return await (await GetQueryableAsync(GetCancellationToken(cancellationToken)))
.OrderBy(x => x.Id) .OrderBy(x => x.Id)
.SkipIf<OpenIddictToken, IQueryable<OpenIddictToken>>(offset.HasValue, offset) .SkipIf<OpenIddictToken, IQueryable<OpenIddictToken>>(offset.HasValue, offset)
.TakeIf<OpenIddictToken, IQueryable<OpenIddictToken>>(count.HasValue, count) .TakeIf<OpenIddictToken, IQueryable<OpenIddictToken>>(count.HasValue, count)
.As<IMongoQueryable<OpenIddictToken>>()
.ToListAsync(GetCancellationToken(cancellationToken)); .ToListAsync(GetCancellationToken(cancellationToken));
} }
public virtual async Task<long> PruneAsync(DateTime date, CancellationToken cancellationToken = default) public virtual async Task<long> PruneAsync(DateTime date, CancellationToken cancellationToken = default)
{ {
var authorizationIds = await (await GetMongoQueryableAsync<OpenIddictAuthorization>(cancellationToken)) var authorizationIds = await (await GetQueryableAsync<OpenIddictAuthorization>(cancellationToken))
.Where(x => x.Status != OpenIddictConstants.Statuses.Valid) .Where(x => x.Status != OpenIddictConstants.Statuses.Valid)
.Select(x => x.Id) .Select(x => x.Id)
.ToListAsync(GetCancellationToken(cancellationToken)); .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.CreationDate < date)
.Where(x => (x.Status != OpenIddictConstants.Statuses.Inactive && .Where(x => (x.Status != OpenIddictConstants.Statuses.Inactive &&
x.Status != OpenIddictConstants.Statuses.Valid) || x.Status != OpenIddictConstants.Statuses.Valid) ||

8
modules/openiddict/test/Volo.Abp.OpenIddict.MongoDB.Tests/Volo.Abp.OpenIddict.MongoDB.Tests.csproj

@ -9,10 +9,10 @@
<ItemGroup> <ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" /> <PackageReference Include="Microsoft.NET.Test.Sdk" />
<PackageReference Include="EphemeralMongo.Core" /> <PackageReference Include="MongoSandbox.Core" />
<PackageReference Include="EphemeralMongo6.runtime.linux-x64" Condition="$([MSBuild]::IsOSPlatform('Linux'))" /> <PackageReference Include="MongoSandbox6.runtime.linux-x64" Condition="$([MSBuild]::IsOSPlatform('Linux'))" />
<PackageReference Include="EphemeralMongo6.runtime.osx-x64" Condition="$([MSBuild]::IsOSPlatform('OSX'))" /> <PackageReference Include="MongoSandbox6.runtime.osx-x64" Condition="$([MSBuild]::IsOSPlatform('OSX'))" />
<PackageReference Include="EphemeralMongo6.runtime.win-x64" Condition="$([MSBuild]::IsOSPlatform('Windows'))" /> <PackageReference Include="MongoSandbox6.runtime.win-x64" Condition="$([MSBuild]::IsOSPlatform('Windows'))" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>

2
modules/openiddict/test/Volo.Abp.OpenIddict.MongoDB.Tests/Volo/Abp/OpenIddict/MongoDB/MongoDbFixture.cs

@ -1,5 +1,5 @@
using System; using System;
using EphemeralMongo; using MongoSandbox;
namespace Volo.Abp.OpenIddict.MongoDB; namespace Volo.Abp.OpenIddict.MongoDB;

3
modules/permission-management/src/Volo.Abp.PermissionManagement.MongoDB/Volo/Abp/PermissionManagement/MongoDb/MongoPermissionDefinitionRecordRepository.cs

@ -1,6 +1,7 @@
using System; using System;
using System.Threading; using System.Threading;
using System.Threading.Tasks; using System.Threading.Tasks;
using System.Linq;
using MongoDB.Driver.Linq; using MongoDB.Driver.Linq;
using Volo.Abp.Domain.Repositories.MongoDB; using Volo.Abp.Domain.Repositories.MongoDB;
using Volo.Abp.MongoDB; using Volo.Abp.MongoDB;
@ -22,7 +23,7 @@ public class MongoPermissionDefinitionRecordRepository :
CancellationToken cancellationToken = default) CancellationToken cancellationToken = default)
{ {
cancellationToken = GetCancellationToken(cancellationToken); cancellationToken = GetCancellationToken(cancellationToken);
return await (await GetMongoQueryableAsync(cancellationToken)) return await (await GetQueryableAsync(cancellationToken))
.OrderBy(x => x.Id) .OrderBy(x => x.Id)
.FirstOrDefaultAsync( .FirstOrDefaultAsync(
s => s.Name == name, s => s.Name == name,

6
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 cancellationToken = default)
{ {
cancellationToken = GetCancellationToken(cancellationToken); cancellationToken = GetCancellationToken(cancellationToken);
return await (await GetMongoQueryableAsync(cancellationToken)) return await (await GetQueryableAsync(cancellationToken))
.OrderBy(x => x.Id) .OrderBy(x => x.Id)
.FirstOrDefaultAsync(s => .FirstOrDefaultAsync(s =>
s.Name == name && s.Name == name &&
@ -43,7 +43,7 @@ public class MongoPermissionGrantRepository :
CancellationToken cancellationToken = default) CancellationToken cancellationToken = default)
{ {
cancellationToken = GetCancellationToken(cancellationToken); cancellationToken = GetCancellationToken(cancellationToken);
return await (await GetMongoQueryableAsync(cancellationToken)) return await (await GetQueryableAsync(cancellationToken))
.Where(s => .Where(s =>
s.ProviderName == providerName && s.ProviderName == providerName &&
s.ProviderKey == providerKey s.ProviderKey == providerKey
@ -54,7 +54,7 @@ public class MongoPermissionGrantRepository :
CancellationToken cancellationToken = default) CancellationToken cancellationToken = default)
{ {
cancellationToken = GetCancellationToken(cancellationToken); cancellationToken = GetCancellationToken(cancellationToken);
return await (await GetMongoQueryableAsync(cancellationToken)) return await (await GetQueryableAsync(cancellationToken))
.Where(s => .Where(s =>
names.Contains(s.Name) && names.Contains(s.Name) &&
s.ProviderName == providerName && s.ProviderName == providerName &&

8
modules/permission-management/test/Volo.Abp.PermissionManagement.MongoDB.Tests/Volo.Abp.PermissionManagement.MongoDB.Tests.csproj

@ -19,10 +19,10 @@
<ItemGroup> <ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" /> <PackageReference Include="Microsoft.NET.Test.Sdk" />
<PackageReference Include="EphemeralMongo.Core" /> <PackageReference Include="MongoSandbox.Core" />
<PackageReference Include="EphemeralMongo6.runtime.linux-x64" Condition="$([MSBuild]::IsOSPlatform('Linux'))" /> <PackageReference Include="MongoSandbox6.runtime.linux-x64" Condition="$([MSBuild]::IsOSPlatform('Linux'))" />
<PackageReference Include="EphemeralMongo6.runtime.osx-x64" Condition="$([MSBuild]::IsOSPlatform('OSX'))" /> <PackageReference Include="MongoSandbox6.runtime.osx-x64" Condition="$([MSBuild]::IsOSPlatform('OSX'))" />
<PackageReference Include="EphemeralMongo6.runtime.win-x64" Condition="$([MSBuild]::IsOSPlatform('Windows'))" /> <PackageReference Include="MongoSandbox6.runtime.win-x64" Condition="$([MSBuild]::IsOSPlatform('Windows'))" />
</ItemGroup> </ItemGroup>
</Project> </Project>

2
modules/permission-management/test/Volo.Abp.PermissionManagement.MongoDB.Tests/Volo/Abp/PermissionManagement/MongoDb/MongoDbFixture.cs

@ -1,5 +1,5 @@
using System; using System;
using EphemeralMongo; using MongoSandbox;
namespace Volo.Abp.PermissionManagement.MongoDB; namespace Volo.Abp.PermissionManagement.MongoDB;

3
modules/setting-management/src/Volo.Abp.SettingManagement.MongoDB/Volo/Abp/SettingManagement/MongoDB/MongoSettingDefinitionRecordRepository.cs

@ -1,6 +1,7 @@
using System; using System;
using System.Threading; using System.Threading;
using System.Threading.Tasks; using System.Threading.Tasks;
using System.Linq;
using MongoDB.Driver.Linq; using MongoDB.Driver.Linq;
using Volo.Abp.Domain.Repositories.MongoDB; using Volo.Abp.Domain.Repositories.MongoDB;
using Volo.Abp.MongoDB; using Volo.Abp.MongoDB;
@ -16,7 +17,7 @@ public class MongoSettingDefinitionRecordRepository : MongoDbRepository<ISetting
public virtual async Task<SettingDefinitionRecord> FindByNameAsync(string name, CancellationToken cancellationToken = default) public virtual async Task<SettingDefinitionRecord> FindByNameAsync(string name, CancellationToken cancellationToken = default)
{ {
return await (await GetMongoQueryableAsync(cancellationToken)) return await (await GetQueryableAsync(cancellationToken))
.OrderBy(x => x.Id) .OrderBy(x => x.Id)
.FirstOrDefaultAsync(s => s.Name == name, GetCancellationToken(cancellationToken)); .FirstOrDefaultAsync(s => s.Name == name, GetCancellationToken(cancellationToken));
} }

6
modules/setting-management/src/Volo.Abp.SettingManagement.MongoDB/Volo/Abp/SettingManagement/MongoDB/MongoSettingRepository.cs

@ -24,7 +24,7 @@ public class MongoSettingRepository : MongoDbRepository<ISettingManagementMongoD
string providerKey, string providerKey,
CancellationToken cancellationToken = default) CancellationToken cancellationToken = default)
{ {
return await (await GetMongoQueryableAsync(cancellationToken)) return await (await GetQueryableAsync(cancellationToken))
.OrderBy(x => x.Id) .OrderBy(x => x.Id)
.FirstOrDefaultAsync( .FirstOrDefaultAsync(
s => s.Name == name && s.ProviderName == providerName && s.ProviderKey == providerKey, s => s.Name == name && s.ProviderName == providerName && s.ProviderKey == providerKey,
@ -36,7 +36,7 @@ public class MongoSettingRepository : MongoDbRepository<ISettingManagementMongoD
string providerKey, string providerKey,
CancellationToken cancellationToken = default) CancellationToken cancellationToken = default)
{ {
return await (await GetMongoQueryableAsync(cancellationToken)) return await (await GetQueryableAsync(cancellationToken))
.Where(s => s.ProviderName == providerName && s.ProviderKey == providerKey) .Where(s => s.ProviderName == providerName && s.ProviderKey == providerKey)
.ToListAsync(GetCancellationToken(cancellationToken)); .ToListAsync(GetCancellationToken(cancellationToken));
} }
@ -47,7 +47,7 @@ public class MongoSettingRepository : MongoDbRepository<ISettingManagementMongoD
string providerKey, string providerKey,
CancellationToken cancellationToken = default) CancellationToken cancellationToken = default)
{ {
return await (await GetMongoQueryableAsync(cancellationToken)) return await (await GetQueryableAsync(cancellationToken))
.Where(s => names.Contains(s.Name) && s.ProviderName == providerName && s.ProviderKey == providerKey) .Where(s => names.Contains(s.Name) && s.ProviderName == providerName && s.ProviderKey == providerKey)
.ToListAsync(GetCancellationToken(cancellationToken)); .ToListAsync(GetCancellationToken(cancellationToken));
} }

8
modules/setting-management/test/Volo.Abp.SettingManagement.MongoDB.Tests/Volo.Abp.SettingManagement.MongoDB.Tests.csproj

@ -18,10 +18,10 @@
<ItemGroup> <ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" /> <PackageReference Include="Microsoft.NET.Test.Sdk" />
<PackageReference Include="EphemeralMongo.Core" /> <PackageReference Include="MongoSandbox.Core" />
<PackageReference Include="EphemeralMongo6.runtime.linux-x64" Condition="$([MSBuild]::IsOSPlatform('Linux'))" /> <PackageReference Include="MongoSandbox6.runtime.linux-x64" Condition="$([MSBuild]::IsOSPlatform('Linux'))" />
<PackageReference Include="EphemeralMongo6.runtime.osx-x64" Condition="$([MSBuild]::IsOSPlatform('OSX'))" /> <PackageReference Include="MongoSandbox6.runtime.osx-x64" Condition="$([MSBuild]::IsOSPlatform('OSX'))" />
<PackageReference Include="EphemeralMongo6.runtime.win-x64" Condition="$([MSBuild]::IsOSPlatform('Windows'))" /> <PackageReference Include="MongoSandbox6.runtime.win-x64" Condition="$([MSBuild]::IsOSPlatform('Windows'))" />
</ItemGroup> </ItemGroup>
</Project> </Project>

2
modules/setting-management/test/Volo.Abp.SettingManagement.MongoDB.Tests/Volo/Abp/SettingManagement/MongoDB/MongoDbFixture.cs

@ -1,5 +1,5 @@
using System; using System;
using EphemeralMongo; using MongoSandbox;
namespace Volo.Abp.SettingManagement.MongoDB; namespace Volo.Abp.SettingManagement.MongoDB;

17
modules/tenant-management/src/Volo.Abp.TenantManagement.MongoDB/Volo/Abp/TenantManagement/MongoDb/MongoTenantRepository.cs

@ -24,21 +24,21 @@ public class MongoTenantRepository : MongoDbRepository<ITenantManagementMongoDbC
bool includeDetails = true, bool includeDetails = true,
CancellationToken cancellationToken = default) CancellationToken cancellationToken = default)
{ {
return await (await GetMongoQueryableAsync(cancellationToken)) return await (await GetQueryableAsync(cancellationToken))
.FirstOrDefaultAsync(t => t.NormalizedName == normalizedName, GetCancellationToken(cancellationToken)); .FirstOrDefaultAsync(t => t.NormalizedName == normalizedName, GetCancellationToken(cancellationToken));
} }
[Obsolete("Use FindByNameAsync method.")] [Obsolete("Use FindByNameAsync method.")]
public virtual Tenant FindByName(string normalizedName, bool includeDetails = true) public virtual Tenant FindByName(string normalizedName, bool includeDetails = true)
{ {
return GetMongoQueryable() return GetQueryable()
.FirstOrDefault(t => t.NormalizedName == normalizedName); .FirstOrDefault(t => t.NormalizedName == normalizedName);
} }
[Obsolete("Use FindAsync method.")] [Obsolete("Use FindAsync method.")]
public virtual Tenant FindById(Guid id, bool includeDetails = true) public virtual Tenant FindById(Guid id, bool includeDetails = true)
{ {
return GetMongoQueryable() return GetQueryable()
.FirstOrDefault(t => t.Id == id); .FirstOrDefault(t => t.Id == id);
} }
@ -50,22 +50,21 @@ public class MongoTenantRepository : MongoDbRepository<ITenantManagementMongoDbC
bool includeDetails = false, bool includeDetails = false,
CancellationToken cancellationToken = default) CancellationToken cancellationToken = default)
{ {
return await (await GetMongoQueryableAsync(cancellationToken)) return await (await GetQueryableAsync(cancellationToken))
.WhereIf<Tenant, IMongoQueryable<Tenant>>( .WhereIf(
!filter.IsNullOrWhiteSpace(), !filter.IsNullOrWhiteSpace(),
u => u =>
u.Name.Contains(filter) u.Name.Contains(filter)
) )
.OrderBy(sorting.IsNullOrEmpty() ? nameof(Tenant.Name) : sorting) .OrderBy(sorting.IsNullOrEmpty() ? nameof(Tenant.Name) : sorting)
.As<IMongoQueryable<Tenant>>() .PageBy(skipCount, maxResultCount)
.PageBy<Tenant, IMongoQueryable<Tenant>>(skipCount, maxResultCount)
.ToListAsync(GetCancellationToken(cancellationToken)); .ToListAsync(GetCancellationToken(cancellationToken));
} }
public virtual async Task<long> GetCountAsync(string filter = null, CancellationToken cancellationToken = default) public virtual async Task<long> GetCountAsync(string filter = null, CancellationToken cancellationToken = default)
{ {
return await (await GetMongoQueryableAsync(cancellationToken)) return await (await GetQueryableAsync(cancellationToken))
.WhereIf<Tenant, IMongoQueryable<Tenant>>( .WhereIf(
!filter.IsNullOrWhiteSpace(), !filter.IsNullOrWhiteSpace(),
u => u =>
u.Name.Contains(filter) u.Name.Contains(filter)

8
modules/tenant-management/test/Volo.Abp.TenantManagement.MongoDB.Tests/Volo.Abp.TenantManagement.MongoDB.Tests.csproj

@ -18,10 +18,10 @@
<ItemGroup> <ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" /> <PackageReference Include="Microsoft.NET.Test.Sdk" />
<PackageReference Include="EphemeralMongo.Core" /> <PackageReference Include="MongoSandbox.Core" />
<PackageReference Include="EphemeralMongo6.runtime.linux-x64" Condition="$([MSBuild]::IsOSPlatform('Linux'))" /> <PackageReference Include="MongoSandbox6.runtime.linux-x64" Condition="$([MSBuild]::IsOSPlatform('Linux'))" />
<PackageReference Include="EphemeralMongo6.runtime.osx-x64" Condition="$([MSBuild]::IsOSPlatform('OSX'))" /> <PackageReference Include="MongoSandbox6.runtime.osx-x64" Condition="$([MSBuild]::IsOSPlatform('OSX'))" />
<PackageReference Include="EphemeralMongo6.runtime.win-x64" Condition="$([MSBuild]::IsOSPlatform('Windows'))" /> <PackageReference Include="MongoSandbox6.runtime.win-x64" Condition="$([MSBuild]::IsOSPlatform('Windows'))" />
</ItemGroup> </ItemGroup>
</Project> </Project>

2
modules/tenant-management/test/Volo.Abp.TenantManagement.MongoDB.Tests/Volo/Abp/TenantManagement/MongoDb/MongoDbFixture.cs

@ -1,5 +1,5 @@
using System; using System;
using EphemeralMongo; using MongoSandbox;
using MongoDB.Driver; using MongoDB.Driver;
using Volo.Abp.MongoDB; using Volo.Abp.MongoDB;

15
modules/users/src/Volo.Abp.Users.MongoDB/Volo/Abp/Users/MongoDB/MongoUserRepositoryBase.cs

@ -24,7 +24,7 @@ public abstract class MongoUserRepositoryBase<TDbContext, TUser> : MongoDbReposi
public virtual async Task<TUser> FindByUserNameAsync(string userName, CancellationToken cancellationToken = default) public virtual async Task<TUser> FindByUserNameAsync(string userName, CancellationToken cancellationToken = default)
{ {
cancellationToken = GetCancellationToken(cancellationToken); cancellationToken = GetCancellationToken(cancellationToken);
return await (await GetMongoQueryableAsync(cancellationToken)) return await (await GetQueryableAsync(cancellationToken))
.OrderBy(x => x.Id) .OrderBy(x => x.Id)
.FirstOrDefaultAsync(u => u.UserName == userName, cancellationToken); .FirstOrDefaultAsync(u => u.UserName == userName, cancellationToken);
} }
@ -32,7 +32,7 @@ public abstract class MongoUserRepositoryBase<TDbContext, TUser> : MongoDbReposi
public virtual async Task<List<TUser>> GetListAsync(IEnumerable<Guid> ids, CancellationToken cancellationToken = default) public virtual async Task<List<TUser>> GetListAsync(IEnumerable<Guid> ids, CancellationToken cancellationToken = default)
{ {
cancellationToken = GetCancellationToken(cancellationToken); cancellationToken = GetCancellationToken(cancellationToken);
return await (await GetMongoQueryableAsync(cancellationToken)) return await (await GetQueryableAsync(cancellationToken))
.Where(u => ids.Contains(u.Id)) .Where(u => ids.Contains(u.Id))
.ToListAsync(cancellationToken); .ToListAsync(cancellationToken);
} }
@ -45,8 +45,8 @@ public abstract class MongoUserRepositoryBase<TDbContext, TUser> : MongoDbReposi
CancellationToken cancellationToken = default) CancellationToken cancellationToken = default)
{ {
cancellationToken = GetCancellationToken(cancellationToken); cancellationToken = GetCancellationToken(cancellationToken);
return await (await GetMongoQueryableAsync(cancellationToken)) return await (await GetQueryableAsync(cancellationToken))
.WhereIf<TUser, IMongoQueryable<TUser>>( .WhereIf(
!filter.IsNullOrWhiteSpace(), !filter.IsNullOrWhiteSpace(),
u => u =>
u.UserName.Contains(filter) || u.UserName.Contains(filter) ||
@ -55,16 +55,15 @@ public abstract class MongoUserRepositoryBase<TDbContext, TUser> : MongoDbReposi
(u.Surname != null && u.Surname.Contains(filter)) (u.Surname != null && u.Surname.Contains(filter))
) )
.OrderBy(sorting.IsNullOrEmpty() ? nameof(IUserData.UserName) : sorting) .OrderBy(sorting.IsNullOrEmpty() ? nameof(IUserData.UserName) : sorting)
.As<IMongoQueryable<TUser>>() .PageBy(skipCount, maxResultCount)
.PageBy<TUser, IMongoQueryable<TUser>>(skipCount, maxResultCount)
.ToListAsync(cancellationToken); .ToListAsync(cancellationToken);
} }
public async Task<long> GetCountAsync(string filter = null, CancellationToken cancellationToken = default) public async Task<long> GetCountAsync(string filter = null, CancellationToken cancellationToken = default)
{ {
cancellationToken = GetCancellationToken(cancellationToken); cancellationToken = GetCancellationToken(cancellationToken);
return await (await GetMongoQueryableAsync(cancellationToken)) return await (await GetQueryableAsync(cancellationToken))
.WhereIf<TUser, IMongoQueryable<TUser>>( .WhereIf(
!filter.IsNullOrWhiteSpace(), !filter.IsNullOrWhiteSpace(),
u => u =>
u.UserName.Contains(filter) || u.UserName.Contains(filter) ||

2
templates/app/aspnet-core/test/MyCompanyName.MyProjectName.MongoDB.Tests/MongoDb/MyProjectNameMongoDbFixture.cs

@ -1,5 +1,5 @@
using System; using System;
using EphemeralMongo; using MongoSandbox;
namespace MyCompanyName.MyProjectName.MongoDB; namespace MyCompanyName.MyProjectName.MongoDB;

2
templates/app/aspnet-core/test/MyCompanyName.MyProjectName.MongoDB.Tests/MongoDb/Samples/SampleRepositoryTests.cs

@ -32,7 +32,7 @@ public class SampleRepositoryTests : MyProjectNameMongoDbTestBase
await WithUnitOfWorkAsync(async () => await WithUnitOfWorkAsync(async () =>
{ {
//Act //Act
var adminUser = await (await _appUserRepository.GetMongoQueryableAsync()) var adminUser = await (await _appUserRepository.GetQueryableAsync())
.FirstOrDefaultAsync(u => u.UserName == "admin"); .FirstOrDefaultAsync(u => u.UserName == "admin");
//Assert //Assert

8
templates/app/aspnet-core/test/MyCompanyName.MyProjectName.MongoDB.Tests/MyCompanyName.MyProjectName.MongoDB.Tests.csproj

@ -15,10 +15,10 @@
<ItemGroup> <ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.11.1.0" /> <PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.11.1.0" />
<PackageReference Include="EphemeralMongo.Core" Version="1.1.3" /> <PackageReference Include="MongoSandbox.Core" Version="1.0.1" />
<PackageReference Include="EphemeralMongo6.runtime.linux-x64" Version="1.1.3" Condition="$([MSBuild]::IsOSPlatform('Linux'))" /> <PackageReference Include="MongoSandbox6.runtime.linux-x64" Version="1.0.1" Condition="$([MSBuild]::IsOSPlatform('Linux'))" />
<PackageReference Include="EphemeralMongo6.runtime.osx-x64" Version="1.1.3" Condition="$([MSBuild]::IsOSPlatform('OSX'))" /> <PackageReference Include="MongoSandbox6.runtime.osx-x64" Version="1.0.1" Condition="$([MSBuild]::IsOSPlatform('OSX'))" />
<PackageReference Include="EphemeralMongo6.runtime.win-x64" Version="1.1.3" Condition="$([MSBuild]::IsOSPlatform('Windows'))" /> <PackageReference Include="MongoSandbox6.runtime.win-x64" Version="1.0.1" Condition="$([MSBuild]::IsOSPlatform('Windows'))" />
</ItemGroup> </ItemGroup>
</Project> </Project>

2
templates/module/aspnet-core/test/MyCompanyName.MyProjectName.MongoDB.Tests/MongoDB/MongoDbFixture.cs

@ -1,5 +1,5 @@
using System; using System;
using EphemeralMongo; using MongoSandbox;
namespace MyCompanyName.MyProjectName.MongoDB; namespace MyCompanyName.MyProjectName.MongoDB;

8
templates/module/aspnet-core/test/MyCompanyName.MyProjectName.MongoDB.Tests/MyCompanyName.MyProjectName.MongoDB.Tests.csproj

@ -10,10 +10,10 @@
<ItemGroup> <ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.11.1.0" /> <PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.11.1.0" />
<PackageReference Include="EphemeralMongo.Core" Version="1.1.3" /> <PackageReference Include="MongoSandbox.Core" Version="1.0.1" />
<PackageReference Include="EphemeralMongo6.runtime.linux-x64" Version="1.1.3" Condition="$([MSBuild]::IsOSPlatform('Linux'))" /> <PackageReference Include="MongoSandbox6.runtime.linux-x64" Version="1.0.1" Condition="$([MSBuild]::IsOSPlatform('Linux'))" />
<PackageReference Include="EphemeralMongo6.runtime.osx-x64" Version="1.1.3" Condition="$([MSBuild]::IsOSPlatform('OSX'))" /> <PackageReference Include="MongoSandbox6.runtime.osx-x64" Version="1.0.1" Condition="$([MSBuild]::IsOSPlatform('OSX'))" />
<PackageReference Include="EphemeralMongo6.runtime.win-x64" Version="1.1.3" Condition="$([MSBuild]::IsOSPlatform('Windows'))" /> <PackageReference Include="MongoSandbox6.runtime.win-x64" Version="1.0.1" Condition="$([MSBuild]::IsOSPlatform('Windows'))" />
<ProjectReference Include="..\..\src\MyCompanyName.MyProjectName.MongoDB\MyCompanyName.MyProjectName.MongoDB.csproj" /> <ProjectReference Include="..\..\src\MyCompanyName.MyProjectName.MongoDB\MyCompanyName.MyProjectName.MongoDB.csproj" />
<ProjectReference Include="..\MyCompanyName.MyProjectName.Application.Tests\MyCompanyName.MyProjectName.Application.Tests.csproj" /> <ProjectReference Include="..\MyCompanyName.MyProjectName.Application.Tests\MyCompanyName.MyProjectName.Application.Tests.csproj" />
</ItemGroup> </ItemGroup>

Loading…
Cancel
Save