getandupdate and getpaginated
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq.Expressions;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using MongoDB.Driver;
|
||||
using MongoDbGenericRepository.Models;
|
||||
@@ -39,42 +40,29 @@ namespace MongoDbGenericRepository
|
||||
{
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Asynchronously returns a paginated list of the documents matching the filter condition.
|
||||
/// </summary>
|
||||
/// <typeparam name="TDocument">The type representing a Document.</typeparam>
|
||||
/// <param name="filter">A LINQ expression filter.</param>
|
||||
/// <param name="skipNumber">The number of documents you want to skip. Default value is 0.</param>
|
||||
/// <param name="takeNumber">The number of documents you want to take. Default value is 50.</param>
|
||||
/// <param name="partitionKey">An optional partition key.</param>
|
||||
/// <inheritdoc />
|
||||
public virtual async Task<List<TDocument>> GetPaginatedAsync<TDocument>(
|
||||
Expression<Func<TDocument, bool>> filter,
|
||||
int skipNumber = 0,
|
||||
int takeNumber = 50,
|
||||
string partitionKey = null)
|
||||
string partitionKey = null,
|
||||
CancellationToken cancellationToken = default)
|
||||
where TDocument : IDocument
|
||||
{
|
||||
return await HandlePartitioned<TDocument>(partitionKey).Find(filter).Skip(skipNumber).Limit(takeNumber).ToListAsync();
|
||||
return await HandlePartitioned<TDocument>(partitionKey).Find(filter).Skip(skipNumber).Limit(takeNumber).ToListAsync(cancellationToken);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Asynchronously returns a paginated list of the documents matching the filter condition.
|
||||
/// </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="filter">A LINQ expression filter.</param>
|
||||
/// <param name="skipNumber">The number of documents you want to skip. Default value is 0.</param>
|
||||
/// <param name="takeNumber">The number of documents you want to take. Default value is 50.</param>
|
||||
/// <param name="partitionKey">An optional partition key.</param>
|
||||
/// <inheritdoc />
|
||||
public virtual async Task<List<TDocument>> GetPaginatedAsync<TDocument, TKey>(
|
||||
Expression<Func<TDocument, bool>> filter,
|
||||
int skipNumber = 0,
|
||||
int takeNumber = 50,
|
||||
string partitionKey = null)
|
||||
string partitionKey = null,
|
||||
CancellationToken cancellationToken = default)
|
||||
where TDocument : IDocument<TKey>
|
||||
where TKey : IEquatable<TKey>
|
||||
{
|
||||
return await HandlePartitioned<TDocument, TKey>(partitionKey).Find(filter).Skip(skipNumber).Limit(takeNumber).ToListAsync();
|
||||
return await HandlePartitioned<TDocument, TKey>(partitionKey).Find(filter).Skip(skipNumber).Limit(takeNumber).ToListAsync(cancellationToken);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -150,33 +138,28 @@ namespace MongoDbGenericRepository
|
||||
}
|
||||
|
||||
#region Find And Update
|
||||
|
||||
/// <summary>
|
||||
/// GetAndUpdateOne with filter
|
||||
/// </summary>
|
||||
/// <typeparam name="TDocument">The type representing a Document.</typeparam>
|
||||
/// <param name="filter">A LINQ expression filter.</param>
|
||||
/// <param name="update"></param>
|
||||
/// <param name="options"></param>
|
||||
/// <returns></returns>
|
||||
/// <inheritdoc />
|
||||
public virtual async Task<TDocument> GetAndUpdateOne<TDocument>(
|
||||
FilterDefinition<TDocument> filter,
|
||||
UpdateDefinition<TDocument> update,
|
||||
FindOneAndUpdateOptions<TDocument, TDocument> options)
|
||||
where TDocument : IDocument
|
||||
{
|
||||
return await GetCollection<TDocument>().FindOneAndUpdateAsync(filter, update, options);
|
||||
return await GetAndUpdateOne(filter, update, options, CancellationToken.None);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// GetAndUpdateOne with filter
|
||||
/// </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="filter">A LINQ expression filter.</param>
|
||||
/// <param name="update"></param>
|
||||
/// <param name="options"></param>
|
||||
/// <returns></returns>
|
||||
/// <inheritdoc />
|
||||
public virtual async Task<TDocument> GetAndUpdateOne<TDocument>(
|
||||
FilterDefinition<TDocument> filter,
|
||||
UpdateDefinition<TDocument> update,
|
||||
FindOneAndUpdateOptions<TDocument, TDocument> options,
|
||||
CancellationToken cancellationToken)
|
||||
where TDocument : IDocument
|
||||
{
|
||||
return await GetCollection<TDocument>().FindOneAndUpdateAsync(filter, update, options, cancellationToken);
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public virtual async Task<TDocument> GetAndUpdateOne<TDocument, TKey>(
|
||||
FilterDefinition<TDocument> filter,
|
||||
UpdateDefinition<TDocument> update,
|
||||
@@ -184,7 +167,19 @@ namespace MongoDbGenericRepository
|
||||
where TDocument : IDocument<TKey>
|
||||
where TKey : IEquatable<TKey>
|
||||
{
|
||||
return await GetCollection<TDocument, TKey>().FindOneAndUpdateAsync(filter, update, options);
|
||||
return await GetAndUpdateOne<TDocument, TKey>(filter, update, options, CancellationToken.None);
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public virtual async Task<TDocument> GetAndUpdateOne<TDocument, TKey>(
|
||||
FilterDefinition<TDocument> filter,
|
||||
UpdateDefinition<TDocument> update,
|
||||
FindOneAndUpdateOptions<TDocument, TDocument> options,
|
||||
CancellationToken cancellationToken)
|
||||
where TDocument : IDocument<TKey>
|
||||
where TKey : IEquatable<TKey>
|
||||
{
|
||||
return await GetCollection<TDocument, TKey>().FindOneAndUpdateAsync(filter, update, options, cancellationToken);
|
||||
}
|
||||
|
||||
#endregion Find And Update
|
||||
|
||||
Reference in New Issue
Block a user