Compare commits
6 Commits
1.4.4
...
alex/UpdateMany
| Author | SHA1 | Date | |
|---|---|---|---|
| eebdc89575 | |||
| ee4950c5d4 | |||
| 658c753989 | |||
| 0e8d629a8f | |||
| ba3f876f95 | |||
| e4a36e5c60 |
@@ -7,8 +7,7 @@
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Microsoft.AspNetCore.Identity" Version="2.1.2" />
|
||||
<PackageReference Include="Microsoft.Extensions.Identity.Stores" Version="2.1.2" />
|
||||
<PackageReference Include="MongoDB.Driver" Version="2.9.3" />
|
||||
<PackageReference Include="MongoDbGenericRepository" Version="1.4.4" />
|
||||
<PackageReference Include="MongoDB.Driver" Version="2.12.0" />
|
||||
<PackageReference Include="xunit" Version="2.4.1" />
|
||||
<PackageReference Include="xunit.runner.console" Version="2.4.1">
|
||||
<PrivateAssets>all</PrivateAssets>
|
||||
@@ -18,6 +17,10 @@
|
||||
<DotNetCliToolReference Include="dotnet-xunit" Version="2.3.0-beta4-build3742" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\MongoDbGenericRepository\MongoDbGenericRepository.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<Reference Include="System.Configuration">
|
||||
<HintPath>..\..\..\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.6.1\System.Configuration.dll</HintPath>
|
||||
|
||||
@@ -49,8 +49,8 @@
|
||||
<Reference Include="MongoDB.Driver.Core, Version=2.9.3.0, Culture=neutral, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\MongoDB.Driver.Core.2.9.3\lib\net452\MongoDB.Driver.Core.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="MongoDbGenericRepository, Version=1.4.4.0, Culture=neutral, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\MongoDbGenericRepository.1.4.4\lib\net452\MongoDbGenericRepository.dll</HintPath>
|
||||
<Reference Include="MongoDbGenericRepository, Version=1.4.5.0, Culture=neutral, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\MongoDbGenericRepository.1.4.5\lib\net452\MongoDbGenericRepository.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="nunit.framework, Version=3.12.0.0, Culture=neutral, PublicKeyToken=2638cd05610744eb, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\NUnit.3.12.0\lib\net45\nunit.framework.dll</HintPath>
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
<package id="MongoDB.Bson" version="2.9.3" targetFramework="net461" />
|
||||
<package id="MongoDB.Driver" version="2.9.3" targetFramework="net461" />
|
||||
<package id="MongoDB.Driver.Core" version="2.9.3" targetFramework="net461" />
|
||||
<package id="MongoDbGenericRepository" version="1.4.4" targetFramework="net461" />
|
||||
<package id="MongoDbGenericRepository" version="1.4.5" targetFramework="net461" />
|
||||
<package id="NUnit" version="3.12.0" targetFramework="net461" />
|
||||
<package id="NUnit.ConsoleRunner" version="3.10.0" targetFramework="net461" />
|
||||
<package id="NUnit3TestAdapter" version="3.15.1" targetFramework="net461" />
|
||||
|
||||
@@ -6,6 +6,9 @@ using System.Threading.Tasks;
|
||||
|
||||
namespace MongoDbGenericRepository
|
||||
{
|
||||
/// <summary>
|
||||
/// The IBaseMongoRepository_Update interface exposing update functionality for documents with Guid Ids.
|
||||
/// </summary>
|
||||
public interface IBaseMongoRepository_Update : IBaseMongoRepository_Update<Guid>
|
||||
{
|
||||
/// <summary>
|
||||
|
||||
+53
-50
@@ -7,6 +7,9 @@ using MongoDbGenericRepository.Models;
|
||||
|
||||
namespace MongoDbGenericRepository.DataAccess.Update
|
||||
{
|
||||
/// <summary>
|
||||
/// The IBaseMongoRepository_Update_ClientSession interface exposing update functionality with a IClientSessionHandle.
|
||||
/// </summary>
|
||||
public interface IBaseMongoRepository_Update_ClientSession
|
||||
{
|
||||
/// <summary>
|
||||
@@ -14,10 +17,14 @@ namespace MongoDbGenericRepository.DataAccess.Update
|
||||
/// </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="TField">The type of the field to update.</typeparam>
|
||||
/// <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>
|
||||
/// <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))
|
||||
where TDocument : IDocument<TKey>
|
||||
where TKey : IEquatable<TKey>;
|
||||
@@ -27,42 +34,18 @@ namespace MongoDbGenericRepository.DataAccess.Update
|
||||
/// </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="TField">The type of the field to update.</typeparam>
|
||||
/// <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>
|
||||
/// <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))
|
||||
where TDocument : IDocument<TKey>
|
||||
where TKey : IEquatable<TKey>;
|
||||
|
||||
/// <summary>
|
||||
/// Updates a document.
|
||||
/// </summary>
|
||||
/// <typeparam name="TDocument">The type representing 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="documentToModify">The document to modify.</param>
|
||||
/// <param name="update">The update definition.</param>
|
||||
/// <param name="cancellationToken">The optional cancellation token.</param>
|
||||
/// <returns></returns>
|
||||
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 TKey : IEquatable<TKey>;
|
||||
|
||||
/// <summary>
|
||||
/// Updates a document.
|
||||
/// </summary>
|
||||
/// <typeparam name="TDocument">The type representing 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="documentToModify">The document to modify.</param>
|
||||
/// <param name="update">The update definition.</param>
|
||||
/// <param name="cancellationToken">The optional cancellation token.</param>
|
||||
/// <returns></returns>
|
||||
bool UpdateOne<TDocument, TKey>(IClientSessionHandle session, TDocument modifiedDocument, CancellationToken cancellationToken = default(CancellationToken))
|
||||
where TDocument : IDocument<TKey>
|
||||
where TKey : IEquatable<TKey>;
|
||||
|
||||
/// <summary>
|
||||
/// Updates a document.
|
||||
/// </summary>
|
||||
@@ -74,7 +57,34 @@ namespace MongoDbGenericRepository.DataAccess.Update
|
||||
/// <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>
|
||||
/// <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))
|
||||
where TDocument : IDocument<TKey>
|
||||
where TKey : IEquatable<TKey>;
|
||||
|
||||
/// <summary>
|
||||
/// Updates a document.
|
||||
/// </summary>
|
||||
/// <typeparam name="TDocument">The type representing 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="modifiedDocument">The document with the modifications you want to persist.</param>
|
||||
/// <param name="cancellationToken">The optional cancellation token.</param>
|
||||
/// <returns>A boolean value indicating success.</returns>
|
||||
bool UpdateOne<TDocument, TKey>(IClientSessionHandle session, TDocument modifiedDocument, CancellationToken cancellationToken = default(CancellationToken))
|
||||
where TDocument : IDocument<TKey>
|
||||
where TKey : IEquatable<TKey>;
|
||||
|
||||
/// <summary>
|
||||
/// Updates a document.
|
||||
/// </summary>
|
||||
/// <typeparam name="TDocument">The type representing 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="documentToModify">The document to modify.</param>
|
||||
/// <param name="update">The update definition.</param>
|
||||
/// <param name="cancellationToken">The optional cancellation token.</param>
|
||||
/// <returns>A boolean value indicating success.</returns>
|
||||
bool UpdateOne<TDocument, TKey>(IClientSessionHandle session, TDocument documentToModify, UpdateDefinition<TDocument> update, CancellationToken cancellationToken = default(CancellationToken))
|
||||
where TDocument : IDocument<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="TField">The type of the field to update.</typeparam>
|
||||
/// <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="value">The value of the field.</param>
|
||||
/// <param name="partitionKey">The optional partition key.</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))
|
||||
where TDocument : IDocument<TKey>
|
||||
where TKey : IEquatable<TKey>;
|
||||
@@ -119,12 +130,11 @@ namespace MongoDbGenericRepository.DataAccess.Update
|
||||
/// <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="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="value">The value of the field.</param>
|
||||
/// <param name="partitionKey">The optional partition key.</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))
|
||||
where TDocument : IDocument<TKey>
|
||||
where TKey : IEquatable<TKey>;
|
||||
@@ -134,14 +144,10 @@ namespace MongoDbGenericRepository.DataAccess.Update
|
||||
/// </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="TField">The type of the field to update.</typeparam>
|
||||
/// <param name="session">The client session.</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="modifiedDocument">The document with the modifications you want to persist.</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))
|
||||
where TDocument : IDocument<TKey>
|
||||
where TKey : IEquatable<TKey>;
|
||||
@@ -151,14 +157,11 @@ namespace MongoDbGenericRepository.DataAccess.Update
|
||||
/// </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="TField">The type of the field to update.</typeparam>
|
||||
/// <param name="session">The client session.</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="documentToModify">The document to modify.</param>
|
||||
/// <param name="update">The update definition.</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))
|
||||
where TDocument : IDocument<TKey>
|
||||
where TKey : IEquatable<TKey>;
|
||||
|
||||
@@ -4,6 +4,7 @@ using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Linq.Expressions;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace MongoDbGenericRepository
|
||||
@@ -32,7 +33,8 @@ namespace MongoDbGenericRepository
|
||||
/// <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="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 TKey : IEquatable<TKey>;
|
||||
|
||||
@@ -54,7 +56,8 @@ namespace MongoDbGenericRepository
|
||||
/// <typeparam name="TKey">The type of the primary key for a Document.</typeparam>
|
||||
/// <param name="filter">A LINQ expression filter.</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 TKey : IEquatable<TKey>;
|
||||
|
||||
@@ -88,7 +91,8 @@ namespace MongoDbGenericRepository
|
||||
/// <typeparam name="TKey">The type of the primary key for a Document.</typeparam>
|
||||
/// <param name="filter">A LINQ expression filter.</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 TKey : IEquatable<TKey>;
|
||||
|
||||
@@ -110,7 +114,8 @@ namespace MongoDbGenericRepository
|
||||
/// <typeparam name="TKey">The type of the primary key for a Document.</typeparam>
|
||||
/// <param name="filter">A LINQ expression filter.</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 TKey : IEquatable<TKey>;
|
||||
|
||||
@@ -132,7 +137,8 @@ namespace MongoDbGenericRepository
|
||||
/// <typeparam name="TKey">The type of the primary key for a Document.</typeparam>
|
||||
/// <param name="filter">A LINQ expression filter.</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 TKey : IEquatable<TKey>;
|
||||
|
||||
@@ -157,9 +163,13 @@ namespace MongoDbGenericRepository
|
||||
/// <typeparam name="TDocument">The document type.</typeparam>
|
||||
/// <typeparam name="TKey">The type of the primary key.</typeparam>
|
||||
/// <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>
|
||||
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 TKey : IEquatable<TKey>;
|
||||
|
||||
@@ -181,9 +191,13 @@ namespace MongoDbGenericRepository
|
||||
/// <typeparam name="TDocument">The document type.</typeparam>
|
||||
/// <typeparam name="TKey">The type of the primary key.</typeparam>
|
||||
/// <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>
|
||||
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 TKey : IEquatable<TKey>;
|
||||
|
||||
@@ -193,9 +207,9 @@ namespace MongoDbGenericRepository
|
||||
/// <typeparam name="TDocument">The document type.</typeparam>
|
||||
/// <typeparam name="TKey">The type of the primary key.</typeparam>
|
||||
/// <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>
|
||||
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 TKey : IEquatable<TKey>;
|
||||
|
||||
@@ -206,9 +220,14 @@ namespace MongoDbGenericRepository
|
||||
/// <typeparam name="TKey">The type of the primary key.</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="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>
|
||||
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 TKey : IEquatable<TKey>;
|
||||
|
||||
@@ -219,9 +238,9 @@ namespace MongoDbGenericRepository
|
||||
/// <typeparam name="TKey">The type of the primary key.</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="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>
|
||||
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 TKey : IEquatable<TKey>;
|
||||
|
||||
@@ -234,7 +253,12 @@ namespace MongoDbGenericRepository
|
||||
/// <param name="filter">A LINQ expression filter.</param>
|
||||
/// <param name="minValueSelector">A property selector to order by ascending.</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 TKey : IEquatable<TKey>;
|
||||
|
||||
@@ -263,9 +287,11 @@ namespace MongoDbGenericRepository
|
||||
/// <param name="filter">A LINQ expression filter.</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="cancellationToken">An optional cancellation Token.</param>
|
||||
Task<int> SumByAsync<TDocument, TKey>(Expression<Func<TDocument, bool>> filter,
|
||||
Expression<Func<TDocument, int>> selector,
|
||||
string partitionKey = null)
|
||||
string partitionKey = null,
|
||||
CancellationToken cancellationToken = default)
|
||||
where TDocument : IDocument<TKey>
|
||||
where TKey : IEquatable<TKey>;
|
||||
|
||||
@@ -321,10 +347,15 @@ namespace MongoDbGenericRepository
|
||||
/// <typeparam name="TDocument">The type representing 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>
|
||||
/// <param name="filter"></param>
|
||||
/// <param name="filter">A LINQ expression filter.</param>
|
||||
/// <param name="projection">The projection expression.</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 TKey : IEquatable<TKey>
|
||||
where TProjection : class;
|
||||
@@ -349,10 +380,15 @@ namespace MongoDbGenericRepository
|
||||
/// <typeparam name="TDocument">The type representing 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>
|
||||
/// <param name="filter"></param>
|
||||
/// <param name="filter">A LINQ expression filter.</param>
|
||||
/// <param name="projection">The projection expression.</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>
|
||||
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 TKey : IEquatable<TKey>
|
||||
where TProjection : class;
|
||||
@@ -450,12 +486,14 @@ namespace MongoDbGenericRepository
|
||||
/// <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="partitionKey">An optional partition key.</param>
|
||||
/// <param name="cancellationToken">An optional cancellation Token.</param>
|
||||
Task<List<TDocument>> GetSortedPaginatedAsync<TDocument, TKey>(
|
||||
Expression<Func<TDocument, bool>> filter,
|
||||
SortDefinition<TDocument> sortDefinition,
|
||||
int skipNumber = 0,
|
||||
int takeNumber = 50,
|
||||
string partitionKey = null)
|
||||
string partitionKey = null,
|
||||
CancellationToken cancellationToken = default)
|
||||
where TDocument : IDocument<TKey>
|
||||
where TKey : IEquatable<TKey>;
|
||||
|
||||
|
||||
@@ -18,7 +18,7 @@ namespace MongoDbGenericRepository
|
||||
/// <param name="session">The client session.</param>
|
||||
/// <param name="modifiedDocument">The document with the modifications you want to persist.</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))
|
||||
where TDocument : IDocument<TKey>
|
||||
where TKey : IEquatable<TKey>
|
||||
@@ -34,7 +34,7 @@ namespace MongoDbGenericRepository
|
||||
/// <param name="session">The client session.</param>
|
||||
/// <param name="modifiedDocument">The document with the modifications you want to persist.</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))
|
||||
where TDocument : IDocument<TKey>
|
||||
where TKey : IEquatable<TKey>
|
||||
@@ -51,7 +51,7 @@ namespace MongoDbGenericRepository
|
||||
/// <param name="documentToModify">The document to modify.</param>
|
||||
/// <param name="update">The update definition.</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))
|
||||
where TDocument : IDocument<TKey>
|
||||
where TKey : IEquatable<TKey>
|
||||
@@ -68,7 +68,7 @@ namespace MongoDbGenericRepository
|
||||
/// <param name="documentToModify">The document to modify.</param>
|
||||
/// <param name="update">The update definition.</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))
|
||||
where TDocument : IDocument<TKey>
|
||||
where TKey : IEquatable<TKey>
|
||||
@@ -87,7 +87,7 @@ namespace MongoDbGenericRepository
|
||||
/// <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>
|
||||
/// <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))
|
||||
where TDocument : IDocument<TKey>
|
||||
where TKey : IEquatable<TKey>
|
||||
@@ -106,7 +106,7 @@ namespace MongoDbGenericRepository
|
||||
/// <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>
|
||||
/// <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))
|
||||
where TDocument : IDocument<TKey>
|
||||
where TKey : IEquatable<TKey>
|
||||
@@ -126,7 +126,7 @@ namespace MongoDbGenericRepository
|
||||
/// <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>
|
||||
/// <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))
|
||||
where TDocument : IDocument<TKey>
|
||||
where TKey : IEquatable<TKey>
|
||||
@@ -146,7 +146,7 @@ namespace MongoDbGenericRepository
|
||||
/// <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>
|
||||
/// <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))
|
||||
where TDocument : IDocument<TKey>
|
||||
where TKey : IEquatable<TKey>
|
||||
@@ -166,7 +166,7 @@ namespace MongoDbGenericRepository
|
||||
/// <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>
|
||||
/// <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))
|
||||
where TDocument : IDocument<TKey>
|
||||
where TKey : IEquatable<TKey>
|
||||
@@ -186,7 +186,7 @@ namespace MongoDbGenericRepository
|
||||
/// <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>
|
||||
/// <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))
|
||||
where TDocument : IDocument<TKey>
|
||||
where TKey : IEquatable<TKey>
|
||||
|
||||
@@ -7,10 +7,20 @@ using System.Linq.Expressions;
|
||||
|
||||
namespace MongoDbGenericRepository.DataAccess.Base
|
||||
{
|
||||
/// <summary>
|
||||
/// A base class for accessing the Database and its Collections.
|
||||
/// </summary>
|
||||
public class DataAccessBase
|
||||
{
|
||||
/// <summary>
|
||||
/// The MongoDbContext
|
||||
/// </summary>
|
||||
protected IMongoDbContext MongoDbContext;
|
||||
|
||||
/// <summary>
|
||||
/// The constructor of the DataAccessBase class
|
||||
/// </summary>
|
||||
/// <param name="mongoDbContext"></param>
|
||||
public DataAccessBase(IMongoDbContext mongoDbContext)
|
||||
{
|
||||
MongoDbContext = mongoDbContext;
|
||||
@@ -108,7 +118,6 @@ namespace MongoDbGenericRepository.DataAccess.Base
|
||||
LanguageOverride = indexCreationOptions.LanguageOverride,
|
||||
ExpireAfter = indexCreationOptions.ExpireAfter,
|
||||
DefaultLanguage = indexCreationOptions.DefaultLanguage,
|
||||
BucketSize = indexCreationOptions.BucketSize,
|
||||
Bits = indexCreationOptions.Bits,
|
||||
Background = indexCreationOptions.Background,
|
||||
Version = indexCreationOptions.Version
|
||||
|
||||
@@ -6,6 +6,7 @@ using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Linq.Expressions;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace MongoDbGenericRepository.DataAccess.Read
|
||||
@@ -25,12 +26,13 @@ namespace MongoDbGenericRepository.DataAccess.Read
|
||||
/// <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="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 TKey : IEquatable<TKey>
|
||||
{
|
||||
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>
|
||||
@@ -55,11 +57,12 @@ namespace MongoDbGenericRepository.DataAccess.Read
|
||||
/// <typeparam name="TKey">The type of the primary key for a Document.</typeparam>
|
||||
/// <param name="filter">A LINQ expression filter.</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 TKey : IEquatable<TKey>
|
||||
{
|
||||
return await HandlePartitioned<TDocument, TKey>(partitionKey).Find(filter).FirstOrDefaultAsync();
|
||||
return await HandlePartitioned<TDocument, TKey>(partitionKey).Find(filter).FirstOrDefaultAsync(cancellationToken);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -97,11 +100,12 @@ namespace MongoDbGenericRepository.DataAccess.Read
|
||||
/// <typeparam name="TKey">The type of the primary key for a Document.</typeparam>
|
||||
/// <param name="filter">A LINQ expression filter.</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 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);
|
||||
}
|
||||
|
||||
@@ -127,11 +131,12 @@ namespace MongoDbGenericRepository.DataAccess.Read
|
||||
/// <typeparam name="TKey">The type of the primary key for a Document.</typeparam>
|
||||
/// <param name="filter">A LINQ expression filter.</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 TKey : IEquatable<TKey>
|
||||
{
|
||||
return await HandlePartitioned<TDocument, TKey>(partitionKey).Find(filter).ToListAsync();
|
||||
return await HandlePartitioned<TDocument, TKey>(partitionKey).Find(filter).ToListAsync(cancellationToken);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -155,11 +160,12 @@ namespace MongoDbGenericRepository.DataAccess.Read
|
||||
/// <typeparam name="TKey">The type of the primary key for a Document.</typeparam>
|
||||
/// <param name="filter">A LINQ expression filter.</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 TKey : IEquatable<TKey>
|
||||
{
|
||||
return await HandlePartitioned<TDocument, TKey>(partitionKey).CountDocumentsAsync(filter);
|
||||
return await HandlePartitioned<TDocument, TKey>(partitionKey).CountDocumentsAsync(filter, cancellationToken: cancellationToken);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -187,15 +193,16 @@ namespace MongoDbGenericRepository.DataAccess.Read
|
||||
/// <typeparam name="TKey">The type of the primary key.</typeparam>
|
||||
/// <param name="filter">A LINQ expression filter.</param>
|
||||
/// <param name="maxValueSelector">A property selector to order by descending.</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="partitionKey">An optional partitionKey.</param
|
||||
/// <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 TKey : IEquatable<TKey>
|
||||
{
|
||||
return await GetCollection<TDocument, TKey>(partitionKey).Find(Builders<TDocument>.Filter.Where(filter))
|
||||
.SortByDescending(maxValueSelector)
|
||||
.Limit(1)
|
||||
.FirstOrDefaultAsync();
|
||||
.FirstOrDefaultAsync(cancellationToken);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -224,14 +231,15 @@ namespace MongoDbGenericRepository.DataAccess.Read
|
||||
/// <param name="filter">A LINQ expression filter.</param>
|
||||
/// <param name="minValueSelector">A property selector to order by ascending.</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 TKey : IEquatable<TKey>
|
||||
{
|
||||
return await GetCollection<TDocument, TKey>(partitionKey).Find(Builders<TDocument>.Filter.Where(filter))
|
||||
.SortBy(minValueSelector)
|
||||
.Limit(1)
|
||||
.FirstOrDefaultAsync();
|
||||
.FirstOrDefaultAsync(cancellationToken);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -257,16 +265,18 @@ namespace MongoDbGenericRepository.DataAccess.Read
|
||||
/// </summary>
|
||||
/// <typeparam name="TDocument">The document type.</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="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>
|
||||
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 TKey : IEquatable<TKey>
|
||||
{
|
||||
return await GetMaxMongoQuery<TDocument, TKey, TValue>(filter, maxValueSelector, partitionKey)
|
||||
.Project(maxValueSelector)
|
||||
.FirstOrDefaultAsync();
|
||||
.FirstOrDefaultAsync(cancellationToken);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -296,11 +306,12 @@ namespace MongoDbGenericRepository.DataAccess.Read
|
||||
/// <param name="filter">A LINQ expression filter.</param>
|
||||
/// <param name="minValueSelector">A property selector to order by ascending.</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 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>
|
||||
@@ -332,13 +343,15 @@ namespace MongoDbGenericRepository.DataAccess.Read
|
||||
/// <param name="filter">A LINQ expression filter.</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="cancellationToken">An optional cancellation Token.</param>
|
||||
public virtual async Task<int> SumByAsync<TDocument, TKey>(Expression<Func<TDocument, bool>> filter,
|
||||
Expression<Func<TDocument, int>> selector,
|
||||
string partitionKey = null)
|
||||
string partitionKey = null,
|
||||
CancellationToken cancellationToken = default)
|
||||
where TDocument : IDocument<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>
|
||||
@@ -366,13 +379,14 @@ namespace MongoDbGenericRepository.DataAccess.Read
|
||||
/// <param name="filter">A LINQ expression filter.</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="cancellationToken">An optional cancellation Token.</param>
|
||||
public virtual async Task<decimal> SumByAsync<TDocument, TKey>(Expression<Func<TDocument, bool>> filter,
|
||||
Expression<Func<TDocument, decimal>> selector,
|
||||
string partitionKey = null)
|
||||
string partitionKey = null, CancellationToken cancellationToken = default)
|
||||
where TDocument : IDocument<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>
|
||||
@@ -451,6 +465,36 @@ namespace MongoDbGenericRepository.DataAccess.Read
|
||||
.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>
|
||||
/// Asynchronously returns a paginated list of the documents matching the filter condition.
|
||||
/// </summary>
|
||||
@@ -462,13 +506,15 @@ namespace MongoDbGenericRepository.DataAccess.Read
|
||||
/// <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="partitionKey">An optional partition key.</param>
|
||||
/// <param name="cancellationToken">An optional cancellation Token.</param>
|
||||
public virtual async Task<List<TDocument>> GetSortedPaginatedAsync<TDocument, TKey>(
|
||||
Expression<Func<TDocument, bool>> filter,
|
||||
Expression<Func<TDocument, object>> sortSelector,
|
||||
bool ascending = true,
|
||||
int skipNumber = 0,
|
||||
int takeNumber = 50,
|
||||
string partitionKey = null)
|
||||
string partitionKey = null,
|
||||
CancellationToken cancellationToken = default)
|
||||
where TDocument : IDocument<TKey>
|
||||
where TKey : IEquatable<TKey>
|
||||
{
|
||||
@@ -481,7 +527,7 @@ namespace MongoDbGenericRepository.DataAccess.Read
|
||||
.Sort(sorting)
|
||||
.Skip(skipNumber)
|
||||
.Limit(takeNumber)
|
||||
.ToListAsync();
|
||||
.ToListAsync(cancellationToken);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -494,12 +540,14 @@ namespace MongoDbGenericRepository.DataAccess.Read
|
||||
/// <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="partitionKey">An optional partition key.</param>
|
||||
/// <param name="cancellationToken">An optional cancellation Token.</param>
|
||||
public virtual async Task<List<TDocument>> GetSortedPaginatedAsync<TDocument, TKey>(
|
||||
Expression<Func<TDocument, bool>> filter,
|
||||
SortDefinition<TDocument> sortDefinition,
|
||||
int skipNumber = 0,
|
||||
int takeNumber = 50,
|
||||
string partitionKey = null)
|
||||
string partitionKey = null,
|
||||
CancellationToken cancellationToken = default)
|
||||
where TDocument : IDocument<TKey>
|
||||
where TKey : IEquatable<TKey>
|
||||
{
|
||||
@@ -508,7 +556,7 @@ namespace MongoDbGenericRepository.DataAccess.Read
|
||||
.Sort(sortDefinition)
|
||||
.Skip(skipNumber)
|
||||
.Limit(takeNumber)
|
||||
.ToListAsync();
|
||||
.ToListAsync(cancellationToken);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,6 +5,7 @@ using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Linq.Expressions;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace MongoDbGenericRepository.DataAccess.Read
|
||||
@@ -20,14 +21,19 @@ namespace MongoDbGenericRepository.DataAccess.Read
|
||||
/// <param name="filter">A LINQ expression filter.</param>
|
||||
/// <param name="projection">The projection expression.</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 TKey : IEquatable<TKey>
|
||||
where TProjection : class
|
||||
{
|
||||
return await HandlePartitioned<TDocument, TKey>(partitionKey).Find(filter)
|
||||
.Project(projection)
|
||||
.FirstOrDefaultAsync();
|
||||
.FirstOrDefaultAsync(cancellationToken);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -58,14 +64,19 @@ namespace MongoDbGenericRepository.DataAccess.Read
|
||||
/// <param name="filter">A LINQ expression filter.</param>
|
||||
/// <param name="projection">The projection expression.</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 TKey : IEquatable<TKey>
|
||||
where TProjection : class
|
||||
{
|
||||
return await HandlePartitioned<TDocument, TKey>(partitionKey).Find(filter)
|
||||
.Project(projection)
|
||||
.ToListAsync();
|
||||
.ToListAsync(cancellationToken);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
||||
@@ -62,7 +62,7 @@ namespace MongoDbGenericRepository.DataAccess.Update
|
||||
where TKey : IEquatable<TKey>
|
||||
{
|
||||
var filter = Builders<TDocument>.Filter.Eq("Id", documentToModify.Id);
|
||||
var updateRes = await HandlePartitioned<TDocument, TKey>(documentToModify).UpdateOneAsync(session, filter, update, new UpdateOptions { IsUpsert = true }, cancellationToken).ConfigureAwait(false);
|
||||
var updateRes = await HandlePartitioned<TDocument, TKey>(documentToModify).UpdateOneAsync(session, filter, update, null, cancellationToken).ConfigureAwait(false);
|
||||
return updateRes.ModifiedCount == 1;
|
||||
}
|
||||
|
||||
@@ -81,7 +81,7 @@ namespace MongoDbGenericRepository.DataAccess.Update
|
||||
where TKey : IEquatable<TKey>
|
||||
{
|
||||
var filter = Builders<TDocument>.Filter.Eq("Id", documentToModify.Id);
|
||||
var updateRes = HandlePartitioned<TDocument, TKey>(documentToModify).UpdateOne(session, filter, update, new UpdateOptions { IsUpsert = true }, cancellationToken);
|
||||
var updateRes = HandlePartitioned<TDocument, TKey>(documentToModify).UpdateOne(session, filter, update, null, cancellationToken);
|
||||
return updateRes.ModifiedCount == 1;
|
||||
}
|
||||
|
||||
|
||||
@@ -56,7 +56,7 @@ namespace MongoDbGenericRepository.DataAccess.Update
|
||||
where TKey : IEquatable<TKey>
|
||||
{
|
||||
var filter = Builders<TDocument>.Filter.Eq("Id", documentToModify.Id);
|
||||
var updateRes = await HandlePartitioned<TDocument, TKey>(documentToModify).UpdateOneAsync(filter, update, new UpdateOptions { IsUpsert = true });
|
||||
var updateRes = await HandlePartitioned<TDocument, TKey>(documentToModify).UpdateOneAsync(filter, update);
|
||||
return updateRes.ModifiedCount == 1;
|
||||
}
|
||||
|
||||
@@ -72,7 +72,7 @@ namespace MongoDbGenericRepository.DataAccess.Update
|
||||
where TKey : IEquatable<TKey>
|
||||
{
|
||||
var filter = Builders<TDocument>.Filter.Eq("Id", documentToModify.Id);
|
||||
var updateRes = HandlePartitioned<TDocument, TKey>(documentToModify).UpdateOne(filter, update, new UpdateOptions { IsUpsert = true });
|
||||
var updateRes = HandlePartitioned<TDocument, TKey>(documentToModify).UpdateOne(filter, update);
|
||||
return updateRes.ModifiedCount == 1;
|
||||
}
|
||||
|
||||
@@ -250,7 +250,7 @@ namespace MongoDbGenericRepository.DataAccess.Update
|
||||
where TKey : IEquatable<TKey>
|
||||
{
|
||||
var collection = string.IsNullOrEmpty(partitionKey) ? GetCollection<TDocument, TKey>() : GetCollection<TDocument, TKey>(partitionKey);
|
||||
var updateRes = await collection.UpdateManyAsync(filter, updateDefinition, new UpdateOptions { IsUpsert = true });
|
||||
var updateRes = await collection.UpdateManyAsync(filter, updateDefinition);
|
||||
return updateRes.ModifiedCount;
|
||||
}
|
||||
|
||||
@@ -304,7 +304,7 @@ namespace MongoDbGenericRepository.DataAccess.Update
|
||||
where TKey : IEquatable<TKey>
|
||||
{
|
||||
var collection = string.IsNullOrEmpty(partitionKey) ? GetCollection<TDocument, TKey>() : GetCollection<TDocument, TKey>(partitionKey);
|
||||
var updateRes = collection.UpdateMany(filter, UpdateDefinition, new UpdateOptions { IsUpsert = true });
|
||||
var updateRes = collection.UpdateMany(filter, UpdateDefinition);
|
||||
return updateRes.ModifiedCount;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -52,10 +52,6 @@ namespace MongoDbGenericRepository.Models
|
||||
/// </summary>
|
||||
public string DefaultLanguage { get; set; }
|
||||
/// <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.
|
||||
/// </summary>
|
||||
public int? Bits { get; set; }
|
||||
|
||||
@@ -2,8 +2,9 @@
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFrameworks>net452;netstandard2.0;netstandard1.5;</TargetFrameworks>
|
||||
<GenerateDocumentationFile>true</GenerateDocumentationFile>
|
||||
<PackageId>MongoDbGenericRepository</PackageId>
|
||||
<PackageVersion>1.4.4</PackageVersion>
|
||||
<PackageVersion>1.4.6</PackageVersion>
|
||||
<Authors>Alexandre Spieser</Authors>
|
||||
<PackageTitle>MongoDb Generic Repository</PackageTitle>
|
||||
<Description>A generic repository implementation using the MongoDB C# Sharp 2.0 driver.</Description>
|
||||
@@ -14,25 +15,17 @@
|
||||
<Copyright>Copyright 2020 (c) Alexandre Spieser. All rights reserved.</Copyright>
|
||||
<PackageTags>MongoDb Repository Generic NoSql</PackageTags>
|
||||
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
|
||||
<Version>1.4.4</Version>
|
||||
<Version>1.4.6</Version>
|
||||
<RepositoryUrl>https://github.com/alexandre-spieser/mongodb-generic-repository</RepositoryUrl>
|
||||
<RepositoryType>Git</RepositoryType>
|
||||
</PropertyGroup>
|
||||
|
||||
<PropertyGroup Condition="'$(Configuration)|$(TargetFramework)|$(Platform)'=='Release|net45|AnyCPU'">
|
||||
<DocumentationFile>bin\Release\net45\MongoDbGenericRepository.xml</DocumentationFile>
|
||||
</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>
|
||||
<DocumentationFile>bin\$(Configuration)\$(TargetFramework)\$(AssemblyName).xml</DocumentationFile>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="MongoDB.Driver" Version="2.9.3" />
|
||||
<PackageReference Include="MongoDB.Driver" Version="2.12.0" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
<package >
|
||||
<metadata>
|
||||
<id>MongoDbGenericRepository</id>
|
||||
<version>1.4.4</version>
|
||||
<version>1.4.5</version>
|
||||
<title>MongoDb Generic Repository</title>
|
||||
<authors>Alexandre Spieser</authors>
|
||||
<owners>Alexandre Spieser</owners>
|
||||
|
||||
@@ -5,6 +5,7 @@ using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Linq.Expressions;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace MongoDbGenericRepository
|
||||
@@ -49,11 +50,12 @@ namespace MongoDbGenericRepository
|
||||
/// <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="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 TKey : IEquatable<TKey>
|
||||
{
|
||||
return await MongoDbReader.GetByIdAsync<TDocument, TKey>(id, partitionKey);
|
||||
return await MongoDbReader.GetByIdAsync<TDocument, TKey>(id, partitionKey, cancellationToken);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -77,11 +79,12 @@ namespace MongoDbGenericRepository
|
||||
/// <typeparam name="TKey">The type of the primary key for a Document.</typeparam>
|
||||
/// <param name="filter">A LINQ expression filter.</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 TKey : IEquatable<TKey>
|
||||
{
|
||||
return await MongoDbReader.GetOneAsync<TDocument, TKey>(filter, partitionKey);
|
||||
return await MongoDbReader.GetOneAsync<TDocument, TKey>(filter, partitionKey, cancellationToken);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -119,11 +122,12 @@ namespace MongoDbGenericRepository
|
||||
/// <typeparam name="TKey">The type of the primary key for a Document.</typeparam>
|
||||
/// <param name="filter">A LINQ expression filter.</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 TKey : IEquatable<TKey>
|
||||
{
|
||||
return await MongoDbReader.AnyAsync<TDocument, TKey>(filter, partitionKey);
|
||||
return await MongoDbReader.AnyAsync<TDocument, TKey>(filter, partitionKey, cancellationToken);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -147,11 +151,12 @@ namespace MongoDbGenericRepository
|
||||
/// <typeparam name="TKey">The type of the primary key for a Document.</typeparam>
|
||||
/// <param name="filter">A LINQ expression filter.</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 TKey : IEquatable<TKey>
|
||||
{
|
||||
return await MongoDbReader.GetAllAsync<TDocument, TKey>(filter, partitionKey);
|
||||
return await MongoDbReader.GetAllAsync<TDocument, TKey>(filter, partitionKey, cancellationToken);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -175,11 +180,12 @@ namespace MongoDbGenericRepository
|
||||
/// <typeparam name="TKey">The type of the primary key for a Document.</typeparam>
|
||||
/// <param name="filter">A LINQ expression filter.</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 TKey : IEquatable<TKey>
|
||||
{
|
||||
return await MongoDbReader.CountAsync<TDocument, TKey>(filter, partitionKey);
|
||||
return await MongoDbReader.CountAsync<TDocument, TKey>(filter, partitionKey, cancellationToken);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -204,11 +210,15 @@ namespace MongoDbGenericRepository
|
||||
/// <param name="filter">A LINQ expression filter.</param>
|
||||
/// <param name="maxValueSelector">A property selector to order by descending.</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 TKey : IEquatable<TKey>
|
||||
{
|
||||
return await MongoDbReader.GetByMaxAsync<TDocument, TKey>(filter, maxValueSelector, partitionKey);
|
||||
return await MongoDbReader.GetByMaxAsync<TDocument, TKey>(filter, maxValueSelector, partitionKey, cancellationToken);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -232,13 +242,17 @@ namespace MongoDbGenericRepository
|
||||
/// <typeparam name="TDocument">The document type.</typeparam>
|
||||
/// <typeparam name="TKey">The type of the primary key.</typeparam>
|
||||
/// <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>
|
||||
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 TKey : IEquatable<TKey>
|
||||
{
|
||||
return await MongoDbReader.GetByMinAsync<TDocument, TKey>(filter, minValueSelector, partitionKey);
|
||||
return await MongoDbReader.GetByMinAsync<TDocument, TKey>(filter, minValueSelector, partitionKey, cancellationToken);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -247,7 +261,7 @@ namespace MongoDbGenericRepository
|
||||
/// <typeparam name="TDocument">The document type.</typeparam>
|
||||
/// <typeparam name="TKey">The type of the primary key.</typeparam>
|
||||
/// <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>
|
||||
public virtual TDocument GetByMin<TDocument, TKey>(Expression<Func<TDocument, bool>> filter, Expression<Func<TDocument, object>> minValueSelector, string partitionKey = null)
|
||||
where TDocument : IDocument<TKey>
|
||||
@@ -263,13 +277,18 @@ namespace MongoDbGenericRepository
|
||||
/// <typeparam name="TKey">The type of the primary key.</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="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>
|
||||
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 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>
|
||||
@@ -297,11 +316,16 @@ namespace MongoDbGenericRepository
|
||||
/// <param name="filter">A LINQ expression filter.</param>
|
||||
/// <param name="minValueSelector">A property selector to order by ascending.</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 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>
|
||||
@@ -332,13 +356,15 @@ namespace MongoDbGenericRepository
|
||||
/// <param name="filter">A LINQ expression filter.</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="cancellationToken">An optional cancellation Token.</param>
|
||||
public virtual async Task<int> SumByAsync<TDocument, TKey>(Expression<Func<TDocument, bool>> filter,
|
||||
Expression<Func<TDocument, int>> selector,
|
||||
string partitionKey = null)
|
||||
string partitionKey = null,
|
||||
CancellationToken cancellationToken = default)
|
||||
where TDocument : IDocument<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>
|
||||
@@ -405,12 +431,17 @@ namespace MongoDbGenericRepository
|
||||
/// <param name="filter">A LINQ expression filter.</param>
|
||||
/// <param name="projection">The projection expression.</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 TKey : IEquatable<TKey>
|
||||
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>
|
||||
@@ -439,12 +470,16 @@ namespace MongoDbGenericRepository
|
||||
/// <param name="filter">A LINQ expression filter.</param>
|
||||
/// <param name="projection">The projection expression.</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 TKey : IEquatable<TKey>
|
||||
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>
|
||||
@@ -562,12 +597,14 @@ namespace MongoDbGenericRepository
|
||||
/// <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="partitionKey">An optional partition key.</param>
|
||||
/// <param name="cancellationToken">An optional cancellation Token.</param>
|
||||
public virtual async Task<List<TDocument>> GetSortedPaginatedAsync<TDocument, TKey>(
|
||||
Expression<Func<TDocument, bool>> filter,
|
||||
SortDefinition<TDocument> sortDefinition,
|
||||
int skipNumber = 0,
|
||||
int takeNumber = 50,
|
||||
string partitionKey = null)
|
||||
string partitionKey = null,
|
||||
CancellationToken cancellationToken = default)
|
||||
where TDocument : IDocument<TKey>
|
||||
where TKey : IEquatable<TKey>
|
||||
{
|
||||
@@ -576,7 +613,7 @@ namespace MongoDbGenericRepository
|
||||
.Sort(sortDefinition)
|
||||
.Skip(skipNumber)
|
||||
.Limit(takeNumber)
|
||||
.ToListAsync();
|
||||
.ToListAsync(cancellationToken);
|
||||
}
|
||||
|
||||
#endregion Pagination
|
||||
|
||||
Binary file not shown.
File diff suppressed because it is too large
Load Diff
Binary file not shown.
Binary file not shown.
@@ -11,7 +11,7 @@ The MongoDbGenericRepository is also used in [AspNetCore.Identity.MongoDbCore](h
|
||||
|
||||
# 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
|
||||
|
||||
|
||||
Reference in New Issue
Block a user