pushed cancellation token changes
This commit is contained in:
@@ -28,6 +28,14 @@ namespace MongoDbGenericRepository.DataAccess.Base
|
||||
|
||||
#region Utility Methods
|
||||
|
||||
/// <summary>
|
||||
/// Gets a IMongoQueryable for a potentially partitioned document type and a filter.
|
||||
/// </summary>
|
||||
/// <typeparam name="TDocument">The document type.</typeparam>
|
||||
/// <typeparam name="TKey">The type of the primary key.</typeparam>
|
||||
/// <param name="filter">The filter definition.</param>
|
||||
/// <param name="partitionKey">The collection partition key.</param>
|
||||
/// <returns></returns>
|
||||
public virtual IMongoQueryable<TDocument> GetQuery<TDocument, TKey>(Expression<Func<TDocument, bool>> filter, string partitionKey = null)
|
||||
where TDocument : IDocument<TKey>
|
||||
where TKey : IEquatable<TKey>
|
||||
|
||||
@@ -6,12 +6,20 @@ using MongoDbGenericRepository.Utils;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace MongoDbGenericRepository.DataAccess.Create
|
||||
{
|
||||
/// <summary>
|
||||
/// A class to insert MongoDb document.
|
||||
/// </summary>
|
||||
public class MongoDbCreator : DataAccessBase
|
||||
{
|
||||
/// <summary>
|
||||
/// The construct of the MongoDbCreator class.
|
||||
/// </summary>
|
||||
/// <param name="mongoDbContext">A <see cref="IMongoDbContext"/> instance.</param>
|
||||
public MongoDbCreator(IMongoDbContext mongoDbContext) : base(mongoDbContext)
|
||||
{
|
||||
}
|
||||
@@ -25,12 +33,13 @@ namespace MongoDbGenericRepository.DataAccess.Create
|
||||
/// <typeparam name="TDocument">The type representing a Document.</typeparam>
|
||||
/// <typeparam name="TKey">The type of the primary key for a Document.</typeparam>
|
||||
/// <param name="document">The document you want to add.</param>
|
||||
public virtual async Task AddOneAsync<TDocument, TKey>(TDocument document)
|
||||
/// <param name="cancellationToken">An optional cancellation Token.</param>
|
||||
public virtual async Task AddOneAsync<TDocument, TKey>(TDocument document, CancellationToken cancellationToken = default)
|
||||
where TDocument : IDocument<TKey>
|
||||
where TKey : IEquatable<TKey>
|
||||
{
|
||||
FormatDocument<TDocument, TKey>(document);
|
||||
await HandlePartitioned<TDocument, TKey>(document).InsertOneAsync(document);
|
||||
await HandlePartitioned<TDocument, TKey>(document).InsertOneAsync(document, null, cancellationToken);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -55,7 +64,8 @@ namespace MongoDbGenericRepository.DataAccess.Create
|
||||
/// <typeparam name="TDocument">The type representing a Document.</typeparam>
|
||||
/// <typeparam name="TKey">The type of the primary key for a Document.</typeparam>
|
||||
/// <param name="documents">The documents you want to add.</param>
|
||||
public virtual async Task AddManyAsync<TDocument, TKey>(IEnumerable<TDocument> documents)
|
||||
/// <param name="cancellationToken">An optional cancellation Token.</param>
|
||||
public virtual async Task AddManyAsync<TDocument, TKey>(IEnumerable<TDocument> documents, CancellationToken cancellationToken = default)
|
||||
where TDocument : IDocument<TKey>
|
||||
where TKey : IEquatable<TKey>
|
||||
{
|
||||
@@ -72,12 +82,12 @@ namespace MongoDbGenericRepository.DataAccess.Create
|
||||
{
|
||||
foreach (var group in documents.GroupBy(e => ((IPartitionedDocument)e).PartitionKey))
|
||||
{
|
||||
await HandlePartitioned<TDocument, TKey>(group.FirstOrDefault()).InsertManyAsync(group.ToList());
|
||||
await HandlePartitioned<TDocument, TKey>(group.FirstOrDefault()).InsertManyAsync(group.ToList(), null, cancellationToken);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
await GetCollection<TDocument, TKey>().InsertManyAsync(documents.ToList());
|
||||
await GetCollection<TDocument, TKey>().InsertManyAsync(documents.ToList(), null, cancellationToken);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -11,8 +11,15 @@ using System.Threading.Tasks;
|
||||
|
||||
namespace MongoDbGenericRepository.DataAccess.Read
|
||||
{
|
||||
/// <summary>
|
||||
/// A class to read MongoDb document.
|
||||
/// </summary>
|
||||
public partial class MongoDbReader : DataAccessBase
|
||||
{
|
||||
/// <summary>
|
||||
/// The construct of the MongoDbReader class.
|
||||
/// </summary>
|
||||
/// <param name="mongoDbContext">A <see cref="IMongoDbContext"/> instance.</param>
|
||||
public MongoDbReader(IMongoDbContext mongoDbContext) : base(mongoDbContext)
|
||||
{
|
||||
}
|
||||
@@ -193,7 +200,7 @@ 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
|
||||
/// <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>
|
||||
|
||||
Reference in New Issue
Block a user