Compare commits

...

11 Commits

Author SHA1 Message Date
Alexandre SPIESER dc196b24f7 Upgraded MongoDB.Driver to 2.13.2, move target framework of CoreIntegrationTests to netcoreapp2.1 2021-10-13 22:52:00 +01:00
Alexandre SPIESER fe02d871f3 Merge branch 'alex/CancellationTokenWork' 2021-03-15 11:39:18 +00:00
Alexandre SPIESER ff94611ee9 remove legacy stuff, bump to version 1.4.7 after missed cancellation token mapping in AddOneAsync. 2021-03-15 11:38:37 +00:00
Alexandre SPIESER 71b64c84a0 Merge pull request #39 from alexandre-spieser/alex/CancellationTokenWork
Alex/cancellation token work
2021-03-15 11:15:00 +00:00
Alexandre SPIESER 5f6e015bf2 fix mistake: missing cancellation token 2021-03-15 11:07:35 +00:00
Alexandre SPIESER 6d8e358ccc reference package in tests 2021-03-15 09:45:15 +00:00
Alexandre SPIESER 76a1aab671 pushed cancellation token changes 2021-03-15 08:03:50 +00:00
Alexandre SPIESER eebdc89575 adding cancellation token 2021-03-12 10:13:28 +00:00
Alexandre SPIESER ee4950c5d4 Merge branch 'master' into alex/UpdateMany 2021-03-10 08:45:10 +00:00
Alexandre SPIESER 658c753989 Added cancellation tokens (ongoing) 2021-03-10 08:44:50 +00:00
Alexandre SPIESER 0e8d629a8f Update README.md 2020-06-09 17:18:43 +01:00
31 changed files with 430 additions and 5254 deletions
@@ -1,14 +1,14 @@
<Project Sdk="Microsoft.NET.Sdk"> <Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup> <PropertyGroup>
<TargetFramework>netcoreapp2.0</TargetFramework> <TargetFramework>netcoreapp2.1</TargetFramework>
</PropertyGroup> </PropertyGroup>
<ItemGroup> <ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.Identity" Version="2.1.2" /> <PackageReference Include="Microsoft.AspNetCore.Identity" Version="2.1.2" />
<PackageReference Include="Microsoft.Extensions.Identity.Stores" Version="2.1.2" /> <PackageReference Include="Microsoft.Extensions.Identity.Stores" Version="2.1.2" />
<PackageReference Include="MongoDB.Driver" Version="2.9.3" /> <PackageReference Include="MongoDB.Driver" Version="2.13.2" />
<PackageReference Include="MongoDbGenericRepository" Version="1.4.5" /> <PackageReference Include="MongoDbGenericRepository" Version="1.4.8" />
<PackageReference Include="xunit" Version="2.4.1" /> <PackageReference Include="xunit" Version="2.4.1" />
<PackageReference Include="xunit.runner.console" Version="2.4.1"> <PackageReference Include="xunit.runner.console" Version="2.4.1">
<PrivateAssets>all</PrivateAssets> <PrivateAssets>all</PrivateAssets>
@@ -796,7 +796,7 @@ namespace CoreIntegrationTests.Infrastructure
#region Index Management #region Index Management
static SemaphoreSlim textIndexSemaphore = new SemaphoreSlim(1, 1); static readonly SemaphoreSlim textIndexSemaphore = new SemaphoreSlim(1, 1);
[Fact] [Fact]
public async Task CreateTextIndexNoOptionAsync() public async Task CreateTextIndexNoOptionAsync()
+2 -2
View File
@@ -10,8 +10,8 @@
<runtime> <runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1"> <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly> <dependentAssembly>
<assemblyIdentity name="System.Runtime.InteropServices.RuntimeInformation" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" /> <assemblyIdentity name="System.Net.Http" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-4.0.2.0" newVersion="4.0.2.0" /> <bindingRedirect oldVersion="0.0.0.0-4.1.1.3" newVersion="4.1.1.3" />
</dependentAssembly> </dependentAssembly>
</assemblyBinding> </assemblyBinding>
</runtime> </runtime>
@@ -1,5 +1,4 @@
using MongoDB.Bson.Serialization.Attributes; using MongoDbGenericRepository.Models;
using MongoDbGenericRepository.Models;
using NUnit.Framework; using NUnit.Framework;
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
+54 -19
View File
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> <Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="..\packages\NUnit3TestAdapter.3.15.1\build\net35\NUnit3TestAdapter.props" Condition="Exists('..\packages\NUnit3TestAdapter.3.15.1\build\net35\NUnit3TestAdapter.props')" /> <Import Project="..\packages\NUnit3TestAdapter.4.0.0\build\net35\NUnit3TestAdapter.props" Condition="Exists('..\packages\NUnit3TestAdapter.4.0.0\build\net35\NUnit3TestAdapter.props')" />
<Import Project="..\packages\NUnit.3.12.0\build\NUnit.props" Condition="Exists('..\packages\NUnit.3.12.0\build\NUnit.props')" /> <Import Project="..\packages\NUnit.3.13.2\build\NUnit.props" Condition="Exists('..\packages\NUnit.3.13.2\build\NUnit.props')" />
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" /> <Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
<PropertyGroup> <PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration> <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
@@ -37,23 +37,26 @@
<Reference Include="Crc32C.NET, Version=1.0.5.0, Culture=neutral, processorArchitecture=MSIL"> <Reference Include="Crc32C.NET, Version=1.0.5.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\packages\Crc32C.NET.1.0.5.0\lib\net20\Crc32C.NET.dll</HintPath> <HintPath>..\packages\Crc32C.NET.1.0.5.0\lib\net20\Crc32C.NET.dll</HintPath>
</Reference> </Reference>
<Reference Include="DnsClient, Version=1.2.0.0, Culture=neutral, PublicKeyToken=4574bb5573c51424, processorArchitecture=MSIL"> <Reference Include="DnsClient, Version=1.4.0.0, Culture=neutral, PublicKeyToken=4574bb5573c51424, processorArchitecture=MSIL">
<HintPath>..\packages\DnsClient.1.2.0\lib\net45\DnsClient.dll</HintPath> <HintPath>..\packages\DnsClient.1.4.0\lib\net45\DnsClient.dll</HintPath>
</Reference> </Reference>
<Reference Include="MongoDB.Bson, Version=2.9.3.0, Culture=neutral, processorArchitecture=MSIL"> <Reference Include="MongoDB.Bson, Version=2.13.2.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\packages\MongoDB.Bson.2.9.3\lib\net452\MongoDB.Bson.dll</HintPath> <HintPath>..\packages\MongoDB.Bson.2.13.2\lib\net452\MongoDB.Bson.dll</HintPath>
</Reference> </Reference>
<Reference Include="MongoDB.Driver, Version=2.9.3.0, Culture=neutral, processorArchitecture=MSIL"> <Reference Include="MongoDB.Driver, Version=2.13.2.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\packages\MongoDB.Driver.2.9.3\lib\net452\MongoDB.Driver.dll</HintPath> <HintPath>..\packages\MongoDB.Driver.2.13.2\lib\net452\MongoDB.Driver.dll</HintPath>
</Reference> </Reference>
<Reference Include="MongoDB.Driver.Core, Version=2.9.3.0, Culture=neutral, processorArchitecture=MSIL"> <Reference Include="MongoDB.Driver.Core, Version=2.13.2.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\packages\MongoDB.Driver.Core.2.9.3\lib\net452\MongoDB.Driver.Core.dll</HintPath> <HintPath>..\packages\MongoDB.Driver.Core.2.13.2\lib\net452\MongoDB.Driver.Core.dll</HintPath>
</Reference> </Reference>
<Reference Include="MongoDbGenericRepository, Version=1.4.5.0, Culture=neutral, processorArchitecture=MSIL"> <Reference Include="MongoDB.Libmongocrypt, Version=1.2.2.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\packages\MongoDbGenericRepository.1.4.5\lib\net452\MongoDbGenericRepository.dll</HintPath> <HintPath>..\packages\MongoDB.Libmongocrypt.1.2.2\lib\net452\MongoDB.Libmongocrypt.dll</HintPath>
</Reference> </Reference>
<Reference Include="nunit.framework, Version=3.12.0.0, Culture=neutral, PublicKeyToken=2638cd05610744eb, processorArchitecture=MSIL"> <Reference Include="MongoDbGenericRepository, Version=1.4.8.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\packages\NUnit.3.12.0\lib\net45\nunit.framework.dll</HintPath> <HintPath>..\packages\MongoDbGenericRepository.1.4.8\lib\net452\MongoDbGenericRepository.dll</HintPath>
</Reference>
<Reference Include="nunit.framework, Version=3.13.2.0, Culture=neutral, PublicKeyToken=2638cd05610744eb, processorArchitecture=MSIL">
<HintPath>..\packages\NUnit.3.13.2\lib\net45\nunit.framework.dll</HintPath>
</Reference> </Reference>
<Reference Include="SharpCompress, Version=0.23.0.0, Culture=neutral, PublicKeyToken=afb0a02973931d96, processorArchitecture=MSIL"> <Reference Include="SharpCompress, Version=0.23.0.0, Culture=neutral, PublicKeyToken=afb0a02973931d96, processorArchitecture=MSIL">
<HintPath>..\packages\SharpCompress.0.23.0\lib\net45\SharpCompress.dll</HintPath> <HintPath>..\packages\SharpCompress.0.23.0\lib\net45\SharpCompress.dll</HintPath>
@@ -62,16 +65,35 @@
<HintPath>..\packages\Snappy.NET.1.1.1.8\lib\net45\Snappy.NET.dll</HintPath> <HintPath>..\packages\Snappy.NET.1.1.1.8\lib\net45\Snappy.NET.dll</HintPath>
</Reference> </Reference>
<Reference Include="System" /> <Reference Include="System" />
<Reference Include="System.Buffers, Version=4.0.2.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51, processorArchitecture=MSIL"> <Reference Include="System.Buffers, Version=4.0.3.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51, processorArchitecture=MSIL">
<HintPath>..\packages\System.Buffers.4.4.0\lib\netstandard2.0\System.Buffers.dll</HintPath> <HintPath>..\packages\System.Buffers.4.5.1\lib\net461\System.Buffers.dll</HintPath>
</Reference> </Reference>
<Reference Include="System.Configuration" /> <Reference Include="System.Configuration" />
<Reference Include="System.Core" /> <Reference Include="System.Core" />
<Reference Include="Microsoft.CSharp" /> <Reference Include="Microsoft.CSharp" />
<Reference Include="System.Net.Http, Version=4.1.1.3, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
<HintPath>..\packages\System.Net.Http.4.3.4\lib\net46\System.Net.Http.dll</HintPath>
</Reference>
<Reference Include="System.Runtime.CompilerServices.Unsafe, Version=5.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
<HintPath>..\packages\System.Runtime.CompilerServices.Unsafe.5.0.0\lib\net45\System.Runtime.CompilerServices.Unsafe.dll</HintPath>
</Reference>
<Reference Include="System.Runtime.InteropServices.RuntimeInformation, Version=4.0.1.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL"> <Reference Include="System.Runtime.InteropServices.RuntimeInformation, Version=4.0.1.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
<HintPath>..\packages\System.Runtime.InteropServices.RuntimeInformation.4.3.0\lib\net45\System.Runtime.InteropServices.RuntimeInformation.dll</HintPath> <HintPath>..\packages\System.Runtime.InteropServices.RuntimeInformation.4.3.0\lib\net45\System.Runtime.InteropServices.RuntimeInformation.dll</HintPath>
<Private>True</Private> </Reference>
<Private>True</Private> <Reference Include="System.Security.Cryptography.Algorithms, Version=4.1.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
<HintPath>..\packages\System.Security.Cryptography.Algorithms.4.3.0\lib\net461\System.Security.Cryptography.Algorithms.dll</HintPath>
</Reference>
<Reference Include="System.Security.Cryptography.Encoding, Version=4.0.1.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
<HintPath>..\packages\System.Security.Cryptography.Encoding.4.3.0\lib\net46\System.Security.Cryptography.Encoding.dll</HintPath>
</Reference>
<Reference Include="System.Security.Cryptography.Primitives, Version=4.0.1.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
<HintPath>..\packages\System.Security.Cryptography.Primitives.4.3.0\lib\net46\System.Security.Cryptography.Primitives.dll</HintPath>
</Reference>
<Reference Include="System.Security.Cryptography.X509Certificates, Version=4.1.1.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
<HintPath>..\packages\System.Security.Cryptography.X509Certificates.4.3.0\lib\net461\System.Security.Cryptography.X509Certificates.dll</HintPath>
</Reference>
<Reference Include="System.ValueTuple, Version=4.0.3.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51, processorArchitecture=MSIL">
<HintPath>..\packages\System.ValueTuple.4.5.0\lib\net461\System.ValueTuple.dll</HintPath>
</Reference> </Reference>
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
@@ -96,16 +118,29 @@
<None Include="App.config"> <None Include="App.config">
<SubType>Designer</SubType> <SubType>Designer</SubType>
</None> </None>
<None Include="libmongocrypt.dylib" />
<None Include="libmongocrypt.so" />
<None Include="packages.config" /> <None Include="packages.config" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<Service Include="{82A7F48D-3B50-4B1E-B82E-3ADA8210C358}" /> <Service Include="{82A7F48D-3B50-4B1E-B82E-3ADA8210C358}" />
</ItemGroup> </ItemGroup>
<ItemGroup>
<Content Include="Core\Compression\Snappy\lib\win\snappy32.dll" />
<Content Include="Core\Compression\Snappy\lib\win\snappy64.dll" />
<Content Include="Core\Compression\Zstandard\lib\win\libzstd.dll" />
<Content Include="mongocrypt.dll" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" /> <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<Target Name="EnsureNuGetPackageBuildImports" BeforeTargets="PrepareForBuild"> <Target Name="EnsureNuGetPackageBuildImports" BeforeTargets="PrepareForBuild">
<PropertyGroup> <PropertyGroup>
<ErrorText>This project references NuGet package(s) that are missing on this computer. Use NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}.</ErrorText> <ErrorText>This project references NuGet package(s) that are missing on this computer. Use NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}.</ErrorText>
</PropertyGroup> </PropertyGroup>
<Error Condition="!Exists('..\packages\NUnit3TestAdapter.3.15.1\build\net35\NUnit3TestAdapter.props')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\NUnit3TestAdapter.3.15.1\build\net35\NUnit3TestAdapter.props'))" /> <Error Condition="!Exists('..\packages\MongoDB.Libmongocrypt.1.2.2\build\MongoDB.Libmongocrypt.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\MongoDB.Libmongocrypt.1.2.2\build\MongoDB.Libmongocrypt.targets'))" />
<Error Condition="!Exists('..\packages\NUnit.3.13.2\build\NUnit.props')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\NUnit.3.13.2\build\NUnit.props'))" />
<Error Condition="!Exists('..\packages\NUnit3TestAdapter.4.0.0\build\net35\NUnit3TestAdapter.props')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\NUnit3TestAdapter.4.0.0\build\net35\NUnit3TestAdapter.props'))" />
<Error Condition="!Exists('..\packages\MongoDB.Driver.Core.2.13.2\build\MongoDB.Driver.Core.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\MongoDB.Driver.Core.2.13.2\build\MongoDB.Driver.Core.targets'))" />
</Target> </Target>
<Import Project="..\packages\MongoDB.Libmongocrypt.1.2.2\build\MongoDB.Libmongocrypt.targets" Condition="Exists('..\packages\MongoDB.Libmongocrypt.1.2.2\build\MongoDB.Libmongocrypt.targets')" />
<Import Project="..\packages\MongoDB.Driver.Core.2.13.2\build\MongoDB.Driver.Core.targets" Condition="Exists('..\packages\MongoDB.Driver.Core.2.13.2\build\MongoDB.Driver.Core.targets')" />
</Project> </Project>
Binary file not shown.
Binary file not shown.
Binary file not shown.
+17 -9
View File
@@ -1,16 +1,24 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<packages> <packages>
<package id="Crc32C.NET" version="1.0.5.0" targetFramework="net461" /> <package id="Crc32C.NET" version="1.0.5.0" targetFramework="net461" />
<package id="DnsClient" version="1.2.0" targetFramework="net461" /> <package id="DnsClient" version="1.4.0" targetFramework="net461" />
<package id="MongoDB.Bson" version="2.9.3" targetFramework="net461" /> <package id="MongoDB.Bson" version="2.13.2" targetFramework="net461" />
<package id="MongoDB.Driver" version="2.9.3" targetFramework="net461" /> <package id="MongoDB.Driver" version="2.13.2" targetFramework="net461" />
<package id="MongoDB.Driver.Core" version="2.9.3" targetFramework="net461" /> <package id="MongoDB.Driver.Core" version="2.13.2" targetFramework="net461" />
<package id="MongoDbGenericRepository" version="1.4.5" targetFramework="net461" /> <package id="MongoDB.Libmongocrypt" version="1.2.2" targetFramework="net461" />
<package id="NUnit" version="3.12.0" targetFramework="net461" /> <package id="MongoDbGenericRepository" version="1.4.8" targetFramework="net461" />
<package id="NUnit.ConsoleRunner" version="3.10.0" targetFramework="net461" /> <package id="NUnit" version="3.13.2" targetFramework="net461" />
<package id="NUnit3TestAdapter" version="3.15.1" targetFramework="net461" /> <package id="NUnit.ConsoleRunner" version="3.12.0" targetFramework="net461" />
<package id="NUnit3TestAdapter" version="4.0.0" targetFramework="net461" />
<package id="SharpCompress" version="0.23.0" targetFramework="net461" /> <package id="SharpCompress" version="0.23.0" targetFramework="net461" />
<package id="Snappy.NET" version="1.1.1.8" targetFramework="net461" /> <package id="Snappy.NET" version="1.1.1.8" targetFramework="net461" />
<package id="System.Buffers" version="4.4.0" targetFramework="net461" /> <package id="System.Buffers" version="4.5.1" targetFramework="net461" />
<package id="System.Net.Http" version="4.3.4" targetFramework="net461" />
<package id="System.Runtime.CompilerServices.Unsafe" version="5.0.0" targetFramework="net461" />
<package id="System.Runtime.InteropServices.RuntimeInformation" version="4.3.0" targetFramework="net461" /> <package id="System.Runtime.InteropServices.RuntimeInformation" version="4.3.0" targetFramework="net461" />
<package id="System.Security.Cryptography.Algorithms" version="4.3.0" targetFramework="net461" />
<package id="System.Security.Cryptography.Encoding" version="4.3.0" targetFramework="net461" />
<package id="System.Security.Cryptography.Primitives" version="4.3.0" targetFramework="net461" />
<package id="System.Security.Cryptography.X509Certificates" version="4.3.0" targetFramework="net461" />
<package id="System.ValueTuple" version="4.5.0" targetFramework="net461" />
</packages> </packages>
@@ -6,6 +6,9 @@ using System.Threading.Tasks;
namespace MongoDbGenericRepository namespace MongoDbGenericRepository
{ {
/// <summary>
/// The IBaseMongoRepository_Update interface exposing update functionality for documents with Guid Ids.
/// </summary>
public interface IBaseMongoRepository_Update : IBaseMongoRepository_Update<Guid> public interface IBaseMongoRepository_Update : IBaseMongoRepository_Update<Guid>
{ {
/// <summary> /// <summary>
@@ -7,6 +7,9 @@ using MongoDbGenericRepository.Models;
namespace MongoDbGenericRepository.DataAccess.Update namespace MongoDbGenericRepository.DataAccess.Update
{ {
/// <summary>
/// The IBaseMongoRepository_Update_ClientSession interface exposing update functionality with a IClientSessionHandle.
/// </summary>
public interface IBaseMongoRepository_Update_ClientSession public interface IBaseMongoRepository_Update_ClientSession
{ {
/// <summary> /// <summary>
@@ -14,10 +17,14 @@ namespace MongoDbGenericRepository.DataAccess.Update
/// </summary> /// </summary>
/// <typeparam name="TDocument">The type representing a Document.</typeparam> /// <typeparam name="TDocument">The type representing a Document.</typeparam>
/// <typeparam name="TKey">The type of the primary key for a Document.</typeparam> /// <typeparam name="TKey">The type of the primary key for a Document.</typeparam>
/// <typeparam name="TField">The type of the field to update.</typeparam>
/// <param name="session">The client session.</param> /// <param name="session">The client session.</param>
/// <param name="modifiedDocument">The document with the modifications you want to persist.</param> /// <param name="filter">The filter for the update.</param>
/// <param name="field">The field to update.</param>
/// <param name="value">The value of the field.</param>
/// <param name="partitionKey">The optional partition key.</param>
/// <param name="cancellationToken">The optional cancellation token.</param> /// <param name="cancellationToken">The optional cancellation token.</param>
/// <returns></returns> /// <returns>A boolean value indicating success.</returns>
bool UpdateOne<TDocument, TKey, TField>(IClientSessionHandle session, Expression<Func<TDocument, bool>> filter, Expression<Func<TDocument, TField>> field, TField value, string partitionKey = null, CancellationToken cancellationToken = default(CancellationToken)) bool UpdateOne<TDocument, TKey, TField>(IClientSessionHandle session, Expression<Func<TDocument, bool>> filter, Expression<Func<TDocument, TField>> field, TField value, string partitionKey = null, CancellationToken cancellationToken = default(CancellationToken))
where TDocument : IDocument<TKey> where TDocument : IDocument<TKey>
where TKey : IEquatable<TKey>; where TKey : IEquatable<TKey>;
@@ -27,10 +34,14 @@ namespace MongoDbGenericRepository.DataAccess.Update
/// </summary> /// </summary>
/// <typeparam name="TDocument">The type representing a Document.</typeparam> /// <typeparam name="TDocument">The type representing a Document.</typeparam>
/// <typeparam name="TKey">The type of the primary key for a Document.</typeparam> /// <typeparam name="TKey">The type of the primary key for a Document.</typeparam>
/// <typeparam name="TField">The type of the field to update.</typeparam>
/// <param name="session">The client session.</param> /// <param name="session">The client session.</param>
/// <param name="modifiedDocument">The document with the modifications you want to persist.</param> /// <param name="filter">The filter for the update.</param>
/// <param name="field">The field to update.</param>
/// <param name="value">The value of the field.</param>
/// <param name="partitionKey">The optional partition key.</param>
/// <param name="cancellationToken">The optional cancellation token.</param> /// <param name="cancellationToken">The optional cancellation token.</param>
/// <returns></returns> /// <returns>A boolean value indicating success.</returns>
bool UpdateOne<TDocument, TKey, TField>(IClientSessionHandle session, FilterDefinition<TDocument> filter, Expression<Func<TDocument, TField>> field, TField value, string partitionKey = null, CancellationToken cancellationToken = default(CancellationToken)) bool UpdateOne<TDocument, TKey, TField>(IClientSessionHandle session, FilterDefinition<TDocument> filter, Expression<Func<TDocument, TField>> field, TField value, string partitionKey = null, CancellationToken cancellationToken = default(CancellationToken))
where TDocument : IDocument<TKey> where TDocument : IDocument<TKey>
where TKey : IEquatable<TKey>; where TKey : IEquatable<TKey>;
@@ -40,11 +51,13 @@ namespace MongoDbGenericRepository.DataAccess.Update
/// </summary> /// </summary>
/// <typeparam name="TDocument">The type representing a Document.</typeparam> /// <typeparam name="TDocument">The type representing a Document.</typeparam>
/// <typeparam name="TKey">The type of the primary key for a Document.</typeparam> /// <typeparam name="TKey">The type of the primary key for a Document.</typeparam>
/// <typeparam name="TField">The type of the field to update.</typeparam>
/// <param name="session">The client session.</param> /// <param name="session">The client session.</param>
/// <param name="documentToModify">The document to modify.</param> /// <param name="documentToModify">The document to modify.</param>
/// <param name="update">The update definition.</param> /// <param name="field">The field to update.</param>
/// <param name="value">The value of the field.</param>
/// <param name="cancellationToken">The optional cancellation token.</param> /// <param name="cancellationToken">The optional cancellation token.</param>
/// <returns></returns> /// <returns>A boolean value indicating success.</returns>
bool UpdateOne<TDocument, TKey, TField>(IClientSessionHandle session, TDocument documentToModify, Expression<Func<TDocument, TField>> field, TField value, CancellationToken cancellationToken = default(CancellationToken)) bool UpdateOne<TDocument, TKey, TField>(IClientSessionHandle session, TDocument documentToModify, Expression<Func<TDocument, TField>> field, TField value, CancellationToken cancellationToken = default(CancellationToken))
where TDocument : IDocument<TKey> where TDocument : IDocument<TKey>
where TKey : IEquatable<TKey>; where TKey : IEquatable<TKey>;
@@ -55,10 +68,9 @@ namespace MongoDbGenericRepository.DataAccess.Update
/// <typeparam name="TDocument">The type representing a Document.</typeparam> /// <typeparam name="TDocument">The type representing a Document.</typeparam>
/// <typeparam name="TKey">The type of the primary key for a Document.</typeparam> /// <typeparam name="TKey">The type of the primary key for a Document.</typeparam>
/// <param name="session">The client session.</param> /// <param name="session">The client session.</param>
/// <param name="documentToModify">The document to modify.</param> /// <param name="modifiedDocument">The document with the modifications you want to persist.</param>
/// <param name="update">The update definition.</param>
/// <param name="cancellationToken">The optional cancellation token.</param> /// <param name="cancellationToken">The optional cancellation token.</param>
/// <returns></returns> /// <returns>A boolean value indicating success.</returns>
bool UpdateOne<TDocument, TKey>(IClientSessionHandle session, TDocument modifiedDocument, CancellationToken cancellationToken = default(CancellationToken)) bool UpdateOne<TDocument, TKey>(IClientSessionHandle session, TDocument modifiedDocument, CancellationToken cancellationToken = default(CancellationToken))
where TDocument : IDocument<TKey> where TDocument : IDocument<TKey>
where TKey : IEquatable<TKey>; where TKey : IEquatable<TKey>;
@@ -68,13 +80,11 @@ namespace MongoDbGenericRepository.DataAccess.Update
/// </summary> /// </summary>
/// <typeparam name="TDocument">The type representing a Document.</typeparam> /// <typeparam name="TDocument">The type representing a Document.</typeparam>
/// <typeparam name="TKey">The type of the primary key for a Document.</typeparam> /// <typeparam name="TKey">The type of the primary key for a Document.</typeparam>
/// <typeparam name="TField">The type of the field to update.</typeparam> /// <param name="session">The client session.</param>
/// <param name="session">The client session.</param>
/// <param name="documentToModify">The document to modify.</param> /// <param name="documentToModify">The document to modify.</param>
/// <param name="field">The field to update.</param> /// <param name="update">The update definition.</param>
/// <param name="value">The value of the field.</param>
/// <param name="cancellationToken">The optional cancellation token.</param> /// <param name="cancellationToken">The optional cancellation token.</param>
/// <returns></returns> /// <returns>A boolean value indicating success.</returns>
bool UpdateOne<TDocument, TKey>(IClientSessionHandle session, TDocument documentToModify, UpdateDefinition<TDocument> update, CancellationToken cancellationToken = default(CancellationToken)) bool UpdateOne<TDocument, TKey>(IClientSessionHandle session, TDocument documentToModify, UpdateDefinition<TDocument> update, CancellationToken cancellationToken = default(CancellationToken))
where TDocument : IDocument<TKey> where TDocument : IDocument<TKey>
where TKey : IEquatable<TKey>; where TKey : IEquatable<TKey>;
@@ -86,11 +96,12 @@ namespace MongoDbGenericRepository.DataAccess.Update
/// <typeparam name="TKey">The type of the primary key for a Document.</typeparam> /// <typeparam name="TKey">The type of the primary key for a Document.</typeparam>
/// <typeparam name="TField">The type of the field to update.</typeparam> /// <typeparam name="TField">The type of the field to update.</typeparam>
/// <param name="session">The client session.</param> /// <param name="session">The client session.</param>
/// <param name="documentToModify">The document to modify.</param> /// <param name="filter">The filter for the update.</param>
/// <param name="field">The field to update.</param> /// <param name="field">The field to update.</param>
/// <param name="value">The value of the field.</param> /// <param name="value">The value of the field.</param>
/// <param name="partitionKey">The optional partition key.</param>
/// <param name="cancellationToken">The optional cancellation token.</param> /// <param name="cancellationToken">The optional cancellation token.</param>
/// <returns></returns> /// <returns>A boolean value indicating success.</returns>
Task<bool> UpdateOneAsync<TDocument, TKey, TField>(IClientSessionHandle session, Expression<Func<TDocument, bool>> filter, Expression<Func<TDocument, TField>> field, TField value, string partitionKey = null, CancellationToken cancellationToken = default(CancellationToken)) Task<bool> UpdateOneAsync<TDocument, TKey, TField>(IClientSessionHandle session, Expression<Func<TDocument, bool>> filter, Expression<Func<TDocument, TField>> field, TField value, string partitionKey = null, CancellationToken cancellationToken = default(CancellationToken))
where TDocument : IDocument<TKey> where TDocument : IDocument<TKey>
where TKey : IEquatable<TKey>; where TKey : IEquatable<TKey>;
@@ -118,13 +129,12 @@ namespace MongoDbGenericRepository.DataAccess.Update
/// <typeparam name="TDocument">The type representing a Document.</typeparam> /// <typeparam name="TDocument">The type representing a Document.</typeparam>
/// <typeparam name="TKey">The type of the primary key for a Document.</typeparam> /// <typeparam name="TKey">The type of the primary key for a Document.</typeparam>
/// <typeparam name="TField">The type of the field to update.</typeparam> /// <typeparam name="TField">The type of the field to update.</typeparam>
/// <param name="session">The client session.</param> /// <param name="session">The client session.</param>
/// <param name="filter">The filter for the update.</param> /// <param name="documentToModify">The document to modify.</param>
/// <param name="field">The field to update.</param> /// <param name="field">The field to update.</param>
/// <param name="value">The value of the field.</param> /// <param name="value">The value of the field.</param>
/// <param name="partitionKey">The optional partition key.</param>
/// <param name="cancellationToken">The optional cancellation token.</param> /// <param name="cancellationToken">The optional cancellation token.</param>
/// <returns></returns> /// <returns>A boolean value indicating success.</returns>
Task<bool> UpdateOneAsync<TDocument, TKey, TField>(IClientSessionHandle session, TDocument documentToModify, Expression<Func<TDocument, TField>> field, TField value, CancellationToken cancellationToken = default(CancellationToken)) Task<bool> UpdateOneAsync<TDocument, TKey, TField>(IClientSessionHandle session, TDocument documentToModify, Expression<Func<TDocument, TField>> field, TField value, CancellationToken cancellationToken = default(CancellationToken))
where TDocument : IDocument<TKey> where TDocument : IDocument<TKey>
where TKey : IEquatable<TKey>; where TKey : IEquatable<TKey>;
@@ -134,14 +144,10 @@ namespace MongoDbGenericRepository.DataAccess.Update
/// </summary> /// </summary>
/// <typeparam name="TDocument">The type representing a Document.</typeparam> /// <typeparam name="TDocument">The type representing a Document.</typeparam>
/// <typeparam name="TKey">The type of the primary key for a Document.</typeparam> /// <typeparam name="TKey">The type of the primary key for a Document.</typeparam>
/// <typeparam name="TField">The type of the field to update.</typeparam>
/// <param name="session">The client session.</param> /// <param name="session">The client session.</param>
/// <param name="filter">The filter for the update.</param> /// <param name="modifiedDocument">The document with the modifications you want to persist.</param>
/// <param name="field">The field to update.</param>
/// <param name="value">The value of the field.</param>
/// <param name="partitionKey">The optional partition key.</param>
/// <param name="cancellationToken">The optional cancellation token.</param> /// <param name="cancellationToken">The optional cancellation token.</param>
/// <returns></returns> /// <returns>A boolean value indicating success.</returns>
Task<bool> UpdateOneAsync<TDocument, TKey>(IClientSessionHandle session, TDocument modifiedDocument, CancellationToken cancellationToken = default(CancellationToken)) Task<bool> UpdateOneAsync<TDocument, TKey>(IClientSessionHandle session, TDocument modifiedDocument, CancellationToken cancellationToken = default(CancellationToken))
where TDocument : IDocument<TKey> where TDocument : IDocument<TKey>
where TKey : IEquatable<TKey>; where TKey : IEquatable<TKey>;
@@ -151,14 +157,11 @@ namespace MongoDbGenericRepository.DataAccess.Update
/// </summary> /// </summary>
/// <typeparam name="TDocument">The type representing a Document.</typeparam> /// <typeparam name="TDocument">The type representing a Document.</typeparam>
/// <typeparam name="TKey">The type of the primary key for a Document.</typeparam> /// <typeparam name="TKey">The type of the primary key for a Document.</typeparam>
/// <typeparam name="TField">The type of the field to update.</typeparam>
/// <param name="session">The client session.</param> /// <param name="session">The client session.</param>
/// <param name="filter">The filter for the update.</param> /// <param name="documentToModify">The document to modify.</param>
/// <param name="field">The field to update.</param> /// <param name="update">The update definition.</param>
/// <param name="value">The value of the field.</param>
/// <param name="partitionKey">The optional partition key.</param>
/// <param name="cancellationToken">The optional cancellation token.</param> /// <param name="cancellationToken">The optional cancellation token.</param>
/// <returns></returns> /// <returns>A boolean value indicating success.</returns>
Task<bool> UpdateOneAsync<TDocument, TKey>(IClientSessionHandle session, TDocument documentToModify, UpdateDefinition<TDocument> update, CancellationToken cancellationToken = default(CancellationToken)) Task<bool> UpdateOneAsync<TDocument, TKey>(IClientSessionHandle session, TDocument documentToModify, UpdateDefinition<TDocument> update, CancellationToken cancellationToken = default(CancellationToken))
where TDocument : IDocument<TKey> where TDocument : IDocument<TKey>
where TKey : IEquatable<TKey>; where TKey : IEquatable<TKey>;
@@ -4,6 +4,7 @@ using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Linq.Expressions; using System.Linq.Expressions;
using System.Threading;
using System.Threading.Tasks; using System.Threading.Tasks;
namespace MongoDbGenericRepository namespace MongoDbGenericRepository
@@ -32,7 +33,8 @@ namespace MongoDbGenericRepository
/// <typeparam name="TKey">The type of the primary key for a Document.</typeparam> /// <typeparam name="TKey">The type of the primary key for a Document.</typeparam>
/// <param name="id">The Id of the document you want to get.</param> /// <param name="id">The Id of the document you want to get.</param>
/// <param name="partitionKey">An optional partition key.</param> /// <param name="partitionKey">An optional partition key.</param>
Task<TDocument> GetByIdAsync<TDocument, TKey>(TKey id, string partitionKey = null) /// <param name="cancellationToken">An optional cancellation Token.</param>
Task<TDocument> GetByIdAsync<TDocument, TKey>(TKey id, string partitionKey = null, CancellationToken cancellationToken = default)
where TDocument : IDocument<TKey> where TDocument : IDocument<TKey>
where TKey : IEquatable<TKey>; where TKey : IEquatable<TKey>;
@@ -54,7 +56,8 @@ namespace MongoDbGenericRepository
/// <typeparam name="TKey">The type of the primary key for a Document.</typeparam> /// <typeparam name="TKey">The type of the primary key for a Document.</typeparam>
/// <param name="filter">A LINQ expression filter.</param> /// <param name="filter">A LINQ expression filter.</param>
/// <param name="partitionKey">An optional partition key.</param> /// <param name="partitionKey">An optional partition key.</param>
Task<TDocument> GetOneAsync<TDocument, TKey>(Expression<Func<TDocument, bool>> filter, string partitionKey = null) /// <param name="cancellationToken">An optional cancellation Token.</param>
Task<TDocument> GetOneAsync<TDocument, TKey>(Expression<Func<TDocument, bool>> filter, string partitionKey = null, CancellationToken cancellationToken = default)
where TDocument : IDocument<TKey> where TDocument : IDocument<TKey>
where TKey : IEquatable<TKey>; where TKey : IEquatable<TKey>;
@@ -88,7 +91,8 @@ namespace MongoDbGenericRepository
/// <typeparam name="TKey">The type of the primary key for a Document.</typeparam> /// <typeparam name="TKey">The type of the primary key for a Document.</typeparam>
/// <param name="filter">A LINQ expression filter.</param> /// <param name="filter">A LINQ expression filter.</param>
/// <param name="partitionKey">An optional partition key.</param> /// <param name="partitionKey">An optional partition key.</param>
Task<bool> AnyAsync<TDocument, TKey>(Expression<Func<TDocument, bool>> filter, string partitionKey = null) /// <param name="cancellationToken">An optional cancellation Token.</param>
Task<bool> AnyAsync<TDocument, TKey>(Expression<Func<TDocument, bool>> filter, string partitionKey = null, CancellationToken cancellationToken = default)
where TDocument : IDocument<TKey> where TDocument : IDocument<TKey>
where TKey : IEquatable<TKey>; where TKey : IEquatable<TKey>;
@@ -110,7 +114,8 @@ namespace MongoDbGenericRepository
/// <typeparam name="TKey">The type of the primary key for a Document.</typeparam> /// <typeparam name="TKey">The type of the primary key for a Document.</typeparam>
/// <param name="filter">A LINQ expression filter.</param> /// <param name="filter">A LINQ expression filter.</param>
/// <param name="partitionKey">An optional partition key.</param> /// <param name="partitionKey">An optional partition key.</param>
Task<List<TDocument>> GetAllAsync<TDocument, TKey>(Expression<Func<TDocument, bool>> filter, string partitionKey = null) /// <param name="cancellationToken">An optional cancellation Token.</param>
Task<List<TDocument>> GetAllAsync<TDocument, TKey>(Expression<Func<TDocument, bool>> filter, string partitionKey = null, CancellationToken cancellationToken = default)
where TDocument : IDocument<TKey> where TDocument : IDocument<TKey>
where TKey : IEquatable<TKey>; where TKey : IEquatable<TKey>;
@@ -132,7 +137,8 @@ namespace MongoDbGenericRepository
/// <typeparam name="TKey">The type of the primary key for a Document.</typeparam> /// <typeparam name="TKey">The type of the primary key for a Document.</typeparam>
/// <param name="filter">A LINQ expression filter.</param> /// <param name="filter">A LINQ expression filter.</param>
/// <param name="partitionKey">An optional partitionKey</param> /// <param name="partitionKey">An optional partitionKey</param>
Task<long> CountAsync<TDocument, TKey>(Expression<Func<TDocument, bool>> filter, string partitionKey = null) /// <param name="cancellationToken">An optional cancellation Token.</param>
Task<long> CountAsync<TDocument, TKey>(Expression<Func<TDocument, bool>> filter, string partitionKey = null, CancellationToken cancellationToken = default)
where TDocument : IDocument<TKey> where TDocument : IDocument<TKey>
where TKey : IEquatable<TKey>; where TKey : IEquatable<TKey>;
@@ -157,9 +163,13 @@ namespace MongoDbGenericRepository
/// <typeparam name="TDocument">The document type.</typeparam> /// <typeparam name="TDocument">The document type.</typeparam>
/// <typeparam name="TKey">The type of the primary key.</typeparam> /// <typeparam name="TKey">The type of the primary key.</typeparam>
/// <param name="filter">A LINQ expression filter.</param> /// <param name="filter">A LINQ expression filter.</param>
/// <param name="orderByDescending">A property selector to order by descending.</param> /// <param name="maxValueSelector">A property selector to order by descending.</param>
/// <param name="partitionKey">An optional partitionKey.</param> /// <param name="partitionKey">An optional partitionKey.</param>
Task<TDocument> GetByMaxAsync<TDocument, TKey>(Expression<Func<TDocument, bool>> filter, Expression<Func<TDocument, object>> orderByDescending, string partitionKey = null) /// <param name="cancellationToken">An optional cancellation Token.</param>
Task<TDocument> GetByMaxAsync<TDocument, TKey>(
Expression<Func<TDocument, bool>> filter,
Expression<Func<TDocument, object>> maxValueSelector,
string partitionKey = null, CancellationToken cancellationToken = default)
where TDocument : IDocument<TKey> where TDocument : IDocument<TKey>
where TKey : IEquatable<TKey>; where TKey : IEquatable<TKey>;
@@ -181,9 +191,13 @@ namespace MongoDbGenericRepository
/// <typeparam name="TDocument">The document type.</typeparam> /// <typeparam name="TDocument">The document type.</typeparam>
/// <typeparam name="TKey">The type of the primary key.</typeparam> /// <typeparam name="TKey">The type of the primary key.</typeparam>
/// <param name="filter">A LINQ expression filter.</param> /// <param name="filter">A LINQ expression filter.</param>
/// <param name="orderByAscending">A property selector to order by ascending.</param> /// <param name="minValueSelector">A property selector for the minimum value you are looking for.</param>
/// <param name="partitionKey">An optional partitionKey.</param> /// <param name="partitionKey">An optional partitionKey.</param>
Task<TDocument> GetByMinAsync<TDocument, TKey>(Expression<Func<TDocument, bool>> filter, Expression<Func<TDocument, object>> orderByAscending, string partitionKey = null) /// <param name="cancellationToken">An optional cancellation Token.</param>
Task<TDocument> GetByMinAsync<TDocument, TKey>(Expression<Func<TDocument, bool>> filter,
Expression<Func<TDocument, object>> minValueSelector,
string partitionKey = null,
CancellationToken cancellationToken = default)
where TDocument : IDocument<TKey> where TDocument : IDocument<TKey>
where TKey : IEquatable<TKey>; where TKey : IEquatable<TKey>;
@@ -193,9 +207,9 @@ namespace MongoDbGenericRepository
/// <typeparam name="TDocument">The document type.</typeparam> /// <typeparam name="TDocument">The document type.</typeparam>
/// <typeparam name="TKey">The type of the primary key.</typeparam> /// <typeparam name="TKey">The type of the primary key.</typeparam>
/// <param name="filter">A LINQ expression filter.</param> /// <param name="filter">A LINQ expression filter.</param>
/// <param name="orderByAscending">A property selector to order by ascending.</param> /// <param name="minValueSelector">A property selector for the minimum value you are looking for.</param>
/// <param name="partitionKey">An optional partitionKey.</param> /// <param name="partitionKey">An optional partitionKey.</param>
TDocument GetByMin<TDocument, TKey>(Expression<Func<TDocument, bool>> filter, Expression<Func<TDocument, object>> orderByAscending, string partitionKey = null) TDocument GetByMin<TDocument, TKey>(Expression<Func<TDocument, bool>> filter, Expression<Func<TDocument, object>> minValueSelector, string partitionKey = null)
where TDocument : IDocument<TKey> where TDocument : IDocument<TKey>
where TKey : IEquatable<TKey>; where TKey : IEquatable<TKey>;
@@ -206,9 +220,14 @@ namespace MongoDbGenericRepository
/// <typeparam name="TKey">The type of the primary key.</typeparam> /// <typeparam name="TKey">The type of the primary key.</typeparam>
/// <typeparam name="TValue">The type of the value used to order the query.</typeparam> /// <typeparam name="TValue">The type of the value used to order the query.</typeparam>
/// <param name="filter">A LINQ expression filter.</param> /// <param name="filter">A LINQ expression filter.</param>
/// <param name="orderByAscending">A property selector to order by ascending.</param> /// <param name="maxValueSelector">A property selector for the maximum value you are looking for.</param>
/// <param name="partitionKey">An optional partitionKey.</param> /// <param name="partitionKey">An optional partitionKey.</param>
Task<TValue> GetMaxValueAsync<TDocument, TKey, TValue>(Expression<Func<TDocument, bool>> filter, Expression<Func<TDocument, TValue>> orderByAscending, string partitionKey = null) /// <param name="cancellationToken">An optional cancellation Token.</param>
Task<TValue> GetMaxValueAsync<TDocument, TKey, TValue>(
Expression<Func<TDocument, bool>> filter,
Expression<Func<TDocument, TValue>> maxValueSelector,
string partitionKey = null,
CancellationToken cancellationToken = default)
where TDocument : IDocument<TKey> where TDocument : IDocument<TKey>
where TKey : IEquatable<TKey>; where TKey : IEquatable<TKey>;
@@ -219,9 +238,9 @@ namespace MongoDbGenericRepository
/// <typeparam name="TKey">The type of the primary key.</typeparam> /// <typeparam name="TKey">The type of the primary key.</typeparam>
/// <typeparam name="TValue">The type of the value used to order the query.</typeparam> /// <typeparam name="TValue">The type of the value used to order the query.</typeparam>
/// <param name="filter">A LINQ expression filter.</param> /// <param name="filter">A LINQ expression filter.</param>
/// <param name="orderByDescending">A property selector to order by ascending.</param> /// <param name="maxValueSelector">A property selector to order by ascending.</param>
/// <param name="partitionKey">An optional partitionKey.</param> /// <param name="partitionKey">An optional partitionKey.</param>
TValue GetMaxValue<TDocument, TKey, TValue>(Expression<Func<TDocument, bool>> filter, Expression<Func<TDocument, TValue>> orderByDescending, string partitionKey = null) TValue GetMaxValue<TDocument, TKey, TValue>(Expression<Func<TDocument, bool>> filter, Expression<Func<TDocument, TValue>> maxValueSelector, string partitionKey = null)
where TDocument : IDocument<TKey> where TDocument : IDocument<TKey>
where TKey : IEquatable<TKey>; where TKey : IEquatable<TKey>;
@@ -234,7 +253,12 @@ namespace MongoDbGenericRepository
/// <param name="filter">A LINQ expression filter.</param> /// <param name="filter">A LINQ expression filter.</param>
/// <param name="minValueSelector">A property selector to order by ascending.</param> /// <param name="minValueSelector">A property selector to order by ascending.</param>
/// <param name="partitionKey">An optional partition key.</param> /// <param name="partitionKey">An optional partition key.</param>
Task<TValue> GetMinValueAsync<TDocument, TKey, TValue>(Expression<Func<TDocument, bool>> filter, Expression<Func<TDocument, TValue>> minValueSelector, string partitionKey = null) /// <param name="cancellationToken">An optional cancellation Token.</param>
Task<TValue> GetMinValueAsync<TDocument, TKey, TValue>(
Expression<Func<TDocument, bool>> filter,
Expression<Func<TDocument, TValue>> minValueSelector,
string partitionKey = null,
CancellationToken cancellationToken = default)
where TDocument : IDocument<TKey> where TDocument : IDocument<TKey>
where TKey : IEquatable<TKey>; where TKey : IEquatable<TKey>;
@@ -263,9 +287,11 @@ namespace MongoDbGenericRepository
/// <param name="filter">A LINQ expression filter.</param> /// <param name="filter">A LINQ expression filter.</param>
/// <param name="selector">The field you want to sum.</param> /// <param name="selector">The field you want to sum.</param>
/// <param name="partitionKey">The partition key of your document, if any.</param> /// <param name="partitionKey">The partition key of your document, if any.</param>
/// <param name="cancellationToken">An optional cancellation Token.</param>
Task<int> SumByAsync<TDocument, TKey>(Expression<Func<TDocument, bool>> filter, Task<int> SumByAsync<TDocument, TKey>(Expression<Func<TDocument, bool>> filter,
Expression<Func<TDocument, int>> selector, Expression<Func<TDocument, int>> selector,
string partitionKey = null) string partitionKey = null,
CancellationToken cancellationToken = default)
where TDocument : IDocument<TKey> where TDocument : IDocument<TKey>
where TKey : IEquatable<TKey>; where TKey : IEquatable<TKey>;
@@ -321,10 +347,15 @@ namespace MongoDbGenericRepository
/// <typeparam name="TDocument">The type representing a Document.</typeparam> /// <typeparam name="TDocument">The type representing a Document.</typeparam>
/// <typeparam name="TKey">The type of the primary key for a Document.</typeparam> /// <typeparam name="TKey">The type of the primary key for a Document.</typeparam>
/// <typeparam name="TProjection">The type representing the model you want to project to.</typeparam> /// <typeparam name="TProjection">The type representing the model you want to project to.</typeparam>
/// <param name="filter"></param> /// <param name="filter">A LINQ expression filter.</param>
/// <param name="projection">The projection expression.</param> /// <param name="projection">The projection expression.</param>
/// <param name="partitionKey">An optional partition key.</param> /// <param name="partitionKey">An optional partition key.</param>
Task<TProjection> ProjectOneAsync<TDocument, TProjection, TKey>(Expression<Func<TDocument, bool>> filter, Expression<Func<TDocument, TProjection>> projection, string partitionKey = null) /// <param name="cancellationToken">An optional cancellation Token.</param>
Task<TProjection> ProjectOneAsync<TDocument, TProjection, TKey>(
Expression<Func<TDocument, bool>> filter,
Expression<Func<TDocument, TProjection>> projection,
string partitionKey = null,
CancellationToken cancellationToken = default)
where TDocument : IDocument<TKey> where TDocument : IDocument<TKey>
where TKey : IEquatable<TKey> where TKey : IEquatable<TKey>
where TProjection : class; where TProjection : class;
@@ -349,13 +380,18 @@ namespace MongoDbGenericRepository
/// <typeparam name="TDocument">The type representing a Document.</typeparam> /// <typeparam name="TDocument">The type representing a Document.</typeparam>
/// <typeparam name="TKey">The type of the primary key for a Document.</typeparam> /// <typeparam name="TKey">The type of the primary key for a Document.</typeparam>
/// <typeparam name="TProjection">The type representing the model you want to project to.</typeparam> /// <typeparam name="TProjection">The type representing the model you want to project to.</typeparam>
/// <param name="filter"></param> /// <param name="filter">A LINQ expression filter.</param>
/// <param name="projection">The projection expression.</param> /// <param name="projection">The projection expression.</param>
/// <param name="partitionKey">An optional partition key.</param> /// <param name="partitionKey">An optional partition key.</param>
Task<List<TProjection>> ProjectManyAsync<TDocument, TProjection, TKey>(Expression<Func<TDocument, bool>> filter, Expression<Func<TDocument, TProjection>> projection, string partitionKey = null) /// <param name="cancellationToken">An optional cancellation Token.</param>
where TDocument : IDocument<TKey> Task<List<TProjection>> ProjectManyAsync<TDocument, TProjection, TKey>(
where TKey : IEquatable<TKey> Expression<Func<TDocument, bool>> filter,
where TProjection : class; Expression<Func<TDocument, TProjection>> projection,
string partitionKey = null,
CancellationToken cancellationToken = default)
where TDocument : IDocument<TKey>
where TKey : IEquatable<TKey>
where TProjection : class;
/// <summary> /// <summary>
/// Asynchronously returns a list of projected documents matching the filter condition. /// Asynchronously returns a list of projected documents matching the filter condition.
@@ -450,12 +486,14 @@ namespace MongoDbGenericRepository
/// <param name="skipNumber">The number of documents you want to skip. Default value is 0.</param> /// <param name="skipNumber">The number of documents you want to skip. Default value is 0.</param>
/// <param name="takeNumber">The number of documents you want to take. Default value is 50.</param> /// <param name="takeNumber">The number of documents you want to take. Default value is 50.</param>
/// <param name="partitionKey">An optional partition key.</param> /// <param name="partitionKey">An optional partition key.</param>
/// <param name="cancellationToken">An optional cancellation Token.</param>
Task<List<TDocument>> GetSortedPaginatedAsync<TDocument, TKey>( Task<List<TDocument>> GetSortedPaginatedAsync<TDocument, TKey>(
Expression<Func<TDocument, bool>> filter, Expression<Func<TDocument, bool>> filter,
SortDefinition<TDocument> sortDefinition, SortDefinition<TDocument> sortDefinition,
int skipNumber = 0, int skipNumber = 0,
int takeNumber = 50, int takeNumber = 50,
string partitionKey = null) string partitionKey = null,
CancellationToken cancellationToken = default)
where TDocument : IDocument<TKey> where TDocument : IDocument<TKey>
where TKey : IEquatable<TKey>; where TKey : IEquatable<TKey>;
@@ -2,10 +2,15 @@
using MongoDbGenericRepository.Models; using MongoDbGenericRepository.Models;
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Threading;
using System.Threading.Tasks; using System.Threading.Tasks;
namespace MongoDbGenericRepository namespace MongoDbGenericRepository
{ {
/// <summary>
/// The IBaseMongoRepository_Create interface to expose document creation functionality
/// with document having an Id of type Guid.
/// </summary>
public interface IBaseMongoRepository_Create : IBaseMongoRepository_Create<Guid> public interface IBaseMongoRepository_Create : IBaseMongoRepository_Create<Guid>
{ {
/// <summary> /// <summary>
@@ -15,7 +20,8 @@ namespace MongoDbGenericRepository
/// <typeparam name="TDocument">The type representing a Document.</typeparam> /// <typeparam name="TDocument">The type representing a Document.</typeparam>
/// <typeparam name="TKey">The type of the primary key for a Document.</typeparam> /// <typeparam name="TKey">The type of the primary key for a Document.</typeparam>
/// <param name="document">The document you want to add.</param> /// <param name="document">The document you want to add.</param>
Task AddOneAsync<TDocument, TKey>(TDocument document) /// <param name="cancellationToken">An optional cancellation Token.</param>
Task AddOneAsync<TDocument, TKey>(TDocument document, CancellationToken cancellationToken = default)
where TDocument : IDocument<TKey> where TDocument : IDocument<TKey>
where TKey : IEquatable<TKey>; where TKey : IEquatable<TKey>;
@@ -37,7 +43,8 @@ namespace MongoDbGenericRepository
/// <typeparam name="TDocument">The type representing a Document.</typeparam> /// <typeparam name="TDocument">The type representing a Document.</typeparam>
/// <typeparam name="TKey">The type of the primary key for a Document.</typeparam> /// <typeparam name="TKey">The type of the primary key for a Document.</typeparam>
/// <param name="documents">The documents you want to add.</param> /// <param name="documents">The documents you want to add.</param>
Task AddManyAsync<TDocument, TKey>(IEnumerable<TDocument> documents) /// <param name="cancellationToken">An optional cancellation Token.</param>
Task AddManyAsync<TDocument, TKey>(IEnumerable<TDocument> documents, CancellationToken cancellationToken = default)
where TDocument : IDocument<TKey> where TDocument : IDocument<TKey>
where TKey : IEquatable<TKey>; where TKey : IEquatable<TKey>;
@@ -61,6 +68,10 @@ namespace MongoDbGenericRepository
{ {
private readonly object _initLock = new object(); private readonly object _initLock = new object();
private MongoDbCreator _mongoDbCreator; private MongoDbCreator _mongoDbCreator;
/// <summary>
/// The MongoDbCreator field.
/// </summary>
protected virtual MongoDbCreator MongoDbCreator protected virtual MongoDbCreator MongoDbCreator
{ {
get get
@@ -87,11 +98,12 @@ namespace MongoDbGenericRepository
/// <typeparam name="TDocument">The type representing a Document.</typeparam> /// <typeparam name="TDocument">The type representing a Document.</typeparam>
/// <typeparam name="TKey">The type of the primary key for a Document.</typeparam> /// <typeparam name="TKey">The type of the primary key for a Document.</typeparam>
/// <param name="document">The document you want to add.</param> /// <param name="document">The document you want to add.</param>
public virtual async Task AddOneAsync<TDocument, TKey>(TDocument document) /// <param name="cancellationToken">An optional cancellation Token.</param>
public virtual async Task AddOneAsync<TDocument, TKey>(TDocument document, CancellationToken cancellationToken = default)
where TDocument : IDocument<TKey> where TDocument : IDocument<TKey>
where TKey : IEquatable<TKey> where TKey : IEquatable<TKey>
{ {
await MongoDbCreator.AddOneAsync<TDocument, TKey>(document); await MongoDbCreator.AddOneAsync<TDocument, TKey>(document, cancellationToken);
} }
/// <summary> /// <summary>
@@ -100,10 +112,11 @@ namespace MongoDbGenericRepository
/// </summary> /// </summary>
/// <typeparam name="TDocument">The type representing a Document.</typeparam> /// <typeparam name="TDocument">The type representing a Document.</typeparam>
/// <param name="document">The document you want to add.</param> /// <param name="document">The document you want to add.</param>
public virtual async Task AddOneAsync<TDocument>(TDocument document) /// <param name="cancellationToken">An optional cancellation Token.</param>
public virtual async Task AddOneAsync<TDocument>(TDocument document, CancellationToken cancellationToken = default)
where TDocument : IDocument<Guid> where TDocument : IDocument<Guid>
{ {
await MongoDbCreator.AddOneAsync<TDocument, Guid>(document); await MongoDbCreator.AddOneAsync<TDocument, Guid>(document, cancellationToken);
} }
/// <summary> /// <summary>
@@ -138,11 +151,12 @@ namespace MongoDbGenericRepository
/// <typeparam name="TDocument">The type representing a Document.</typeparam> /// <typeparam name="TDocument">The type representing a Document.</typeparam>
/// <typeparam name="TKey">The type of the primary key for a Document.</typeparam> /// <typeparam name="TKey">The type of the primary key for a Document.</typeparam>
/// <param name="documents">The documents you want to add.</param> /// <param name="documents">The documents you want to add.</param>
public virtual async Task AddManyAsync<TDocument, TKey>(IEnumerable<TDocument> documents) /// <param name="cancellationToken">An optional cancellation Token.</param>
public virtual async Task AddManyAsync<TDocument, TKey>(IEnumerable<TDocument> documents, CancellationToken cancellationToken = default)
where TDocument : IDocument<TKey> where TDocument : IDocument<TKey>
where TKey : IEquatable<TKey> where TKey : IEquatable<TKey>
{ {
await MongoDbCreator.AddManyAsync<TDocument, TKey>(documents); await MongoDbCreator.AddManyAsync<TDocument, TKey>(documents, cancellationToken);
} }
/// <summary> /// <summary>
@@ -151,10 +165,11 @@ namespace MongoDbGenericRepository
/// </summary> /// </summary>
/// <typeparam name="TDocument">The type representing a Document.</typeparam> /// <typeparam name="TDocument">The type representing a Document.</typeparam>
/// <param name="documents">The documents you want to add.</param> /// <param name="documents">The documents you want to add.</param>
public virtual async Task AddManyAsync<TDocument>(IEnumerable<TDocument> documents) /// <param name="cancellationToken">An optional cancellation Token.</param>
public virtual async Task AddManyAsync<TDocument>(IEnumerable<TDocument> documents, CancellationToken cancellationToken = default)
where TDocument : IDocument<Guid> where TDocument : IDocument<Guid>
{ {
await MongoDbCreator.AddManyAsync<TDocument, Guid>(documents); await MongoDbCreator.AddManyAsync<TDocument, Guid>(documents, cancellationToken);
} }
/// <summary> /// <summary>
@@ -18,7 +18,7 @@ namespace MongoDbGenericRepository
/// <param name="session">The client session.</param> /// <param name="session">The client session.</param>
/// <param name="modifiedDocument">The document with the modifications you want to persist.</param> /// <param name="modifiedDocument">The document with the modifications you want to persist.</param>
/// <param name="cancellationToken">The optional cancellation token.</param> /// <param name="cancellationToken">The optional cancellation token.</param>
/// <returns></returns> /// <returns>A boolean value indicating success.</returns>
public virtual async Task<bool> UpdateOneAsync<TDocument, TKey>(IClientSessionHandle session, TDocument modifiedDocument, CancellationToken cancellationToken = default(CancellationToken)) public virtual async Task<bool> UpdateOneAsync<TDocument, TKey>(IClientSessionHandle session, TDocument modifiedDocument, CancellationToken cancellationToken = default(CancellationToken))
where TDocument : IDocument<TKey> where TDocument : IDocument<TKey>
where TKey : IEquatable<TKey> where TKey : IEquatable<TKey>
@@ -34,7 +34,7 @@ namespace MongoDbGenericRepository
/// <param name="session">The client session.</param> /// <param name="session">The client session.</param>
/// <param name="modifiedDocument">The document with the modifications you want to persist.</param> /// <param name="modifiedDocument">The document with the modifications you want to persist.</param>
/// <param name="cancellationToken">The optional cancellation token.</param> /// <param name="cancellationToken">The optional cancellation token.</param>
/// <returns></returns> /// <returns>A boolean value indicating success.</returns>
public virtual bool UpdateOne<TDocument, TKey>(IClientSessionHandle session, TDocument modifiedDocument, CancellationToken cancellationToken = default(CancellationToken)) public virtual bool UpdateOne<TDocument, TKey>(IClientSessionHandle session, TDocument modifiedDocument, CancellationToken cancellationToken = default(CancellationToken))
where TDocument : IDocument<TKey> where TDocument : IDocument<TKey>
where TKey : IEquatable<TKey> where TKey : IEquatable<TKey>
@@ -51,7 +51,7 @@ namespace MongoDbGenericRepository
/// <param name="documentToModify">The document to modify.</param> /// <param name="documentToModify">The document to modify.</param>
/// <param name="update">The update definition.</param> /// <param name="update">The update definition.</param>
/// <param name="cancellationToken">The optional cancellation token.</param> /// <param name="cancellationToken">The optional cancellation token.</param>
/// <returns></returns> /// <returns>A boolean value indicating success.</returns>
public virtual async Task<bool> UpdateOneAsync<TDocument, TKey>(IClientSessionHandle session, TDocument documentToModify, UpdateDefinition<TDocument> update, CancellationToken cancellationToken = default(CancellationToken)) public virtual async Task<bool> UpdateOneAsync<TDocument, TKey>(IClientSessionHandle session, TDocument documentToModify, UpdateDefinition<TDocument> update, CancellationToken cancellationToken = default(CancellationToken))
where TDocument : IDocument<TKey> where TDocument : IDocument<TKey>
where TKey : IEquatable<TKey> where TKey : IEquatable<TKey>
@@ -68,7 +68,7 @@ namespace MongoDbGenericRepository
/// <param name="documentToModify">The document to modify.</param> /// <param name="documentToModify">The document to modify.</param>
/// <param name="update">The update definition.</param> /// <param name="update">The update definition.</param>
/// <param name="cancellationToken">The optional cancellation token.</param> /// <param name="cancellationToken">The optional cancellation token.</param>
/// <returns></returns> /// <returns>A boolean value indicating success.</returns>
public virtual bool UpdateOne<TDocument, TKey>(IClientSessionHandle session, TDocument documentToModify, UpdateDefinition<TDocument> update, CancellationToken cancellationToken = default(CancellationToken)) public virtual bool UpdateOne<TDocument, TKey>(IClientSessionHandle session, TDocument documentToModify, UpdateDefinition<TDocument> update, CancellationToken cancellationToken = default(CancellationToken))
where TDocument : IDocument<TKey> where TDocument : IDocument<TKey>
where TKey : IEquatable<TKey> where TKey : IEquatable<TKey>
@@ -87,7 +87,7 @@ namespace MongoDbGenericRepository
/// <param name="field">The field to update.</param> /// <param name="field">The field to update.</param>
/// <param name="value">The value of the field.</param> /// <param name="value">The value of the field.</param>
/// <param name="cancellationToken">The optional cancellation token.</param> /// <param name="cancellationToken">The optional cancellation token.</param>
/// <returns></returns> /// <returns>A boolean value indicating success.</returns>
public virtual async Task<bool> UpdateOneAsync<TDocument, TKey, TField>(IClientSessionHandle session, TDocument documentToModify, Expression<Func<TDocument, TField>> field, TField value, CancellationToken cancellationToken = default(CancellationToken)) public virtual async Task<bool> UpdateOneAsync<TDocument, TKey, TField>(IClientSessionHandle session, TDocument documentToModify, Expression<Func<TDocument, TField>> field, TField value, CancellationToken cancellationToken = default(CancellationToken))
where TDocument : IDocument<TKey> where TDocument : IDocument<TKey>
where TKey : IEquatable<TKey> where TKey : IEquatable<TKey>
@@ -106,7 +106,7 @@ namespace MongoDbGenericRepository
/// <param name="field">The field to update.</param> /// <param name="field">The field to update.</param>
/// <param name="value">The value of the field.</param> /// <param name="value">The value of the field.</param>
/// <param name="cancellationToken">The optional cancellation token.</param> /// <param name="cancellationToken">The optional cancellation token.</param>
/// <returns></returns> /// <returns>A boolean value indicating success.</returns>
public virtual bool UpdateOne<TDocument, TKey, TField>(IClientSessionHandle session, TDocument documentToModify, Expression<Func<TDocument, TField>> field, TField value, CancellationToken cancellationToken = default(CancellationToken)) public virtual bool UpdateOne<TDocument, TKey, TField>(IClientSessionHandle session, TDocument documentToModify, Expression<Func<TDocument, TField>> field, TField value, CancellationToken cancellationToken = default(CancellationToken))
where TDocument : IDocument<TKey> where TDocument : IDocument<TKey>
where TKey : IEquatable<TKey> where TKey : IEquatable<TKey>
@@ -126,7 +126,7 @@ namespace MongoDbGenericRepository
/// <param name="value">The value of the field.</param> /// <param name="value">The value of the field.</param>
/// <param name="partitionKey">The optional partition key.</param> /// <param name="partitionKey">The optional partition key.</param>
/// <param name="cancellationToken">The optional cancellation token.</param> /// <param name="cancellationToken">The optional cancellation token.</param>
/// <returns></returns> /// <returns>A boolean value indicating success.</returns>
public virtual async Task<bool> UpdateOneAsync<TDocument, TKey, TField>(IClientSessionHandle session, FilterDefinition<TDocument> filter, Expression<Func<TDocument, TField>> field, TField value, string partitionKey = null, CancellationToken cancellationToken = default(CancellationToken)) public virtual async Task<bool> UpdateOneAsync<TDocument, TKey, TField>(IClientSessionHandle session, FilterDefinition<TDocument> filter, Expression<Func<TDocument, TField>> field, TField value, string partitionKey = null, CancellationToken cancellationToken = default(CancellationToken))
where TDocument : IDocument<TKey> where TDocument : IDocument<TKey>
where TKey : IEquatable<TKey> where TKey : IEquatable<TKey>
@@ -146,7 +146,7 @@ namespace MongoDbGenericRepository
/// <param name="value">The value of the field.</param> /// <param name="value">The value of the field.</param>
/// <param name="partitionKey">The optional partition key.</param> /// <param name="partitionKey">The optional partition key.</param>
/// <param name="cancellationToken">The optional cancellation token.</param> /// <param name="cancellationToken">The optional cancellation token.</param>
/// <returns></returns> /// <returns>A boolean value indicating success.</returns>
public virtual async Task<bool> UpdateOneAsync<TDocument, TKey, TField>(IClientSessionHandle session, Expression<Func<TDocument, bool>> filter, Expression<Func<TDocument, TField>> field, TField value, string partitionKey = null, CancellationToken cancellationToken = default(CancellationToken)) public virtual async Task<bool> UpdateOneAsync<TDocument, TKey, TField>(IClientSessionHandle session, Expression<Func<TDocument, bool>> filter, Expression<Func<TDocument, TField>> field, TField value, string partitionKey = null, CancellationToken cancellationToken = default(CancellationToken))
where TDocument : IDocument<TKey> where TDocument : IDocument<TKey>
where TKey : IEquatable<TKey> where TKey : IEquatable<TKey>
@@ -166,7 +166,7 @@ namespace MongoDbGenericRepository
/// <param name="value">The value of the field.</param> /// <param name="value">The value of the field.</param>
/// <param name="partitionKey">The optional partition key.</param> /// <param name="partitionKey">The optional partition key.</param>
/// <param name="cancellationToken">The optional cancellation token.</param> /// <param name="cancellationToken">The optional cancellation token.</param>
/// <returns></returns> /// <returns>A boolean value indicating success.</returns>
public virtual bool UpdateOne<TDocument, TKey, TField>(IClientSessionHandle session, FilterDefinition<TDocument> filter, Expression<Func<TDocument, TField>> field, TField value, string partitionKey = null, CancellationToken cancellationToken = default(CancellationToken)) public virtual bool UpdateOne<TDocument, TKey, TField>(IClientSessionHandle session, FilterDefinition<TDocument> filter, Expression<Func<TDocument, TField>> field, TField value, string partitionKey = null, CancellationToken cancellationToken = default(CancellationToken))
where TDocument : IDocument<TKey> where TDocument : IDocument<TKey>
where TKey : IEquatable<TKey> where TKey : IEquatable<TKey>
@@ -186,7 +186,7 @@ namespace MongoDbGenericRepository
/// <param name="value">The value of the field.</param> /// <param name="value">The value of the field.</param>
/// <param name="partitionKey">The optional partition key.</param> /// <param name="partitionKey">The optional partition key.</param>
/// <param name="cancellationToken">The optional cancellation token.</param> /// <param name="cancellationToken">The optional cancellation token.</param>
/// <returns></returns> /// <returns>A boolean value indicating success.</returns>
public virtual bool UpdateOne<TDocument, TKey, TField>(IClientSessionHandle session, Expression<Func<TDocument, bool>> filter, Expression<Func<TDocument, TField>> field, TField value, string partitionKey = null, CancellationToken cancellationToken = default(CancellationToken)) public virtual bool UpdateOne<TDocument, TKey, TField>(IClientSessionHandle session, Expression<Func<TDocument, bool>> filter, Expression<Func<TDocument, TField>> field, TField value, string partitionKey = null, CancellationToken cancellationToken = default(CancellationToken))
where TDocument : IDocument<TKey> where TDocument : IDocument<TKey>
where TKey : IEquatable<TKey> where TKey : IEquatable<TKey>
@@ -7,10 +7,20 @@ using System.Linq.Expressions;
namespace MongoDbGenericRepository.DataAccess.Base namespace MongoDbGenericRepository.DataAccess.Base
{ {
/// <summary>
/// A base class for accessing the Database and its Collections.
/// </summary>
public class DataAccessBase public class DataAccessBase
{ {
/// <summary>
/// The MongoDbContext
/// </summary>
protected IMongoDbContext MongoDbContext; protected IMongoDbContext MongoDbContext;
/// <summary>
/// The constructor of the DataAccessBase class
/// </summary>
/// <param name="mongoDbContext"></param>
public DataAccessBase(IMongoDbContext mongoDbContext) public DataAccessBase(IMongoDbContext mongoDbContext)
{ {
MongoDbContext = mongoDbContext; MongoDbContext = mongoDbContext;
@@ -18,6 +28,14 @@ namespace MongoDbGenericRepository.DataAccess.Base
#region Utility Methods #region Utility Methods
/// <summary>
/// Gets a IMongoQueryable for a potentially partitioned document type and a filter.
/// </summary>
/// <typeparam name="TDocument">The document type.</typeparam>
/// <typeparam name="TKey">The type of the primary key.</typeparam>
/// <param name="filter">The filter definition.</param>
/// <param name="partitionKey">The collection partition key.</param>
/// <returns></returns>
public virtual IMongoQueryable<TDocument> GetQuery<TDocument, TKey>(Expression<Func<TDocument, bool>> filter, string partitionKey = null) public virtual IMongoQueryable<TDocument> GetQuery<TDocument, TKey>(Expression<Func<TDocument, bool>> filter, string partitionKey = null)
where TDocument : IDocument<TKey> where TDocument : IDocument<TKey>
where TKey : IEquatable<TKey> where TKey : IEquatable<TKey>
@@ -108,7 +126,6 @@ namespace MongoDbGenericRepository.DataAccess.Base
LanguageOverride = indexCreationOptions.LanguageOverride, LanguageOverride = indexCreationOptions.LanguageOverride,
ExpireAfter = indexCreationOptions.ExpireAfter, ExpireAfter = indexCreationOptions.ExpireAfter,
DefaultLanguage = indexCreationOptions.DefaultLanguage, DefaultLanguage = indexCreationOptions.DefaultLanguage,
BucketSize = indexCreationOptions.BucketSize,
Bits = indexCreationOptions.Bits, Bits = indexCreationOptions.Bits,
Background = indexCreationOptions.Background, Background = indexCreationOptions.Background,
Version = indexCreationOptions.Version Version = indexCreationOptions.Version
@@ -6,12 +6,20 @@ using MongoDbGenericRepository.Utils;
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Threading;
using System.Threading.Tasks; using System.Threading.Tasks;
namespace MongoDbGenericRepository.DataAccess.Create namespace MongoDbGenericRepository.DataAccess.Create
{ {
/// <summary>
/// A class to insert MongoDb document.
/// </summary>
public class MongoDbCreator : DataAccessBase public class MongoDbCreator : DataAccessBase
{ {
/// <summary>
/// The construct of the MongoDbCreator class.
/// </summary>
/// <param name="mongoDbContext">A <see cref="IMongoDbContext"/> instance.</param>
public MongoDbCreator(IMongoDbContext mongoDbContext) : base(mongoDbContext) public MongoDbCreator(IMongoDbContext mongoDbContext) : base(mongoDbContext)
{ {
} }
@@ -25,12 +33,13 @@ namespace MongoDbGenericRepository.DataAccess.Create
/// <typeparam name="TDocument">The type representing a Document.</typeparam> /// <typeparam name="TDocument">The type representing a Document.</typeparam>
/// <typeparam name="TKey">The type of the primary key for a Document.</typeparam> /// <typeparam name="TKey">The type of the primary key for a Document.</typeparam>
/// <param name="document">The document you want to add.</param> /// <param name="document">The document you want to add.</param>
public virtual async Task AddOneAsync<TDocument, TKey>(TDocument document) /// <param name="cancellationToken">An optional cancellation Token.</param>
public virtual async Task AddOneAsync<TDocument, TKey>(TDocument document, CancellationToken cancellationToken = default)
where TDocument : IDocument<TKey> where TDocument : IDocument<TKey>
where TKey : IEquatable<TKey> where TKey : IEquatable<TKey>
{ {
FormatDocument<TDocument, TKey>(document); FormatDocument<TDocument, TKey>(document);
await HandlePartitioned<TDocument, TKey>(document).InsertOneAsync(document); await HandlePartitioned<TDocument, TKey>(document).InsertOneAsync(document, null, cancellationToken);
} }
/// <summary> /// <summary>
@@ -55,7 +64,8 @@ namespace MongoDbGenericRepository.DataAccess.Create
/// <typeparam name="TDocument">The type representing a Document.</typeparam> /// <typeparam name="TDocument">The type representing a Document.</typeparam>
/// <typeparam name="TKey">The type of the primary key for a Document.</typeparam> /// <typeparam name="TKey">The type of the primary key for a Document.</typeparam>
/// <param name="documents">The documents you want to add.</param> /// <param name="documents">The documents you want to add.</param>
public virtual async Task AddManyAsync<TDocument, TKey>(IEnumerable<TDocument> documents) /// <param name="cancellationToken">An optional cancellation Token.</param>
public virtual async Task AddManyAsync<TDocument, TKey>(IEnumerable<TDocument> documents, CancellationToken cancellationToken = default)
where TDocument : IDocument<TKey> where TDocument : IDocument<TKey>
where TKey : IEquatable<TKey> where TKey : IEquatable<TKey>
{ {
@@ -72,12 +82,12 @@ namespace MongoDbGenericRepository.DataAccess.Create
{ {
foreach (var group in documents.GroupBy(e => ((IPartitionedDocument)e).PartitionKey)) foreach (var group in documents.GroupBy(e => ((IPartitionedDocument)e).PartitionKey))
{ {
await HandlePartitioned<TDocument, TKey>(group.FirstOrDefault()).InsertManyAsync(group.ToList()); await HandlePartitioned<TDocument, TKey>(group.FirstOrDefault()).InsertManyAsync(group.ToList(), null, cancellationToken);
} }
} }
else else
{ {
await GetCollection<TDocument, TKey>().InsertManyAsync(documents.ToList()); await GetCollection<TDocument, TKey>().InsertManyAsync(documents.ToList(), null, cancellationToken);
} }
} }
@@ -6,12 +6,20 @@ using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Linq.Expressions; using System.Linq.Expressions;
using System.Threading;
using System.Threading.Tasks; using System.Threading.Tasks;
namespace MongoDbGenericRepository.DataAccess.Read namespace MongoDbGenericRepository.DataAccess.Read
{ {
/// <summary>
/// A class to read MongoDb document.
/// </summary>
public partial class MongoDbReader : DataAccessBase public partial class MongoDbReader : DataAccessBase
{ {
/// <summary>
/// The construct of the MongoDbReader class.
/// </summary>
/// <param name="mongoDbContext">A <see cref="IMongoDbContext"/> instance.</param>
public MongoDbReader(IMongoDbContext mongoDbContext) : base(mongoDbContext) public MongoDbReader(IMongoDbContext mongoDbContext) : base(mongoDbContext)
{ {
} }
@@ -25,12 +33,13 @@ namespace MongoDbGenericRepository.DataAccess.Read
/// <typeparam name="TKey">The type of the primary key for a Document.</typeparam> /// <typeparam name="TKey">The type of the primary key for a Document.</typeparam>
/// <param name="id">The Id of the document you want to get.</param> /// <param name="id">The Id of the document you want to get.</param>
/// <param name="partitionKey">An optional partition key.</param> /// <param name="partitionKey">An optional partition key.</param>
public async virtual Task<TDocument> GetByIdAsync<TDocument, TKey>(TKey id, string partitionKey = null) /// <param name="cancellationToken">An optional cancellation Token.</param>
public async virtual Task<TDocument> GetByIdAsync<TDocument, TKey>(TKey id, string partitionKey = null, CancellationToken cancellationToken = default)
where TDocument : IDocument<TKey> where TDocument : IDocument<TKey>
where TKey : IEquatable<TKey> where TKey : IEquatable<TKey>
{ {
var filter = Builders<TDocument>.Filter.Eq("Id", id); var filter = Builders<TDocument>.Filter.Eq("Id", id);
return await HandlePartitioned<TDocument, TKey>(partitionKey).Find(filter).FirstOrDefaultAsync(); return await HandlePartitioned<TDocument, TKey>(partitionKey).Find(filter).FirstOrDefaultAsync(cancellationToken);
} }
/// <summary> /// <summary>
@@ -55,11 +64,12 @@ namespace MongoDbGenericRepository.DataAccess.Read
/// <typeparam name="TKey">The type of the primary key for a Document.</typeparam> /// <typeparam name="TKey">The type of the primary key for a Document.</typeparam>
/// <param name="filter">A LINQ expression filter.</param> /// <param name="filter">A LINQ expression filter.</param>
/// <param name="partitionKey">An optional partition key.</param> /// <param name="partitionKey">An optional partition key.</param>
public async virtual Task<TDocument> GetOneAsync<TDocument, TKey>(Expression<Func<TDocument, bool>> filter, string partitionKey = null) /// <param name="cancellationToken">An optional cancellation Token.</param>
public async virtual Task<TDocument> GetOneAsync<TDocument, TKey>(Expression<Func<TDocument, bool>> filter, string partitionKey = null, CancellationToken cancellationToken = default)
where TDocument : IDocument<TKey> where TDocument : IDocument<TKey>
where TKey : IEquatable<TKey> where TKey : IEquatable<TKey>
{ {
return await HandlePartitioned<TDocument, TKey>(partitionKey).Find(filter).FirstOrDefaultAsync(); return await HandlePartitioned<TDocument, TKey>(partitionKey).Find(filter).FirstOrDefaultAsync(cancellationToken);
} }
/// <summary> /// <summary>
@@ -97,11 +107,12 @@ namespace MongoDbGenericRepository.DataAccess.Read
/// <typeparam name="TKey">The type of the primary key for a Document.</typeparam> /// <typeparam name="TKey">The type of the primary key for a Document.</typeparam>
/// <param name="filter">A LINQ expression filter.</param> /// <param name="filter">A LINQ expression filter.</param>
/// <param name="partitionKey">An optional partition key.</param> /// <param name="partitionKey">An optional partition key.</param>
public async virtual Task<bool> AnyAsync<TDocument, TKey>(Expression<Func<TDocument, bool>> filter, string partitionKey = null) /// <param name="cancellationToken">An optional cancellation Token.</param>
public async virtual Task<bool> AnyAsync<TDocument, TKey>(Expression<Func<TDocument, bool>> filter, string partitionKey = null, CancellationToken cancellationToken = default)
where TDocument : IDocument<TKey> where TDocument : IDocument<TKey>
where TKey : IEquatable<TKey> where TKey : IEquatable<TKey>
{ {
var count = await HandlePartitioned<TDocument, TKey>(partitionKey).CountDocumentsAsync(filter); var count = await HandlePartitioned<TDocument, TKey>(partitionKey).CountDocumentsAsync(filter, cancellationToken: cancellationToken);
return (count > 0); return (count > 0);
} }
@@ -127,11 +138,12 @@ namespace MongoDbGenericRepository.DataAccess.Read
/// <typeparam name="TKey">The type of the primary key for a Document.</typeparam> /// <typeparam name="TKey">The type of the primary key for a Document.</typeparam>
/// <param name="filter">A LINQ expression filter.</param> /// <param name="filter">A LINQ expression filter.</param>
/// <param name="partitionKey">An optional partition key.</param> /// <param name="partitionKey">An optional partition key.</param>
public async virtual Task<List<TDocument>> GetAllAsync<TDocument, TKey>(Expression<Func<TDocument, bool>> filter, string partitionKey = null) /// <param name="cancellationToken">An optional cancellation Token.</param>
public async virtual Task<List<TDocument>> GetAllAsync<TDocument, TKey>(Expression<Func<TDocument, bool>> filter, string partitionKey = null, CancellationToken cancellationToken = default)
where TDocument : IDocument<TKey> where TDocument : IDocument<TKey>
where TKey : IEquatable<TKey> where TKey : IEquatable<TKey>
{ {
return await HandlePartitioned<TDocument, TKey>(partitionKey).Find(filter).ToListAsync(); return await HandlePartitioned<TDocument, TKey>(partitionKey).Find(filter).ToListAsync(cancellationToken);
} }
/// <summary> /// <summary>
@@ -155,11 +167,12 @@ namespace MongoDbGenericRepository.DataAccess.Read
/// <typeparam name="TKey">The type of the primary key for a Document.</typeparam> /// <typeparam name="TKey">The type of the primary key for a Document.</typeparam>
/// <param name="filter">A LINQ expression filter.</param> /// <param name="filter">A LINQ expression filter.</param>
/// <param name="partitionKey">An optional partitionKey</param> /// <param name="partitionKey">An optional partitionKey</param>
public async virtual Task<long> CountAsync<TDocument, TKey>(Expression<Func<TDocument, bool>> filter, string partitionKey = null) /// <param name="cancellationToken">An optional cancellation Token.</param>
public async virtual Task<long> CountAsync<TDocument, TKey>(Expression<Func<TDocument, bool>> filter, string partitionKey = null, CancellationToken cancellationToken = default)
where TDocument : IDocument<TKey> where TDocument : IDocument<TKey>
where TKey : IEquatable<TKey> where TKey : IEquatable<TKey>
{ {
return await HandlePartitioned<TDocument, TKey>(partitionKey).CountDocumentsAsync(filter); return await HandlePartitioned<TDocument, TKey>(partitionKey).CountDocumentsAsync(filter, cancellationToken: cancellationToken);
} }
/// <summary> /// <summary>
@@ -188,14 +201,15 @@ namespace MongoDbGenericRepository.DataAccess.Read
/// <param name="filter">A LINQ expression filter.</param> /// <param name="filter">A LINQ expression filter.</param>
/// <param name="maxValueSelector">A property selector to order by descending.</param> /// <param name="maxValueSelector">A property selector to order by descending.</param>
/// <param name="partitionKey">An optional partitionKey.</param> /// <param name="partitionKey">An optional partitionKey.</param>
public async virtual Task<TDocument> GetByMaxAsync<TDocument, TKey>(Expression<Func<TDocument, bool>> filter, Expression<Func<TDocument, object>> maxValueSelector, string partitionKey = null) /// <param name="cancellationToken">An optional cancellation Token.</param>
public async virtual Task<TDocument> GetByMaxAsync<TDocument, TKey>(Expression<Func<TDocument, bool>> filter, Expression<Func<TDocument, object>> maxValueSelector, string partitionKey = null, CancellationToken cancellationToken = default)
where TDocument : IDocument<TKey> where TDocument : IDocument<TKey>
where TKey : IEquatable<TKey> where TKey : IEquatable<TKey>
{ {
return await GetCollection<TDocument, TKey>(partitionKey).Find(Builders<TDocument>.Filter.Where(filter)) return await GetCollection<TDocument, TKey>(partitionKey).Find(Builders<TDocument>.Filter.Where(filter))
.SortByDescending(maxValueSelector) .SortByDescending(maxValueSelector)
.Limit(1) .Limit(1)
.FirstOrDefaultAsync(); .FirstOrDefaultAsync(cancellationToken);
} }
/// <summary> /// <summary>
@@ -224,14 +238,15 @@ namespace MongoDbGenericRepository.DataAccess.Read
/// <param name="filter">A LINQ expression filter.</param> /// <param name="filter">A LINQ expression filter.</param>
/// <param name="minValueSelector">A property selector to order by ascending.</param> /// <param name="minValueSelector">A property selector to order by ascending.</param>
/// <param name="partitionKey">An optional partitionKey.</param> /// <param name="partitionKey">An optional partitionKey.</param>
public async virtual Task<TDocument> GetByMinAsync<TDocument, TKey>(Expression<Func<TDocument, bool>> filter, Expression<Func<TDocument, object>> minValueSelector, string partitionKey = null) /// <param name="cancellationToken">An optional cancellation Token.</param>
public async virtual Task<TDocument> GetByMinAsync<TDocument, TKey>(Expression<Func<TDocument, bool>> filter, Expression<Func<TDocument, object>> minValueSelector, string partitionKey = null, CancellationToken cancellationToken = default)
where TDocument : IDocument<TKey> where TDocument : IDocument<TKey>
where TKey : IEquatable<TKey> where TKey : IEquatable<TKey>
{ {
return await GetCollection<TDocument, TKey>(partitionKey).Find(Builders<TDocument>.Filter.Where(filter)) return await GetCollection<TDocument, TKey>(partitionKey).Find(Builders<TDocument>.Filter.Where(filter))
.SortBy(minValueSelector) .SortBy(minValueSelector)
.Limit(1) .Limit(1)
.FirstOrDefaultAsync(); .FirstOrDefaultAsync(cancellationToken);
} }
/// <summary> /// <summary>
@@ -257,16 +272,18 @@ namespace MongoDbGenericRepository.DataAccess.Read
/// </summary> /// </summary>
/// <typeparam name="TDocument">The document type.</typeparam> /// <typeparam name="TDocument">The document type.</typeparam>
/// <typeparam name="TKey">The type of the primary key.</typeparam> /// <typeparam name="TKey">The type of the primary key.</typeparam>
/// <typeparam name="TValue">The type of the field for which you want the maximum value.</typeparam>
/// <param name="filter">A LINQ expression filter.</param> /// <param name="filter">A LINQ expression filter.</param>
/// <param name="orderByAscending">A property selector to order by ascending.</param> /// <param name="maxValueSelector">A property selector to order by ascending.</param>
/// <param name="partitionKey">An optional partitionKey.</param> /// <param name="partitionKey">An optional partitionKey.</param>
public async virtual Task<TValue> GetMaxValueAsync<TDocument, TKey, TValue>(Expression<Func<TDocument, bool>> filter, Expression<Func<TDocument, TValue>> maxValueSelector, string partitionKey = null) /// <param name="cancellationToken">An optional cancellation Token.</param>
public async virtual Task<TValue> GetMaxValueAsync<TDocument, TKey, TValue>(Expression<Func<TDocument, bool>> filter, Expression<Func<TDocument, TValue>> maxValueSelector, string partitionKey = null, CancellationToken cancellationToken = default)
where TDocument : IDocument<TKey> where TDocument : IDocument<TKey>
where TKey : IEquatable<TKey> where TKey : IEquatable<TKey>
{ {
return await GetMaxMongoQuery<TDocument, TKey, TValue>(filter, maxValueSelector, partitionKey) return await GetMaxMongoQuery<TDocument, TKey, TValue>(filter, maxValueSelector, partitionKey)
.Project(maxValueSelector) .Project(maxValueSelector)
.FirstOrDefaultAsync(); .FirstOrDefaultAsync(cancellationToken);
} }
/// <summary> /// <summary>
@@ -296,11 +313,12 @@ namespace MongoDbGenericRepository.DataAccess.Read
/// <param name="filter">A LINQ expression filter.</param> /// <param name="filter">A LINQ expression filter.</param>
/// <param name="minValueSelector">A property selector to order by ascending.</param> /// <param name="minValueSelector">A property selector to order by ascending.</param>
/// <param name="partitionKey">An optional partition key.</param> /// <param name="partitionKey">An optional partition key.</param>
public virtual async Task<TValue> GetMinValueAsync<TDocument, TKey, TValue>(Expression<Func<TDocument, bool>> filter, Expression<Func<TDocument, TValue>> minValueSelector, string partitionKey = null) /// <param name="cancellationToken">An optional cancellation Token.</param>
public virtual async Task<TValue> GetMinValueAsync<TDocument, TKey, TValue>(Expression<Func<TDocument, bool>> filter, Expression<Func<TDocument, TValue>> minValueSelector, string partitionKey = null, CancellationToken cancellationToken = default)
where TDocument : IDocument<TKey> where TDocument : IDocument<TKey>
where TKey : IEquatable<TKey> where TKey : IEquatable<TKey>
{ {
return await GetMinMongoQuery<TDocument, TKey, TValue>(filter, minValueSelector, partitionKey).Project(minValueSelector).FirstOrDefaultAsync(); return await GetMinMongoQuery<TDocument, TKey, TValue>(filter, minValueSelector, partitionKey).Project(minValueSelector).FirstOrDefaultAsync(cancellationToken);
} }
/// <summary> /// <summary>
@@ -332,13 +350,15 @@ namespace MongoDbGenericRepository.DataAccess.Read
/// <param name="filter">A LINQ expression filter.</param> /// <param name="filter">A LINQ expression filter.</param>
/// <param name="selector">The field you want to sum.</param> /// <param name="selector">The field you want to sum.</param>
/// <param name="partitionKey">The partition key of your document, if any.</param> /// <param name="partitionKey">The partition key of your document, if any.</param>
/// <param name="cancellationToken">An optional cancellation Token.</param>
public virtual async Task<int> SumByAsync<TDocument, TKey>(Expression<Func<TDocument, bool>> filter, public virtual async Task<int> SumByAsync<TDocument, TKey>(Expression<Func<TDocument, bool>> filter,
Expression<Func<TDocument, int>> selector, Expression<Func<TDocument, int>> selector,
string partitionKey = null) string partitionKey = null,
CancellationToken cancellationToken = default)
where TDocument : IDocument<TKey> where TDocument : IDocument<TKey>
where TKey : IEquatable<TKey> where TKey : IEquatable<TKey>
{ {
return await GetQuery<TDocument, TKey>(filter, partitionKey).SumAsync(selector); return await GetQuery<TDocument, TKey>(filter, partitionKey).SumAsync(selector, cancellationToken);
} }
/// <summary> /// <summary>
@@ -366,13 +386,14 @@ namespace MongoDbGenericRepository.DataAccess.Read
/// <param name="filter">A LINQ expression filter.</param> /// <param name="filter">A LINQ expression filter.</param>
/// <param name="selector">The field you want to sum.</param> /// <param name="selector">The field you want to sum.</param>
/// <param name="partitionKey">The partition key of your document, if any.</param> /// <param name="partitionKey">The partition key of your document, if any.</param>
/// <param name="cancellationToken">An optional cancellation Token.</param>
public virtual async Task<decimal> SumByAsync<TDocument, TKey>(Expression<Func<TDocument, bool>> filter, public virtual async Task<decimal> SumByAsync<TDocument, TKey>(Expression<Func<TDocument, bool>> filter,
Expression<Func<TDocument, decimal>> selector, Expression<Func<TDocument, decimal>> selector,
string partitionKey = null) string partitionKey = null, CancellationToken cancellationToken = default)
where TDocument : IDocument<TKey> where TDocument : IDocument<TKey>
where TKey : IEquatable<TKey> where TKey : IEquatable<TKey>
{ {
return await GetQuery<TDocument, TKey>(filter, partitionKey).SumAsync(selector); return await GetQuery<TDocument, TKey>(filter, partitionKey).SumAsync(selector, cancellationToken);
} }
/// <summary> /// <summary>
@@ -451,6 +472,36 @@ namespace MongoDbGenericRepository.DataAccess.Read
.ToList(); .ToList();
} }
/// <summary>
/// Groups filtered a collection of documents given a grouping criteria,
/// and returns a dictionary of listed document groups with keys having the different values of the grouping criteria.
/// </summary>
/// <typeparam name="TDocument">The type representing a Document.</typeparam>
/// <typeparam name="TKey">The type of the primary key for a Document.</typeparam>
/// <typeparam name="TGroupKey">The type of the grouping criteria.</typeparam>
/// <typeparam name="TProjection">The type of the projected group.</typeparam>
/// <param name="filter">A LINQ expression filter.</param>
/// <param name="selector">The grouping criteria.</param>
/// <param name="projection">The projected group result.</param>
/// <param name="partitionKey">The partition key of your document, if any.</param>
/// <param name="cancellationToken">An optional cancellation Token.</param>
public virtual async Task<List<TProjection>> GroupByAsync<TDocument, TGroupKey, TProjection, TKey>(
Expression<Func<TDocument, bool>> filter,
Expression<Func<TDocument, TGroupKey>> selector,
Expression<Func<IGrouping<TGroupKey, TDocument>, TProjection>> projection,
string partitionKey = null,
CancellationToken cancellationToken = default)
where TDocument : IDocument<TKey>
where TKey : IEquatable<TKey>
where TProjection : class, new()
{
var collection = HandlePartitioned<TDocument, TKey>(partitionKey);
return await collection.Aggregate()
.Match(Builders<TDocument>.Filter.Where(filter))
.Group(selector, projection)
.ToListAsync(cancellationToken);
}
/// <summary> /// <summary>
/// Asynchronously returns a paginated list of the documents matching the filter condition. /// Asynchronously returns a paginated list of the documents matching the filter condition.
/// </summary> /// </summary>
@@ -462,13 +513,15 @@ namespace MongoDbGenericRepository.DataAccess.Read
/// <param name="skipNumber">The number of documents you want to skip. Default value is 0.</param> /// <param name="skipNumber">The number of documents you want to skip. Default value is 0.</param>
/// <param name="takeNumber">The number of documents you want to take. Default value is 50.</param> /// <param name="takeNumber">The number of documents you want to take. Default value is 50.</param>
/// <param name="partitionKey">An optional partition key.</param> /// <param name="partitionKey">An optional partition key.</param>
/// <param name="cancellationToken">An optional cancellation Token.</param>
public virtual async Task<List<TDocument>> GetSortedPaginatedAsync<TDocument, TKey>( public virtual async Task<List<TDocument>> GetSortedPaginatedAsync<TDocument, TKey>(
Expression<Func<TDocument, bool>> filter, Expression<Func<TDocument, bool>> filter,
Expression<Func<TDocument, object>> sortSelector, Expression<Func<TDocument, object>> sortSelector,
bool ascending = true, bool ascending = true,
int skipNumber = 0, int skipNumber = 0,
int takeNumber = 50, int takeNumber = 50,
string partitionKey = null) string partitionKey = null,
CancellationToken cancellationToken = default)
where TDocument : IDocument<TKey> where TDocument : IDocument<TKey>
where TKey : IEquatable<TKey> where TKey : IEquatable<TKey>
{ {
@@ -481,7 +534,7 @@ namespace MongoDbGenericRepository.DataAccess.Read
.Sort(sorting) .Sort(sorting)
.Skip(skipNumber) .Skip(skipNumber)
.Limit(takeNumber) .Limit(takeNumber)
.ToListAsync(); .ToListAsync(cancellationToken);
} }
/// <summary> /// <summary>
@@ -494,12 +547,14 @@ namespace MongoDbGenericRepository.DataAccess.Read
/// <param name="skipNumber">The number of documents you want to skip. Default value is 0.</param> /// <param name="skipNumber">The number of documents you want to skip. Default value is 0.</param>
/// <param name="takeNumber">The number of documents you want to take. Default value is 50.</param> /// <param name="takeNumber">The number of documents you want to take. Default value is 50.</param>
/// <param name="partitionKey">An optional partition key.</param> /// <param name="partitionKey">An optional partition key.</param>
/// <param name="cancellationToken">An optional cancellation Token.</param>
public virtual async Task<List<TDocument>> GetSortedPaginatedAsync<TDocument, TKey>( public virtual async Task<List<TDocument>> GetSortedPaginatedAsync<TDocument, TKey>(
Expression<Func<TDocument, bool>> filter, Expression<Func<TDocument, bool>> filter,
SortDefinition<TDocument> sortDefinition, SortDefinition<TDocument> sortDefinition,
int skipNumber = 0, int skipNumber = 0,
int takeNumber = 50, int takeNumber = 50,
string partitionKey = null) string partitionKey = null,
CancellationToken cancellationToken = default)
where TDocument : IDocument<TKey> where TDocument : IDocument<TKey>
where TKey : IEquatable<TKey> where TKey : IEquatable<TKey>
{ {
@@ -508,7 +563,7 @@ namespace MongoDbGenericRepository.DataAccess.Read
.Sort(sortDefinition) .Sort(sortDefinition)
.Skip(skipNumber) .Skip(skipNumber)
.Limit(takeNumber) .Limit(takeNumber)
.ToListAsync(); .ToListAsync(cancellationToken);
} }
} }
} }
@@ -5,6 +5,7 @@ using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Linq.Expressions; using System.Linq.Expressions;
using System.Threading;
using System.Threading.Tasks; using System.Threading.Tasks;
namespace MongoDbGenericRepository.DataAccess.Read namespace MongoDbGenericRepository.DataAccess.Read
@@ -20,14 +21,19 @@ namespace MongoDbGenericRepository.DataAccess.Read
/// <param name="filter">A LINQ expression filter.</param> /// <param name="filter">A LINQ expression filter.</param>
/// <param name="projection">The projection expression.</param> /// <param name="projection">The projection expression.</param>
/// <param name="partitionKey">An optional partition key.</param> /// <param name="partitionKey">An optional partition key.</param>
public virtual async Task<TProjection> ProjectOneAsync<TDocument, TProjection, TKey>(Expression<Func<TDocument, bool>> filter, Expression<Func<TDocument, TProjection>> projection, string partitionKey = null) /// <param name="cancellationToken">An optional cancellation Token.</param>
public virtual async Task<TProjection> ProjectOneAsync<TDocument, TProjection, TKey>(
Expression<Func<TDocument, bool>> filter,
Expression<Func<TDocument, TProjection>> projection,
string partitionKey = null,
CancellationToken cancellationToken = default)
where TDocument : IDocument<TKey> where TDocument : IDocument<TKey>
where TKey : IEquatable<TKey> where TKey : IEquatable<TKey>
where TProjection : class where TProjection : class
{ {
return await HandlePartitioned<TDocument, TKey>(partitionKey).Find(filter) return await HandlePartitioned<TDocument, TKey>(partitionKey).Find(filter)
.Project(projection) .Project(projection)
.FirstOrDefaultAsync(); .FirstOrDefaultAsync(cancellationToken);
} }
/// <summary> /// <summary>
@@ -58,14 +64,19 @@ namespace MongoDbGenericRepository.DataAccess.Read
/// <param name="filter">A LINQ expression filter.</param> /// <param name="filter">A LINQ expression filter.</param>
/// <param name="projection">The projection expression.</param> /// <param name="projection">The projection expression.</param>
/// <param name="partitionKey">An optional partition key.</param> /// <param name="partitionKey">An optional partition key.</param>
public virtual async Task<List<TProjection>> ProjectManyAsync<TDocument, TProjection, TKey>(Expression<Func<TDocument, bool>> filter, Expression<Func<TDocument, TProjection>> projection, string partitionKey = null) /// <param name="cancellationToken">An optional cancellation Token.</param>
public virtual async Task<List<TProjection>> ProjectManyAsync<TDocument, TProjection, TKey>(
Expression<Func<TDocument, bool>> filter,
Expression<Func<TDocument, TProjection>> projection,
string partitionKey = null,
CancellationToken cancellationToken = default)
where TDocument : IDocument<TKey> where TDocument : IDocument<TKey>
where TKey : IEquatable<TKey> where TKey : IEquatable<TKey>
where TProjection : class where TProjection : class
{ {
return await HandlePartitioned<TDocument, TKey>(partitionKey).Find(filter) return await HandlePartitioned<TDocument, TKey>(partitionKey).Find(filter)
.Project(projection) .Project(projection)
.ToListAsync(); .ToListAsync(cancellationToken);
} }
/// <summary> /// <summary>
@@ -2,6 +2,7 @@
using MongoDbGenericRepository.Models; using MongoDbGenericRepository.Models;
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Threading;
using System.Threading.Tasks; using System.Threading.Tasks;
namespace MongoDbGenericRepository namespace MongoDbGenericRepository
@@ -18,7 +19,8 @@ namespace MongoDbGenericRepository
/// </summary> /// </summary>
/// <typeparam name="TDocument">The type representing a Document.</typeparam> /// <typeparam name="TDocument">The type representing a Document.</typeparam>
/// <param name="document">The document you want to add.</param> /// <param name="document">The document you want to add.</param>
Task AddOneAsync<TDocument>(TDocument document) where TDocument : IDocument<TKey>; /// <param name="cancellationToken">An optional cancellation Token.</param>
Task AddOneAsync<TDocument>(TDocument document, CancellationToken cancellationToken = default) where TDocument : IDocument<TKey>;
/// <summary> /// <summary>
/// Adds a document to the collection. /// Adds a document to the collection.
@@ -34,7 +36,8 @@ namespace MongoDbGenericRepository
/// </summary> /// </summary>
/// <typeparam name="TDocument">The type representing a Document.</typeparam> /// <typeparam name="TDocument">The type representing a Document.</typeparam>
/// <param name="documents">The documents you want to add.</param> /// <param name="documents">The documents you want to add.</param>
Task AddManyAsync<TDocument>(IEnumerable<TDocument> documents) where TDocument : IDocument<TKey>; /// <param name="cancellationToken">An optional cancellation Token.</param>
Task AddManyAsync<TDocument>(IEnumerable<TDocument> documents, CancellationToken cancellationToken = default) where TDocument : IDocument<TKey>;
/// <summary> /// <summary>
/// Adds a list of documents to the collection. /// Adds a list of documents to the collection.
@@ -81,9 +84,10 @@ namespace MongoDbGenericRepository
/// </summary> /// </summary>
/// <typeparam name="TDocument">The type representing a Document.</typeparam> /// <typeparam name="TDocument">The type representing a Document.</typeparam>
/// <param name="document">The document you want to add.</param> /// <param name="document">The document you want to add.</param>
public virtual async Task AddOneAsync<TDocument>(TDocument document) where TDocument : IDocument<TKey> /// <param name="cancellationToken">An optional cancellation Token.</param>
public virtual async Task AddOneAsync<TDocument>(TDocument document, CancellationToken cancellationToken = default) where TDocument : IDocument<TKey>
{ {
await MongoDbCreator.AddOneAsync<TDocument, TKey>(document); await MongoDbCreator.AddOneAsync<TDocument, TKey>(document, cancellationToken);
} }
/// <summary> /// <summary>
@@ -103,9 +107,10 @@ namespace MongoDbGenericRepository
/// </summary> /// </summary>
/// <typeparam name="TDocument">The type representing a Document.</typeparam> /// <typeparam name="TDocument">The type representing a Document.</typeparam>
/// <param name="documents">The documents you want to add.</param> /// <param name="documents">The documents you want to add.</param>
public virtual async Task AddManyAsync<TDocument>(IEnumerable<TDocument> documents) where TDocument : IDocument<TKey> /// <param name="cancellationToken">An optional cancellation Token.</param>
public virtual async Task AddManyAsync<TDocument>(IEnumerable<TDocument> documents, CancellationToken cancellationToken = default) where TDocument : IDocument<TKey>
{ {
await MongoDbCreator.AddManyAsync<TDocument, TKey>(documents); await MongoDbCreator.AddManyAsync<TDocument, TKey>(documents, cancellationToken);
} }
/// <summary> /// <summary>
@@ -52,10 +52,6 @@ namespace MongoDbGenericRepository.Models
/// </summary> /// </summary>
public string DefaultLanguage { get; set; } public string DefaultLanguage { get; set; }
/// <summary> /// <summary>
/// Gets or sets the size of a geohash bucket.
/// </summary>
public double? BucketSize { get; set; }
/// <summary>
/// Gets or sets the precision, in bits, used with geohash indexes. /// Gets or sets the precision, in bits, used with geohash indexes.
/// </summary> /// </summary>
public int? Bits { get; set; } public int? Bits { get; set; }
@@ -2,8 +2,9 @@
<PropertyGroup> <PropertyGroup>
<TargetFrameworks>net452;netstandard2.0;netstandard1.5;</TargetFrameworks> <TargetFrameworks>net452;netstandard2.0;netstandard1.5;</TargetFrameworks>
<GenerateDocumentationFile>true</GenerateDocumentationFile>
<PackageId>MongoDbGenericRepository</PackageId> <PackageId>MongoDbGenericRepository</PackageId>
<PackageVersion>1.4.5</PackageVersion> <PackageVersion>1.4.8</PackageVersion>
<Authors>Alexandre Spieser</Authors> <Authors>Alexandre Spieser</Authors>
<PackageTitle>MongoDb Generic Repository</PackageTitle> <PackageTitle>MongoDb Generic Repository</PackageTitle>
<Description>A generic repository implementation using the MongoDB C# Sharp 2.0 driver.</Description> <Description>A generic repository implementation using the MongoDB C# Sharp 2.0 driver.</Description>
@@ -11,28 +12,20 @@
<PackageProjectUrl>http://www.opensource.org/licenses/mit-license.php</PackageProjectUrl> <PackageProjectUrl>http://www.opensource.org/licenses/mit-license.php</PackageProjectUrl>
<PackageRequireLicenseAcceptance>false</PackageRequireLicenseAcceptance> <PackageRequireLicenseAcceptance>false</PackageRequireLicenseAcceptance>
<PackageReleaseNotes>Release notes are at https://github.com/alexandre-spieser/mongodb-generic-repository/releases </PackageReleaseNotes> <PackageReleaseNotes>Release notes are at https://github.com/alexandre-spieser/mongodb-generic-repository/releases </PackageReleaseNotes>
<Copyright>Copyright 2020 (c) Alexandre Spieser. All rights reserved.</Copyright> <Copyright>Copyright 2021 (c) Alexandre Spieser. All rights reserved.</Copyright>
<PackageTags>MongoDb Repository Generic NoSql</PackageTags> <PackageTags>MongoDb Repository Generic NoSql</PackageTags>
<GeneratePackageOnBuild>true</GeneratePackageOnBuild> <GeneratePackageOnBuild>true</GeneratePackageOnBuild>
<Version>1.4.5</Version> <Version>1.4.8</Version>
<RepositoryUrl>https://github.com/alexandre-spieser/mongodb-generic-repository</RepositoryUrl> <RepositoryUrl>https://github.com/alexandre-spieser/mongodb-generic-repository</RepositoryUrl>
<RepositoryType>Git</RepositoryType> <RepositoryType>Git</RepositoryType>
</PropertyGroup> </PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(TargetFramework)|$(Platform)'=='Release|net45|AnyCPU'"> <PropertyGroup>
<DocumentationFile>bin\Release\net45\MongoDbGenericRepository.xml</DocumentationFile> <DocumentationFile>bin\$(Configuration)\$(TargetFramework)\$(AssemblyName).xml</DocumentationFile>
</PropertyGroup> </PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(TargetFramework)|$(Platform)'=='Debug|net452|AnyCPU'">
<DocumentationFile></DocumentationFile>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(TargetFramework)|$(Platform)'=='Release|net452|AnyCPU'">
<DocumentationFile>D:\development\mongodb-generic-repository\MongoDbGenericRepository\MongoDbGenericRepository.xml</DocumentationFile>
</PropertyGroup>
<ItemGroup> <ItemGroup>
<PackageReference Include="MongoDB.Driver" Version="2.9.3" /> <PackageReference Include="MongoDB.Driver" Version="2.13.2" />
</ItemGroup> </ItemGroup>
</Project> </Project>
@@ -1,31 +0,0 @@
<?xml version="1.0"?>
<package >
<metadata>
<id>MongoDbGenericRepository</id>
<version>1.4.5</version>
<title>MongoDb Generic Repository</title>
<authors>Alexandre Spieser</authors>
<owners>Alexandre Spieser</owners>
<licenseUrl>http://www.opensource.org/licenses/mit-license.php</licenseUrl>
<projectUrl>https://github.com/alexandre-spieser/mongodb-generic-repository</projectUrl>
<requireLicenseAcceptance>false</requireLicenseAcceptance>
<description>A generic repository implementation using the MongoDB C# Sharp 2.0 driver.</description>
<releaseNotes>Release notes are at https://github.com/alexandre-spieser/mongodb-generic-repository/releases</releaseNotes>
<copyright>Copyright 2020 (c) Alexandre Spieser. All rights reserved.</copyright>
<tags>MongoDb Repository Generic NoSql</tags>
<dependencies>
<group targetFramework=".NETFramework4.5.2">
<dependency id="MongoDB.Driver" version="2.9.3" exclude="Build,Analyzers" />
</group>
<group targetFramework=".NETStandard1.5">
<dependency id="MongoDB.Driver" version="2.9.3" exclude="Build,Analyzers" />
</group>
<group targetFramework=".NETStandard2.0">
<dependency id="MongoDB.Driver" version="2.9.3" exclude="Build,Analyzers"/>
</group>
</dependencies>
</metadata>
<files>
<file src="lib\**" target="lib" />
</files>
</package>
@@ -5,6 +5,7 @@ using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Linq.Expressions; using System.Linq.Expressions;
using System.Threading;
using System.Threading.Tasks; using System.Threading.Tasks;
namespace MongoDbGenericRepository namespace MongoDbGenericRepository
@@ -49,11 +50,12 @@ namespace MongoDbGenericRepository
/// <typeparam name="TKey">The type of the primary key for a Document.</typeparam> /// <typeparam name="TKey">The type of the primary key for a Document.</typeparam>
/// <param name="id">The Id of the document you want to get.</param> /// <param name="id">The Id of the document you want to get.</param>
/// <param name="partitionKey">An optional partition key.</param> /// <param name="partitionKey">An optional partition key.</param>
public async virtual Task<TDocument> GetByIdAsync<TDocument, TKey>(TKey id, string partitionKey = null) /// <param name="cancellationToken">An optional cancellation Token.</param>
public async virtual Task<TDocument> GetByIdAsync<TDocument, TKey>(TKey id, string partitionKey = null, CancellationToken cancellationToken = default)
where TDocument : IDocument<TKey> where TDocument : IDocument<TKey>
where TKey : IEquatable<TKey> where TKey : IEquatable<TKey>
{ {
return await MongoDbReader.GetByIdAsync<TDocument, TKey>(id, partitionKey); return await MongoDbReader.GetByIdAsync<TDocument, TKey>(id, partitionKey, cancellationToken);
} }
/// <summary> /// <summary>
@@ -77,11 +79,12 @@ namespace MongoDbGenericRepository
/// <typeparam name="TKey">The type of the primary key for a Document.</typeparam> /// <typeparam name="TKey">The type of the primary key for a Document.</typeparam>
/// <param name="filter">A LINQ expression filter.</param> /// <param name="filter">A LINQ expression filter.</param>
/// <param name="partitionKey">An optional partition key.</param> /// <param name="partitionKey">An optional partition key.</param>
public async virtual Task<TDocument> GetOneAsync<TDocument, TKey>(Expression<Func<TDocument, bool>> filter, string partitionKey = null) /// <param name="cancellationToken">An optional cancellation Token.</param>
public async virtual Task<TDocument> GetOneAsync<TDocument, TKey>(Expression<Func<TDocument, bool>> filter, string partitionKey = null, CancellationToken cancellationToken = default)
where TDocument : IDocument<TKey> where TDocument : IDocument<TKey>
where TKey : IEquatable<TKey> where TKey : IEquatable<TKey>
{ {
return await MongoDbReader.GetOneAsync<TDocument, TKey>(filter, partitionKey); return await MongoDbReader.GetOneAsync<TDocument, TKey>(filter, partitionKey, cancellationToken);
} }
/// <summary> /// <summary>
@@ -119,11 +122,12 @@ namespace MongoDbGenericRepository
/// <typeparam name="TKey">The type of the primary key for a Document.</typeparam> /// <typeparam name="TKey">The type of the primary key for a Document.</typeparam>
/// <param name="filter">A LINQ expression filter.</param> /// <param name="filter">A LINQ expression filter.</param>
/// <param name="partitionKey">An optional partition key.</param> /// <param name="partitionKey">An optional partition key.</param>
public async virtual Task<bool> AnyAsync<TDocument, TKey>(Expression<Func<TDocument, bool>> filter, string partitionKey = null) /// <param name="cancellationToken">An optional cancellation Token.</param>
public async virtual Task<bool> AnyAsync<TDocument, TKey>(Expression<Func<TDocument, bool>> filter, string partitionKey = null, CancellationToken cancellationToken = default)
where TDocument : IDocument<TKey> where TDocument : IDocument<TKey>
where TKey : IEquatable<TKey> where TKey : IEquatable<TKey>
{ {
return await MongoDbReader.AnyAsync<TDocument, TKey>(filter, partitionKey); return await MongoDbReader.AnyAsync<TDocument, TKey>(filter, partitionKey, cancellationToken);
} }
/// <summary> /// <summary>
@@ -147,11 +151,12 @@ namespace MongoDbGenericRepository
/// <typeparam name="TKey">The type of the primary key for a Document.</typeparam> /// <typeparam name="TKey">The type of the primary key for a Document.</typeparam>
/// <param name="filter">A LINQ expression filter.</param> /// <param name="filter">A LINQ expression filter.</param>
/// <param name="partitionKey">An optional partition key.</param> /// <param name="partitionKey">An optional partition key.</param>
public async virtual Task<List<TDocument>> GetAllAsync<TDocument, TKey>(Expression<Func<TDocument, bool>> filter, string partitionKey = null) /// <param name="cancellationToken">An optional cancellation Token.</param>
public async virtual Task<List<TDocument>> GetAllAsync<TDocument, TKey>(Expression<Func<TDocument, bool>> filter, string partitionKey = null, CancellationToken cancellationToken = default)
where TDocument : IDocument<TKey> where TDocument : IDocument<TKey>
where TKey : IEquatable<TKey> where TKey : IEquatable<TKey>
{ {
return await MongoDbReader.GetAllAsync<TDocument, TKey>(filter, partitionKey); return await MongoDbReader.GetAllAsync<TDocument, TKey>(filter, partitionKey, cancellationToken);
} }
/// <summary> /// <summary>
@@ -175,11 +180,12 @@ namespace MongoDbGenericRepository
/// <typeparam name="TKey">The type of the primary key for a Document.</typeparam> /// <typeparam name="TKey">The type of the primary key for a Document.</typeparam>
/// <param name="filter">A LINQ expression filter.</param> /// <param name="filter">A LINQ expression filter.</param>
/// <param name="partitionKey">An optional partitionKey</param> /// <param name="partitionKey">An optional partitionKey</param>
public async virtual Task<long> CountAsync<TDocument, TKey>(Expression<Func<TDocument, bool>> filter, string partitionKey = null) /// <param name="cancellationToken">An optional cancellation Token.</param>
public async virtual Task<long> CountAsync<TDocument, TKey>(Expression<Func<TDocument, bool>> filter, string partitionKey = null, CancellationToken cancellationToken = default)
where TDocument : IDocument<TKey> where TDocument : IDocument<TKey>
where TKey : IEquatable<TKey> where TKey : IEquatable<TKey>
{ {
return await MongoDbReader.CountAsync<TDocument, TKey>(filter, partitionKey); return await MongoDbReader.CountAsync<TDocument, TKey>(filter, partitionKey, cancellationToken);
} }
/// <summary> /// <summary>
@@ -204,11 +210,15 @@ namespace MongoDbGenericRepository
/// <param name="filter">A LINQ expression filter.</param> /// <param name="filter">A LINQ expression filter.</param>
/// <param name="maxValueSelector">A property selector to order by descending.</param> /// <param name="maxValueSelector">A property selector to order by descending.</param>
/// <param name="partitionKey">An optional partitionKey.</param> /// <param name="partitionKey">An optional partitionKey.</param>
public async virtual Task<TDocument> GetByMaxAsync<TDocument, TKey>(Expression<Func<TDocument, bool>> filter, Expression<Func<TDocument, object>> maxValueSelector, string partitionKey = null) /// <param name="cancellationToken">An optional cancellation Token.</param>
public async virtual Task<TDocument> GetByMaxAsync<TDocument, TKey>(
Expression<Func<TDocument, bool>> filter,
Expression<Func<TDocument, object>> maxValueSelector,
string partitionKey = null, CancellationToken cancellationToken = default)
where TDocument : IDocument<TKey> where TDocument : IDocument<TKey>
where TKey : IEquatable<TKey> where TKey : IEquatable<TKey>
{ {
return await MongoDbReader.GetByMaxAsync<TDocument, TKey>(filter, maxValueSelector, partitionKey); return await MongoDbReader.GetByMaxAsync<TDocument, TKey>(filter, maxValueSelector, partitionKey, cancellationToken);
} }
/// <summary> /// <summary>
@@ -232,13 +242,17 @@ namespace MongoDbGenericRepository
/// <typeparam name="TDocument">The document type.</typeparam> /// <typeparam name="TDocument">The document type.</typeparam>
/// <typeparam name="TKey">The type of the primary key.</typeparam> /// <typeparam name="TKey">The type of the primary key.</typeparam>
/// <param name="filter">A LINQ expression filter.</param> /// <param name="filter">A LINQ expression filter.</param>
/// <param name="minValueSelector">A property selector to order by ascending.</param> /// <param name="minValueSelector">A property selector for the minimum value you are looking for.</param>
/// <param name="partitionKey">An optional partitionKey.</param> /// <param name="partitionKey">An optional partitionKey.</param>
public async virtual Task<TDocument> GetByMinAsync<TDocument, TKey>(Expression<Func<TDocument, bool>> filter, Expression<Func<TDocument, object>> minValueSelector, string partitionKey = null) /// <param name="cancellationToken">An optional cancellation Token.</param>
public async virtual Task<TDocument> GetByMinAsync<TDocument, TKey>(Expression<Func<TDocument, bool>> filter,
Expression<Func<TDocument, object>> minValueSelector,
string partitionKey = null,
CancellationToken cancellationToken = default)
where TDocument : IDocument<TKey> where TDocument : IDocument<TKey>
where TKey : IEquatable<TKey> where TKey : IEquatable<TKey>
{ {
return await MongoDbReader.GetByMinAsync<TDocument, TKey>(filter, minValueSelector, partitionKey); return await MongoDbReader.GetByMinAsync<TDocument, TKey>(filter, minValueSelector, partitionKey, cancellationToken);
} }
/// <summary> /// <summary>
@@ -247,7 +261,7 @@ namespace MongoDbGenericRepository
/// <typeparam name="TDocument">The document type.</typeparam> /// <typeparam name="TDocument">The document type.</typeparam>
/// <typeparam name="TKey">The type of the primary key.</typeparam> /// <typeparam name="TKey">The type of the primary key.</typeparam>
/// <param name="filter">A LINQ expression filter.</param> /// <param name="filter">A LINQ expression filter.</param>
/// <param name="minValueSelector">A property selector to order by ascending.</param> /// <param name="minValueSelector">A property selector for the minimum value you are looking for.</param>
/// <param name="partitionKey">An optional partitionKey.</param> /// <param name="partitionKey">An optional partitionKey.</param>
public virtual TDocument GetByMin<TDocument, TKey>(Expression<Func<TDocument, bool>> filter, Expression<Func<TDocument, object>> minValueSelector, string partitionKey = null) public virtual TDocument GetByMin<TDocument, TKey>(Expression<Func<TDocument, bool>> filter, Expression<Func<TDocument, object>> minValueSelector, string partitionKey = null)
where TDocument : IDocument<TKey> where TDocument : IDocument<TKey>
@@ -263,13 +277,18 @@ namespace MongoDbGenericRepository
/// <typeparam name="TKey">The type of the primary key.</typeparam> /// <typeparam name="TKey">The type of the primary key.</typeparam>
/// <typeparam name="TValue">The type of the value used to order the query.</typeparam> /// <typeparam name="TValue">The type of the value used to order the query.</typeparam>
/// <param name="filter">A LINQ expression filter.</param> /// <param name="filter">A LINQ expression filter.</param>
/// <param name="maxValueSelector">A property selector to select the max value.</param> /// <param name="maxValueSelector">A property selector for the maximum value you are looking for.</param>
/// <param name="partitionKey">An optional partitionKey.</param> /// <param name="partitionKey">An optional partitionKey.</param>
public async virtual Task<TValue> GetMaxValueAsync<TDocument, TKey, TValue>(Expression<Func<TDocument, bool>> filter, Expression<Func<TDocument, TValue>> maxValueSelector, string partitionKey = null) /// <param name="cancellationToken">An optional cancellation Token.</param>
public async virtual Task<TValue> GetMaxValueAsync<TDocument, TKey, TValue>(
Expression<Func<TDocument, bool>> filter,
Expression<Func<TDocument, TValue>> maxValueSelector,
string partitionKey = null,
CancellationToken cancellationToken = default)
where TDocument : IDocument<TKey> where TDocument : IDocument<TKey>
where TKey : IEquatable<TKey> where TKey : IEquatable<TKey>
{ {
return await MongoDbReader.GetMaxValueAsync<TDocument, TKey, TValue>(filter, maxValueSelector, partitionKey); return await MongoDbReader.GetMaxValueAsync<TDocument, TKey, TValue>(filter, maxValueSelector, partitionKey, cancellationToken);
} }
/// <summary> /// <summary>
@@ -297,11 +316,16 @@ namespace MongoDbGenericRepository
/// <param name="filter">A LINQ expression filter.</param> /// <param name="filter">A LINQ expression filter.</param>
/// <param name="minValueSelector">A property selector to order by ascending.</param> /// <param name="minValueSelector">A property selector to order by ascending.</param>
/// <param name="partitionKey">An optional partition key.</param> /// <param name="partitionKey">An optional partition key.</param>
public virtual async Task<TValue> GetMinValueAsync<TDocument, TKey, TValue>(Expression<Func<TDocument, bool>> filter, Expression<Func<TDocument, TValue>> minValueSelector, string partitionKey = null) /// <param name="cancellationToken">An optional cancellation Token.</param>
public virtual async Task<TValue> GetMinValueAsync<TDocument, TKey, TValue>(
Expression<Func<TDocument, bool>> filter,
Expression<Func<TDocument, TValue>> minValueSelector,
string partitionKey = null,
CancellationToken cancellationToken = default)
where TDocument : IDocument<TKey> where TDocument : IDocument<TKey>
where TKey : IEquatable<TKey> where TKey : IEquatable<TKey>
{ {
return await MongoDbReader.GetMinValueAsync<TDocument, TKey, TValue>(filter, minValueSelector, partitionKey); return await MongoDbReader.GetMinValueAsync<TDocument, TKey, TValue>(filter, minValueSelector, partitionKey, cancellationToken);
} }
/// <summary> /// <summary>
@@ -332,13 +356,15 @@ namespace MongoDbGenericRepository
/// <param name="filter">A LINQ expression filter.</param> /// <param name="filter">A LINQ expression filter.</param>
/// <param name="selector">The field you want to sum.</param> /// <param name="selector">The field you want to sum.</param>
/// <param name="partitionKey">The partition key of your document, if any.</param> /// <param name="partitionKey">The partition key of your document, if any.</param>
/// <param name="cancellationToken">An optional cancellation Token.</param>
public virtual async Task<int> SumByAsync<TDocument, TKey>(Expression<Func<TDocument, bool>> filter, public virtual async Task<int> SumByAsync<TDocument, TKey>(Expression<Func<TDocument, bool>> filter,
Expression<Func<TDocument, int>> selector, Expression<Func<TDocument, int>> selector,
string partitionKey = null) string partitionKey = null,
CancellationToken cancellationToken = default)
where TDocument : IDocument<TKey> where TDocument : IDocument<TKey>
where TKey : IEquatable<TKey> where TKey : IEquatable<TKey>
{ {
return await MongoDbReader.SumByAsync<TDocument, TKey>(filter, selector, partitionKey); return await MongoDbReader.SumByAsync<TDocument, TKey>(filter, selector, partitionKey, cancellationToken);
} }
/// <summary> /// <summary>
@@ -405,12 +431,17 @@ namespace MongoDbGenericRepository
/// <param name="filter">A LINQ expression filter.</param> /// <param name="filter">A LINQ expression filter.</param>
/// <param name="projection">The projection expression.</param> /// <param name="projection">The projection expression.</param>
/// <param name="partitionKey">An optional partition key.</param> /// <param name="partitionKey">An optional partition key.</param>
public virtual async Task<TProjection> ProjectOneAsync<TDocument, TProjection, TKey>(Expression<Func<TDocument, bool>> filter, Expression<Func<TDocument, TProjection>> projection, string partitionKey = null) /// <param name="cancellationToken">An optional cancellation Token.</param>
public virtual async Task<TProjection> ProjectOneAsync<TDocument, TProjection, TKey>(
Expression<Func<TDocument, bool>> filter,
Expression<Func<TDocument, TProjection>> projection,
string partitionKey = null,
CancellationToken cancellationToken = default)
where TDocument : IDocument<TKey> where TDocument : IDocument<TKey>
where TKey : IEquatable<TKey> where TKey : IEquatable<TKey>
where TProjection : class where TProjection : class
{ {
return await MongoDbReader.ProjectOneAsync<TDocument, TProjection, TKey>(filter, projection, partitionKey); return await MongoDbReader.ProjectOneAsync<TDocument, TProjection, TKey>(filter, projection, partitionKey, cancellationToken);
} }
/// <summary> /// <summary>
@@ -439,12 +470,16 @@ namespace MongoDbGenericRepository
/// <param name="filter">A LINQ expression filter.</param> /// <param name="filter">A LINQ expression filter.</param>
/// <param name="projection">The projection expression.</param> /// <param name="projection">The projection expression.</param>
/// <param name="partitionKey">An optional partition key.</param> /// <param name="partitionKey">An optional partition key.</param>
public virtual async Task<List<TProjection>> ProjectManyAsync<TDocument, TProjection, TKey>(Expression<Func<TDocument, bool>> filter, Expression<Func<TDocument, TProjection>> projection, string partitionKey = null) /// <param name="cancellationToken">An optional cancellation Token.</param>
public virtual async Task<List<TProjection>> ProjectManyAsync<TDocument, TProjection, TKey>(
Expression<Func<TDocument, bool>> filter,
Expression<Func<TDocument, TProjection>> projection,
string partitionKey = null, CancellationToken cancellationToken = default)
where TDocument : IDocument<TKey> where TDocument : IDocument<TKey>
where TKey : IEquatable<TKey> where TKey : IEquatable<TKey>
where TProjection : class where TProjection : class
{ {
return await MongoDbReader.ProjectManyAsync<TDocument, TProjection, TKey>(filter, projection, partitionKey); return await MongoDbReader.ProjectManyAsync<TDocument, TProjection, TKey>(filter, projection, partitionKey, cancellationToken);
} }
/// <summary> /// <summary>
@@ -562,12 +597,14 @@ namespace MongoDbGenericRepository
/// <param name="skipNumber">The number of documents you want to skip. Default value is 0.</param> /// <param name="skipNumber">The number of documents you want to skip. Default value is 0.</param>
/// <param name="takeNumber">The number of documents you want to take. Default value is 50.</param> /// <param name="takeNumber">The number of documents you want to take. Default value is 50.</param>
/// <param name="partitionKey">An optional partition key.</param> /// <param name="partitionKey">An optional partition key.</param>
/// <param name="cancellationToken">An optional cancellation Token.</param>
public virtual async Task<List<TDocument>> GetSortedPaginatedAsync<TDocument, TKey>( public virtual async Task<List<TDocument>> GetSortedPaginatedAsync<TDocument, TKey>(
Expression<Func<TDocument, bool>> filter, Expression<Func<TDocument, bool>> filter,
SortDefinition<TDocument> sortDefinition, SortDefinition<TDocument> sortDefinition,
int skipNumber = 0, int skipNumber = 0,
int takeNumber = 50, int takeNumber = 50,
string partitionKey = null) string partitionKey = null,
CancellationToken cancellationToken = default)
where TDocument : IDocument<TKey> where TDocument : IDocument<TKey>
where TKey : IEquatable<TKey> where TKey : IEquatable<TKey>
{ {
@@ -576,7 +613,7 @@ namespace MongoDbGenericRepository
.Sort(sortDefinition) .Sort(sortDefinition)
.Skip(skipNumber) .Skip(skipNumber)
.Limit(takeNumber) .Limit(takeNumber)
.ToListAsync(); .ToListAsync(cancellationToken);
} }
#endregion Pagination #endregion Pagination
File diff suppressed because it is too large Load Diff
+1 -1
View File
@@ -11,7 +11,7 @@ The MongoDbGenericRepository is also used in [AspNetCore.Identity.MongoDbCore](h
# Support This Project # Support This Project
If you have found this project helpful, either as a library that you use or as a learning tool, please consider buying the team a coffee: <a href="https://www.buymeacoffee.com/zeitquest" target="_blank"><img height="40px" src="https://cdn.buymeacoffee.com/buttons/default-orange.png" alt="Buy Me A Coffee" style="max-height: 51px;width: 150px !important;" ></a> If you have found this project helpful, either as a library that you use or as a learning tool, please consider buying Alex a coffee: <a href="https://www.buymeacoffee.com/zeitquest" target="_blank"><img height="40px" src="https://cdn.buymeacoffee.com/buttons/default-orange.png" alt="Buy Me A Coffee" style="max-height: 51px;width: 150px !important;" ></a>
# Worth Knowing # Worth Knowing