adding cancellation token
This commit is contained in:
@@ -8,7 +8,6 @@
|
||||
<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.12.0" />
|
||||
<PackageReference Include="MongoDbGenericRepository" Version="1.4.6" />
|
||||
<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>
|
||||
|
||||
@@ -137,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>;
|
||||
|
||||
@@ -162,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>;
|
||||
|
||||
@@ -186,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>;
|
||||
|
||||
@@ -198,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>;
|
||||
|
||||
@@ -211,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>;
|
||||
|
||||
@@ -224,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>;
|
||||
|
||||
@@ -239,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>;
|
||||
|
||||
@@ -268,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>;
|
||||
|
||||
@@ -326,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;
|
||||
@@ -354,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;
|
||||
@@ -455,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>;
|
||||
|
||||
|
||||
@@ -343,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>
|
||||
|
||||
@@ -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>
|
||||
|
||||
@@ -180,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>
|
||||
@@ -209,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>
|
||||
@@ -237,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>
|
||||
@@ -252,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>
|
||||
@@ -268,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>
|
||||
@@ -302,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>
|
||||
@@ -337,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>
|
||||
@@ -410,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>
|
||||
@@ -444,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>
|
||||
@@ -567,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>
|
||||
{
|
||||
@@ -581,7 +613,7 @@ namespace MongoDbGenericRepository
|
||||
.Sort(sortDefinition)
|
||||
.Skip(skipNumber)
|
||||
.Limit(takeNumber)
|
||||
.ToListAsync();
|
||||
.ToListAsync(cancellationToken);
|
||||
}
|
||||
|
||||
#endregion Pagination
|
||||
|
||||
Reference in New Issue
Block a user