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