From c70727212ee41a69a484ad55ee86691bdb34cc68 Mon Sep 17 00:00:00 2001 From: Sean Garrett Date: Thu, 6 Jul 2023 11:49:45 +0100 Subject: [PATCH] cancellation tokens on repository update methods --- ...aseMongoRepository_Update_ClientSession.cs | 293 ++++- ...aseMongoRepository.Update.ClientSession.cs | 411 +++++-- .../BaseMongoRepository.Update.cs | 1092 +++++++++++------ .../BaseMongoRepository.TKey.Update.cs | 520 +++++--- .../IBaseMongoRepository.TKey.Update.cs | 757 ++++++++++-- 5 files changed, 2332 insertions(+), 741 deletions(-) diff --git a/MongoDbGenericRepository/Abstractions/IBaseMongoRepository_Update_ClientSession.cs b/MongoDbGenericRepository/Abstractions/IBaseMongoRepository_Update_ClientSession.cs index 9e9223b..60dc065 100644 --- a/MongoDbGenericRepository/Abstractions/IBaseMongoRepository_Update_ClientSession.cs +++ b/MongoDbGenericRepository/Abstractions/IBaseMongoRepository_Update_ClientSession.cs @@ -12,6 +12,38 @@ namespace MongoDbGenericRepository.DataAccess.Update /// public interface IBaseMongoRepository_Update_ClientSession { + + /// + /// Updates a document. + /// + /// The type representing a Document. + /// The type of the primary key for a Document. + /// The type of the field to update. + /// The client session. + /// The filter for the update. + /// The field to update. + /// The value of the field. + /// A boolean value indicating success. + bool UpdateOne(IClientSessionHandle session, Expression> filter, Expression> field, TField value) + where TDocument : IDocument + where TKey : IEquatable; + + /// + /// Updates a document. + /// + /// The type representing a Document. + /// The type of the primary key for a Document. + /// The type of the field to update. + /// The client session. + /// The filter for the update. + /// The field to update. + /// The value of the field. + /// The optional cancellation token. + /// A boolean value indicating success. + bool UpdateOne(IClientSessionHandle session, Expression> filter, Expression> field, TField value, CancellationToken cancellationToken) + where TDocument : IDocument + where TKey : IEquatable; + /// /// Updates a document. /// @@ -23,9 +55,8 @@ namespace MongoDbGenericRepository.DataAccess.Update /// The field to update. /// The value of the field. /// The optional partition key. - /// The optional cancellation token. /// A boolean value indicating success. - bool UpdateOne(IClientSessionHandle session, Expression> filter, Expression> field, TField value, string partitionKey = null, CancellationToken cancellationToken = default(CancellationToken)) + bool UpdateOne(IClientSessionHandle session, Expression> filter, Expression> field, TField value, string partitionKey) where TDocument : IDocument where TKey : IEquatable; @@ -42,7 +73,86 @@ namespace MongoDbGenericRepository.DataAccess.Update /// The optional partition key. /// The optional cancellation token. /// A boolean value indicating success. - bool UpdateOne(IClientSessionHandle session, FilterDefinition filter, Expression> field, TField value, string partitionKey = null, CancellationToken cancellationToken = default(CancellationToken)) + bool UpdateOne(IClientSessionHandle session, Expression> filter, Expression> field, TField value, string partitionKey, CancellationToken cancellationToken) + where TDocument : IDocument + where TKey : IEquatable; + + /// + /// Updates a document. + /// + /// The type representing a Document. + /// The type of the primary key for a Document. + /// The type of the field to update. + /// The client session. + /// The filter for the update. + /// The field to update. + /// The value of the field. + /// A boolean value indicating success. + bool UpdateOne(IClientSessionHandle session, FilterDefinition filter, Expression> field, TField value) + where TDocument : IDocument + where TKey : IEquatable; + + /// + /// Updates a document. + /// + /// The type representing a Document. + /// The type of the primary key for a Document. + /// The type of the field to update. + /// The client session. + /// The filter for the update. + /// The field to update. + /// The value of the field. + /// The optional cancellation token. + /// A boolean value indicating success. + bool UpdateOne(IClientSessionHandle session, FilterDefinition filter, Expression> field, TField value, CancellationToken cancellationToken) + where TDocument : IDocument + where TKey : IEquatable; + + /// + /// Updates a document. + /// + /// The type representing a Document. + /// The type of the primary key for a Document. + /// The type of the field to update. + /// The client session. + /// The filter for the update. + /// The field to update. + /// The value of the field. + /// The optional partition key. + /// A boolean value indicating success. + bool UpdateOne(IClientSessionHandle session, FilterDefinition filter, Expression> field, TField value, string partitionKey) + where TDocument : IDocument + where TKey : IEquatable; + + /// + /// Updates a document. + /// + /// The type representing a Document. + /// The type of the primary key for a Document. + /// The type of the field to update. + /// The client session. + /// The filter for the update. + /// The field to update. + /// The value of the field. + /// The optional partition key. + /// The optional cancellation token. + /// A boolean value indicating success. + bool UpdateOne(IClientSessionHandle session, FilterDefinition filter, Expression> field, TField value, string partitionKey, CancellationToken cancellationToken) + where TDocument : IDocument + where TKey : IEquatable; + + /// + /// Updates a document. + /// + /// The type representing a Document. + /// The type of the primary key for a Document. + /// The type of the field to update. + /// The client session. + /// The document to modify. + /// The field to update. + /// The value of the field. + /// A boolean value indicating success. + bool UpdateOne(IClientSessionHandle session, TDocument documentToModify, Expression> field, TField value) where TDocument : IDocument where TKey : IEquatable; @@ -58,7 +168,19 @@ namespace MongoDbGenericRepository.DataAccess.Update /// The value of the field. /// The optional cancellation token. /// A boolean value indicating success. - bool UpdateOne(IClientSessionHandle session, TDocument documentToModify, Expression> field, TField value, CancellationToken cancellationToken = default(CancellationToken)) + bool UpdateOne(IClientSessionHandle session, TDocument documentToModify, Expression> field, TField value, CancellationToken cancellationToken) + where TDocument : IDocument + where TKey : IEquatable; + + /// + /// Updates a document. + /// + /// The type representing a Document. + /// The type of the primary key for a Document. + /// The client session. + /// The document with the modifications you want to persist. + /// A boolean value indicating success. + bool UpdateOne(IClientSessionHandle session, TDocument modifiedDocument) where TDocument : IDocument where TKey : IEquatable; @@ -71,7 +193,20 @@ namespace MongoDbGenericRepository.DataAccess.Update /// The document with the modifications you want to persist. /// The optional cancellation token. /// A boolean value indicating success. - bool UpdateOne(IClientSessionHandle session, TDocument modifiedDocument, CancellationToken cancellationToken = default(CancellationToken)) + bool UpdateOne(IClientSessionHandle session, TDocument modifiedDocument, CancellationToken cancellationToken) + where TDocument : IDocument + where TKey : IEquatable; + + /// + /// Updates a document. + /// + /// The type representing a Document. + /// The type of the primary key for a Document. + /// The client session. + /// The document to modify. + /// The update definition. + /// A boolean value indicating success. + bool UpdateOne(IClientSessionHandle session, TDocument documentToModify, UpdateDefinition update) where TDocument : IDocument where TKey : IEquatable; @@ -85,7 +220,54 @@ namespace MongoDbGenericRepository.DataAccess.Update /// The update definition. /// The optional cancellation token. /// A boolean value indicating success. - bool UpdateOne(IClientSessionHandle session, TDocument documentToModify, UpdateDefinition update, CancellationToken cancellationToken = default(CancellationToken)) + bool UpdateOne(IClientSessionHandle session, TDocument documentToModify, UpdateDefinition update, CancellationToken cancellationToken) + where TDocument : IDocument + where TKey : IEquatable; + + /// + /// Updates a document. + /// + /// The type representing a Document. + /// The type of the primary key for a Document. + /// The type of the field to update. + /// The client session. + /// The filter for the update. + /// The field to update. + /// The value of the field. + /// A boolean value indicating success. + Task UpdateOneAsync(IClientSessionHandle session, Expression> filter, Expression> field, TField value) + where TDocument : IDocument + where TKey : IEquatable; + + /// + /// Updates a document. + /// + /// The type representing a Document. + /// The type of the primary key for a Document. + /// The type of the field to update. + /// The client session. + /// The filter for the update. + /// The field to update. + /// The value of the field. + /// The optional cancellation token. + /// A boolean value indicating success. + Task UpdateOneAsync(IClientSessionHandle session, Expression> filter, Expression> field, TField value, CancellationToken cancellationToken) + where TDocument : IDocument + where TKey : IEquatable; + + /// + /// Updates a document. + /// + /// The type representing a Document. + /// The type of the primary key for a Document. + /// The type of the field to update. + /// The client session. + /// The filter for the update. + /// The field to update. + /// The value of the field. + /// The optional partition key. + /// A boolean value indicating success. + Task UpdateOneAsync(IClientSessionHandle session, Expression> filter, Expression> field, TField value, string partitionKey) where TDocument : IDocument where TKey : IEquatable; @@ -102,7 +284,54 @@ namespace MongoDbGenericRepository.DataAccess.Update /// The optional partition key. /// The optional cancellation token. /// A boolean value indicating success. - Task UpdateOneAsync(IClientSessionHandle session, Expression> filter, Expression> field, TField value, string partitionKey = null, CancellationToken cancellationToken = default(CancellationToken)) + Task UpdateOneAsync(IClientSessionHandle session, Expression> filter, Expression> field, TField value, string partitionKey, CancellationToken cancellationToken) + where TDocument : IDocument + where TKey : IEquatable; + + /// + /// Updates a document. + /// + /// The type representing a Document. + /// The type of the primary key for a Document. + /// The type of the field to update. + /// The client session. + /// The filter for the update. + /// The field to update. + /// The value of the field. + /// + Task UpdateOneAsync(IClientSessionHandle session, FilterDefinition filter, Expression> field, TField value) + where TDocument : IDocument + where TKey : IEquatable; + + /// + /// Updates a document. + /// + /// The type representing a Document. + /// The type of the primary key for a Document. + /// The type of the field to update. + /// The client session. + /// The filter for the update. + /// The field to update. + /// The value of the field. + /// The optional cancellation token. + /// + Task UpdateOneAsync(IClientSessionHandle session, FilterDefinition filter, Expression> field, TField value, CancellationToken cancellationToken) + where TDocument : IDocument + where TKey : IEquatable; + + /// + /// Updates a document. + /// + /// The type representing a Document. + /// The type of the primary key for a Document. + /// The type of the field to update. + /// The client session. + /// The filter for the update. + /// The field to update. + /// The value of the field. + /// The optional partition key. + /// + Task UpdateOneAsync(IClientSessionHandle session, FilterDefinition filter, Expression> field, TField value, string partitionKey) where TDocument : IDocument where TKey : IEquatable; @@ -119,7 +348,7 @@ namespace MongoDbGenericRepository.DataAccess.Update /// The optional partition key. /// The optional cancellation token. /// - Task UpdateOneAsync(IClientSessionHandle session, FilterDefinition filter, Expression> field, TField value, string partitionKey = null, CancellationToken cancellationToken = default(CancellationToken)) + Task UpdateOneAsync(IClientSessionHandle session, FilterDefinition filter, Expression> field, TField value, string partitionKey, CancellationToken cancellationToken) where TDocument : IDocument where TKey : IEquatable; @@ -129,13 +358,40 @@ namespace MongoDbGenericRepository.DataAccess.Update /// The type representing a Document. /// The type of the primary key for a Document. /// The type of the field to update. - /// The client session. + /// The client session. + /// The document to modify. + /// The field to update. + /// The value of the field. + /// A boolean value indicating success. + Task UpdateOneAsync(IClientSessionHandle session, TDocument documentToModify, Expression> field, TField value) + where TDocument : IDocument + where TKey : IEquatable; + + /// + /// Updates a document. + /// + /// The type representing a Document. + /// The type of the primary key for a Document. + /// The type of the field to update. + /// The client session. /// The document to modify. /// The field to update. /// The value of the field. /// The optional cancellation token. /// A boolean value indicating success. - Task UpdateOneAsync(IClientSessionHandle session, TDocument documentToModify, Expression> field, TField value, CancellationToken cancellationToken = default(CancellationToken)) + Task UpdateOneAsync(IClientSessionHandle session, TDocument documentToModify, Expression> field, TField value, CancellationToken cancellationToken) + where TDocument : IDocument + where TKey : IEquatable; + + /// + /// Updates a document. + /// + /// The type representing a Document. + /// The type of the primary key for a Document. + /// The client session. + /// The document with the modifications you want to persist. + /// A boolean value indicating success. + Task UpdateOneAsync(IClientSessionHandle session, TDocument modifiedDocument) where TDocument : IDocument where TKey : IEquatable; @@ -148,7 +404,20 @@ namespace MongoDbGenericRepository.DataAccess.Update /// The document with the modifications you want to persist. /// The optional cancellation token. /// A boolean value indicating success. - Task UpdateOneAsync(IClientSessionHandle session, TDocument modifiedDocument, CancellationToken cancellationToken = default(CancellationToken)) + Task UpdateOneAsync(IClientSessionHandle session, TDocument modifiedDocument, CancellationToken cancellationToken) + where TDocument : IDocument + where TKey : IEquatable; + + /// + /// Updates a document. + /// + /// The type representing a Document. + /// The type of the primary key for a Document. + /// The client session. + /// The document to modify. + /// The update definition. + /// A boolean value indicating success. + Task UpdateOneAsync(IClientSessionHandle session, TDocument documentToModify, UpdateDefinition update) where TDocument : IDocument where TKey : IEquatable; @@ -162,7 +431,7 @@ namespace MongoDbGenericRepository.DataAccess.Update /// The update definition. /// The optional cancellation token. /// A boolean value indicating success. - Task UpdateOneAsync(IClientSessionHandle session, TDocument documentToModify, UpdateDefinition update, CancellationToken cancellationToken = default(CancellationToken)) + Task UpdateOneAsync(IClientSessionHandle session, TDocument documentToModify, UpdateDefinition update, CancellationToken cancellationToken) where TDocument : IDocument where TKey : IEquatable; } diff --git a/MongoDbGenericRepository/BaseMongoRepository.Update.ClientSession.cs b/MongoDbGenericRepository/BaseMongoRepository.Update.ClientSession.cs index aa661b0..ef4b774 100644 --- a/MongoDbGenericRepository/BaseMongoRepository.Update.ClientSession.cs +++ b/MongoDbGenericRepository/BaseMongoRepository.Update.ClientSession.cs @@ -1,197 +1,350 @@ -using MongoDB.Driver; -using MongoDbGenericRepository.DataAccess.Update; -using MongoDbGenericRepository.Models; -using System; +using System; using System.Linq.Expressions; using System.Threading; using System.Threading.Tasks; +using MongoDB.Driver; +using MongoDbGenericRepository.DataAccess.Update; +using MongoDbGenericRepository.Models; namespace MongoDbGenericRepository { public abstract partial class BaseMongoRepository : IBaseMongoRepository_Update_ClientSession { - /// - /// Updates a document. - /// - /// The type representing a Document. - /// The type of the primary key for a Document. - /// The client session. - /// The document with the modifications you want to persist. - /// The optional cancellation token. - /// A boolean value indicating success. - public virtual async Task UpdateOneAsync(IClientSessionHandle session, TDocument modifiedDocument, CancellationToken cancellationToken = default(CancellationToken)) + /// + public virtual async Task UpdateOneAsync(IClientSessionHandle session, TDocument modifiedDocument) + where TDocument : IDocument + where TKey : IEquatable + { + return await UpdateOneAsync(session, modifiedDocument, CancellationToken.None); + } + + /// + public virtual async Task UpdateOneAsync( + IClientSessionHandle session, + TDocument modifiedDocument, + CancellationToken cancellationToken) where TDocument : IDocument where TKey : IEquatable { return await MongoDbUpdater.UpdateOneAsync(session, modifiedDocument, cancellationToken); } - /// - /// Updates a document. - /// - /// The type representing a Document. - /// The type of the primary key for a Document. - /// The client session. - /// The document with the modifications you want to persist. - /// The optional cancellation token. - /// A boolean value indicating success. - public virtual bool UpdateOne(IClientSessionHandle session, TDocument modifiedDocument, CancellationToken cancellationToken = default(CancellationToken)) + /// + public virtual bool UpdateOne(IClientSessionHandle session, TDocument modifiedDocument) + where TDocument : IDocument + where TKey : IEquatable + { + return UpdateOne(session, modifiedDocument, CancellationToken.None); + } + + /// + public virtual bool UpdateOne(IClientSessionHandle session, TDocument modifiedDocument, CancellationToken cancellationToken) where TDocument : IDocument where TKey : IEquatable { return MongoDbUpdater.UpdateOne(session, modifiedDocument, cancellationToken); } - /// - /// Updates a document. - /// - /// The type representing a Document. - /// The type of the primary key for a Document. - /// The client session. - /// The document to modify. - /// The update definition. - /// The optional cancellation token. - /// A boolean value indicating success. - public virtual async Task UpdateOneAsync(IClientSessionHandle session, TDocument documentToModify, UpdateDefinition update, CancellationToken cancellationToken = default(CancellationToken)) + /// + public virtual async Task UpdateOneAsync( + IClientSessionHandle session, + TDocument documentToModify, + UpdateDefinition update) + where TDocument : IDocument + where TKey : IEquatable + { + return await UpdateOneAsync(session, documentToModify, update, CancellationToken.None); + } + + /// + public virtual async Task UpdateOneAsync( + IClientSessionHandle session, + TDocument documentToModify, + UpdateDefinition update, + CancellationToken cancellationToken) where TDocument : IDocument where TKey : IEquatable { return await MongoDbUpdater.UpdateOneAsync(session, documentToModify, update, cancellationToken); } - /// - /// Updates a document. - /// - /// The type representing a Document. - /// The type of the primary key for a Document. - /// The client session. - /// The document to modify. - /// The update definition. - /// The optional cancellation token. - /// A boolean value indicating success. - public virtual bool UpdateOne(IClientSessionHandle session, TDocument documentToModify, UpdateDefinition update, CancellationToken cancellationToken = default(CancellationToken)) + /// + public virtual bool UpdateOne(IClientSessionHandle session, TDocument documentToModify, UpdateDefinition update) + where TDocument : IDocument + where TKey : IEquatable + { + return UpdateOne(session, documentToModify, update, CancellationToken.None); + } + + /// + public virtual bool UpdateOne( + IClientSessionHandle session, + TDocument documentToModify, + UpdateDefinition update, + CancellationToken cancellationToken) where TDocument : IDocument where TKey : IEquatable { return MongoDbUpdater.UpdateOne(session, documentToModify, update, cancellationToken); } - /// - /// Updates a document. - /// - /// The type representing a Document. - /// The type of the primary key for a Document. - /// The type of the field to update. - /// The client session. - /// The document to modify. - /// The field to update. - /// The value of the field. - /// The optional cancellation token. - /// A boolean value indicating success. - public virtual async Task UpdateOneAsync(IClientSessionHandle session, TDocument documentToModify, Expression> field, TField value, CancellationToken cancellationToken = default(CancellationToken)) + /// + public virtual async Task UpdateOneAsync( + IClientSessionHandle session, + TDocument documentToModify, + Expression> field, + TField value) + where TDocument : IDocument + where TKey : IEquatable + { + return await UpdateOneAsync(session, documentToModify, field, value, CancellationToken.None); + } + + /// + public virtual async Task UpdateOneAsync( + IClientSessionHandle session, + TDocument documentToModify, + Expression> field, + TField value, + CancellationToken cancellationToken) where TDocument : IDocument where TKey : IEquatable { return await MongoDbUpdater.UpdateOneAsync(session, documentToModify, field, value, cancellationToken); } - /// - /// Updates a document. - /// - /// The type representing a Document. - /// The type of the primary key for a Document. - /// The type of the field to update. - /// The client session. - /// The document to modify. - /// The field to update. - /// The value of the field. - /// The optional cancellation token. - /// A boolean value indicating success. - public virtual bool UpdateOne(IClientSessionHandle session, TDocument documentToModify, Expression> field, TField value, CancellationToken cancellationToken = default(CancellationToken)) + /// + public virtual bool UpdateOne( + IClientSessionHandle session, + TDocument documentToModify, + Expression> field, + TField value) + where TDocument : IDocument + where TKey : IEquatable + { + return UpdateOne(session, documentToModify, field, value, CancellationToken.None); + } + + /// + public virtual bool UpdateOne( + IClientSessionHandle session, + TDocument documentToModify, + Expression> field, + TField value, + CancellationToken cancellationToken) where TDocument : IDocument where TKey : IEquatable { return MongoDbUpdater.UpdateOne(session, documentToModify, field, value, cancellationToken); } - /// - /// Updates a document. - /// - /// The type representing a Document. - /// The type of the primary key for a Document. - /// The type of the field to update. - /// The client session. - /// The filter for the update. - /// The field to update. - /// The value of the field. - /// The optional partition key. - /// The optional cancellation token. - /// A boolean value indicating success. - public virtual async Task UpdateOneAsync(IClientSessionHandle session, FilterDefinition filter, Expression> field, TField value, string partitionKey = null, CancellationToken cancellationToken = default(CancellationToken)) + /// + public virtual async Task UpdateOneAsync( + IClientSessionHandle session, + FilterDefinition filter, + Expression> field, + TField value) + where TDocument : IDocument + where TKey : IEquatable + { + return await UpdateOneAsync(session, filter, field, value, null, CancellationToken.None); + } + + /// + public virtual async Task UpdateOneAsync( + IClientSessionHandle session, + FilterDefinition filter, + Expression> field, + TField value, + CancellationToken cancellationToken) + where TDocument : IDocument + where TKey : IEquatable + { + return await UpdateOneAsync(session, filter, field, value, null, cancellationToken); + } + + /// + public virtual async Task UpdateOneAsync( + IClientSessionHandle session, + FilterDefinition filter, + Expression> field, + TField value, + string partitionKey) + where TDocument : IDocument + where TKey : IEquatable + { + return await UpdateOneAsync(session, filter, field, value, partitionKey, CancellationToken.None); + } + + /// + public virtual async Task UpdateOneAsync( + IClientSessionHandle session, + FilterDefinition filter, + Expression> field, + TField value, + string partitionKey, + CancellationToken cancellationToken) where TDocument : IDocument where TKey : IEquatable { return await MongoDbUpdater.UpdateOneAsync(session, filter, field, value, partitionKey, cancellationToken); } - /// - /// Updates a document. - /// - /// The type representing a Document. - /// The type of the primary key for a Document. - /// The type of the field to update. - /// The client session. - /// The filter for the update. - /// The field to update. - /// The value of the field. - /// The optional partition key. - /// The optional cancellation token. - /// A boolean value indicating success. - public virtual async Task UpdateOneAsync(IClientSessionHandle session, Expression> filter, Expression> field, TField value, string partitionKey = null, CancellationToken cancellationToken = default(CancellationToken)) + /// + public virtual async Task UpdateOneAsync( + IClientSessionHandle session, + Expression> filter, + Expression> field, + TField value) + where TDocument : IDocument + where TKey : IEquatable + { + return await UpdateOneAsync(session, filter, field, value, null, CancellationToken.None); + } + + /// + public virtual async Task UpdateOneAsync( + IClientSessionHandle session, + Expression> filter, + Expression> field, + TField value, + CancellationToken cancellationToken) + where TDocument : IDocument + where TKey : IEquatable + { + return await UpdateOneAsync(session, filter, field, value, null, cancellationToken); + } + + /// + public virtual async Task UpdateOneAsync( + IClientSessionHandle session, + Expression> filter, + Expression> field, + TField value, + string partitionKey) + where TDocument : IDocument + where TKey : IEquatable + { + return await UpdateOneAsync(session, filter, field, value, partitionKey, CancellationToken.None); + } + + /// + public virtual async Task UpdateOneAsync( + IClientSessionHandle session, + Expression> filter, + Expression> field, + TField value, + string partitionKey, + CancellationToken cancellationToken) where TDocument : IDocument where TKey : IEquatable { return await MongoDbUpdater.UpdateOneAsync(session, filter, field, value, partitionKey, cancellationToken); } - /// - /// Updates a document. - /// - /// The type representing a Document. - /// The type of the primary key for a Document. - /// The type of the field to update. - /// The client session. - /// The filter for the update. - /// The field to update. - /// The value of the field. - /// The optional partition key. - /// The optional cancellation token. - /// A boolean value indicating success. - public virtual bool UpdateOne(IClientSessionHandle session, FilterDefinition filter, Expression> field, TField value, string partitionKey = null, CancellationToken cancellationToken = default(CancellationToken)) + /// + public virtual bool UpdateOne( + IClientSessionHandle session, + FilterDefinition filter, + Expression> field, + TField value) + where TDocument : IDocument + where TKey : IEquatable + { + return UpdateOne(session, filter, field, value, null, CancellationToken.None); + } + + + /// + public virtual bool UpdateOne( + IClientSessionHandle session, + FilterDefinition filter, + Expression> field, + TField value, + CancellationToken cancellationToken) + where TDocument : IDocument + where TKey : IEquatable + { + return UpdateOne(session, filter, field, value, null, cancellationToken); + } + + /// + public virtual bool UpdateOne( + IClientSessionHandle session, + FilterDefinition filter, + Expression> field, + TField value, + string partitionKey) + where TDocument : IDocument + where TKey : IEquatable + { + return UpdateOne(session, filter, field, value, partitionKey, CancellationToken.None); + } + + /// + public virtual bool UpdateOne( + IClientSessionHandle session, + FilterDefinition filter, + Expression> field, + TField value, + string partitionKey, + CancellationToken cancellationToken) where TDocument : IDocument where TKey : IEquatable { return MongoDbUpdater.UpdateOne(session, filter, field, value, partitionKey, cancellationToken); } - /// - /// Updates a document. - /// - /// The type representing a Document. - /// The type of the primary key for a Document. - /// The type of the field to update. - /// The client session. - /// The filter for the update. - /// The field to update. - /// The value of the field. - /// The optional partition key. - /// The optional cancellation token. - /// A boolean value indicating success. - public virtual bool UpdateOne(IClientSessionHandle session, Expression> filter, Expression> field, TField value, string partitionKey = null, CancellationToken cancellationToken = default(CancellationToken)) + /// + public virtual bool UpdateOne( + IClientSessionHandle session, + Expression> filter, + Expression> field, + TField value) + where TDocument : IDocument + where TKey : IEquatable + { + return UpdateOne(session, Builders.Filter.Where(filter), field, value, null, CancellationToken.None); + } + + /// + public virtual bool UpdateOne( + IClientSessionHandle session, + Expression> filter, + Expression> field, + TField value, + CancellationToken cancellationToken) + where TDocument : IDocument + where TKey : IEquatable + { + return UpdateOne(session, Builders.Filter.Where(filter), field, value, null, cancellationToken); + } + + /// + public virtual bool UpdateOne( + IClientSessionHandle session, + Expression> filter, + Expression> field, + TField value, + string partitionKey) + where TDocument : IDocument + where TKey : IEquatable + { + return UpdateOne(session, Builders.Filter.Where(filter), field, value, partitionKey, CancellationToken.None); + } + + /// + public virtual bool UpdateOne( + IClientSessionHandle session, + Expression> filter, + Expression> field, + TField value, + string partitionKey, + CancellationToken cancellationToken) where TDocument : IDocument where TKey : IEquatable { return UpdateOne(session, Builders.Filter.Where(filter), field, value, partitionKey, cancellationToken); } } -} +} \ No newline at end of file diff --git a/MongoDbGenericRepository/BaseMongoRepository.Update.cs b/MongoDbGenericRepository/BaseMongoRepository.Update.cs index 6e96164..3d4ccb7 100644 --- a/MongoDbGenericRepository/BaseMongoRepository.Update.cs +++ b/MongoDbGenericRepository/BaseMongoRepository.Update.cs @@ -3,6 +3,7 @@ using MongoDbGenericRepository.DataAccess.Update; using MongoDbGenericRepository.Models; using System; using System.Linq.Expressions; +using System.Threading; using System.Threading.Tasks; namespace MongoDbGenericRepository @@ -39,538 +40,911 @@ namespace MongoDbGenericRepository #region Update - /// - /// Asynchronously Updates a document. - /// - /// The type representing a Document. - /// The document with the modifications you want to persist. - public virtual async Task UpdateOneAsync(TDocument modifiedDocument) where TDocument : IDocument + /// + public virtual async Task UpdateOneAsync(TDocument modifiedDocument) + where TDocument : IDocument { - return await MongoDbUpdater.UpdateOneAsync(modifiedDocument); + return await UpdateOneAsync(modifiedDocument, CancellationToken.None); } - /// - /// Updates a document. - /// - /// The type representing a Document. - /// The document with the modifications you want to persist. - public virtual bool UpdateOne(TDocument modifiedDocument) where TDocument : IDocument + /// + public virtual async Task UpdateOneAsync(TDocument modifiedDocument, CancellationToken cancellationToken) + where TDocument : IDocument { - return MongoDbUpdater.UpdateOne(modifiedDocument); + return await MongoDbUpdater.UpdateOneAsync(modifiedDocument, cancellationToken); } - /// - /// Takes a document you want to modify and applies the update you have defined in MongoDb. - /// - /// The type representing a Document. - /// The document you want to modify. - /// The update definition for the document. + /// + public virtual bool UpdateOne(TDocument modifiedDocument) + where TDocument : IDocument + { + return UpdateOne(modifiedDocument, CancellationToken.None); + } + + /// + public virtual bool UpdateOne(TDocument modifiedDocument, CancellationToken cancellationToken) + where TDocument : IDocument + { + return MongoDbUpdater.UpdateOne(modifiedDocument, cancellationToken); + } + + /// public virtual async Task UpdateOneAsync(TDocument documentToModify, UpdateDefinition update) where TDocument : IDocument { - return await MongoDbUpdater.UpdateOneAsync(documentToModify, update); - + return await UpdateOneAsync(documentToModify, update, CancellationToken.None); } - /// - /// Takes a document you want to modify and applies the update you have defined in MongoDb. - /// - /// The type representing a Document. - /// The document you want to modify. - /// The update definition for the document. + /// + public virtual async Task UpdateOneAsync(TDocument documentToModify, UpdateDefinition update, CancellationToken cancellationToken) + where TDocument : IDocument + { + return await MongoDbUpdater.UpdateOneAsync(documentToModify, update, cancellationToken); + } + + /// public virtual bool UpdateOne(TDocument documentToModify, UpdateDefinition update) where TDocument : IDocument { - return MongoDbUpdater.UpdateOne(documentToModify, update); + return UpdateOne(documentToModify, update, CancellationToken.None); } - /// - /// Updates the property field with the given value update a property field in entities. - /// - /// The type representing a Document. - /// The type of the field. - /// The document you want to modify. - /// The field selector. - /// The new value of the property field. + /// + public virtual bool UpdateOne(TDocument documentToModify, UpdateDefinition update, CancellationToken cancellationToken) + where TDocument : IDocument + { + return MongoDbUpdater.UpdateOne(documentToModify, update, cancellationToken); + } + + /// public virtual bool UpdateOne(TDocument documentToModify, Expression> field, TField value) where TDocument : IDocument { - return MongoDbUpdater.UpdateOne(documentToModify, field, value); + return UpdateOne(documentToModify, field, value, CancellationToken.None); } - /// - /// Updates the property field with the given value update a property field in entities. - /// - /// The type representing a Document. - /// The type of the field. - /// The document you want to modify. - /// The field selector. - /// The new value of the property field. + /// + public virtual bool UpdateOne(TDocument documentToModify, Expression> field, TField value, CancellationToken cancellationToken) + where TDocument : IDocument + { + return MongoDbUpdater.UpdateOne(documentToModify, field, value, cancellationToken); + } + + /// public virtual async Task UpdateOneAsync(TDocument documentToModify, Expression> field, TField value) where TDocument : IDocument { - return await MongoDbUpdater.UpdateOneAsync(documentToModify, field, value); + return await UpdateOneAsync(documentToModify, field, value, CancellationToken.None); } - - /// - /// Updates the property field with the given value update a property field in entities. - /// - /// The type representing a Document. - /// The type of the field. - /// The document filter. - /// The field selector. - /// The new value of the property field. - /// The value of the partition key. - public virtual bool UpdateOne(FilterDefinition filter, Expression> field, TField value, string partitionKey = null) + /// + public virtual async Task UpdateOneAsync(TDocument documentToModify, Expression> field, TField value, CancellationToken cancellationToken) where TDocument : IDocument { - return MongoDbUpdater.UpdateOne(filter, field, value, partitionKey); + return await MongoDbUpdater.UpdateOneAsync(documentToModify, field, value, cancellationToken); } - /// - /// For the entity selected by the filter, updates the property field with the given value. - /// - /// The type representing a Document. - /// The type of the field. - /// The document filter. - /// The field selector. - /// The new value of the property field. - /// The partition key for the document. - public virtual bool UpdateOne(Expression> filter, Expression> field, TField value, string partitionKey = null) + /// + public virtual bool UpdateOne(FilterDefinition filter, Expression> field, TField value) where TDocument : IDocument { - return MongoDbUpdater.UpdateOne(filter, field, value, partitionKey); + return UpdateOne(filter, field, value, null, CancellationToken.None); } - /// - /// Updates the property field with the given value update a property field in entities. - /// - /// The type representing a Document. - /// The type of the field. - /// The document filter. - /// The field selector. - /// The new value of the property field. - /// The value of the partition key. - public virtual async Task UpdateOneAsync(FilterDefinition filter, Expression> field, TField value, string partitionKey = null) + /// + public virtual bool UpdateOne(FilterDefinition filter, Expression> field, TField value, CancellationToken cancellationToken) where TDocument : IDocument { - return await MongoDbUpdater.UpdateOneAsync(filter, field, value, partitionKey); + return UpdateOne(filter, field, value, null, cancellationToken); } - /// - /// For the entity selected by the filter, updates the property field with the given value. - /// - /// The type representing a Document. - /// The type of the field. - /// The document filter. - /// The field selector. - /// The new value of the property field. - /// The partition key for the document. - public virtual async Task UpdateOneAsync(Expression> filter, Expression> field, TField value, string partitionKey = null) + /// + public virtual bool UpdateOne(FilterDefinition filter, Expression> field, TField value, string partitionKey) where TDocument : IDocument { - return await MongoDbUpdater.UpdateOneAsync(filter, field, value, partitionKey); + return UpdateOne(filter, field, value, partitionKey, CancellationToken.None); } - /// - /// For the entities selected by the filter, updates the property field with the given value. - /// - /// The type representing a Document. - /// The type of the field. - /// The document filter. - /// The field selector. - /// The new value of the property field. - /// The value of the partition key. - public virtual async Task UpdateManyAsync(FilterDefinition filter, Expression> field, TField value, string partitionKey = null) + /// + public virtual bool UpdateOne(FilterDefinition filter, Expression> field, TField value, string partitionKey, CancellationToken cancellationToken) where TDocument : IDocument { - return await MongoDbUpdater.UpdateManyAsync(filter, field, value, partitionKey); + return MongoDbUpdater.UpdateOne(filter, field, value, partitionKey, cancellationToken); } - /// - /// For the entities selected by the filter, updates the property field with the given value. - /// - /// The type representing a Document. - /// The type of the field. - /// The document filter. - /// The field selector. - /// The new value of the property field. - /// The value of the partition key. - public virtual async Task UpdateManyAsync(Expression> filter, Expression> field, TField value, string partitionKey = null) + /// + public virtual bool UpdateOne(Expression> filter, Expression> field, TField value) where TDocument : IDocument { - return await MongoDbUpdater.UpdateManyAsync(filter, field, value, partitionKey); + return UpdateOne(filter, field, value, null, CancellationToken.None); } - /// - /// For the entities selected by the filter, applies the update you have defined in MongoDb. - /// - /// The type representing a Document. - /// The document filter. - /// The update definition to apply. - /// The value of the partition key. - public virtual async Task UpdateManyAsync(FilterDefinition filter, UpdateDefinition updateDefinition, string partitionKey = null) + /// + public virtual bool UpdateOne(Expression> filter, Expression> field, TField value, CancellationToken cancellationToken) where TDocument : IDocument { - return await MongoDbUpdater.UpdateManyAsync(filter, updateDefinition, partitionKey); + return UpdateOne(filter, field, value, null, cancellationToken); } - /// - /// For the entities selected by the filter, applies the update you have defined in MongoDb. - /// - /// The type representing a Document. - /// The document filter. - /// The update definition to apply. - /// The value of the partition key. - public async Task UpdateManyAsync(Expression> filter, UpdateDefinition updateDefinition, string partitionKey = null) + /// + public virtual bool UpdateOne(Expression> filter, Expression> field, TField value, string partitionKey) where TDocument : IDocument { - return await MongoDbUpdater.UpdateManyAsync(filter, updateDefinition, partitionKey); + return UpdateOne(filter, field, value, partitionKey, CancellationToken.None); } - /// - /// For the entities selected by the filter, updates the property field with the given value. - /// - /// The type representing a Document. - /// The type of the field. - /// The document filter. - /// The field selector. - /// The new value of the property field. - /// The value of the partition key. - public virtual long UpdateMany(FilterDefinition filter, Expression> field, TField value, string partitionKey = null) + /// + public virtual bool UpdateOne(Expression> filter, Expression> field, TField value, string partitionKey, CancellationToken cancellationToken) where TDocument : IDocument { - return MongoDbUpdater.UpdateMany(filter, field, value, partitionKey); + return MongoDbUpdater.UpdateOne(filter, field, value, partitionKey, cancellationToken); } - /// - /// For the entities selected by the filter, updates the property field with the given value. - /// - /// The type representing a Document. - /// The type of the field. - /// The document filter. - /// The field selector. - /// The new value of the property field. - /// The value of the partition key. - public virtual long UpdateMany(Expression> filter, Expression> field, TField value, string partitionKey = null) + /// + public virtual async Task UpdateOneAsync(FilterDefinition filter, Expression> field, TField value) where TDocument : IDocument { - return MongoDbUpdater.UpdateMany(filter, field, value, partitionKey); + return await UpdateOneAsync(filter, field, value, null, CancellationToken.None); } - /// - /// For the entities selected by the filter, applies the update you have defined in MongoDb. - /// - /// The type representing a Document. - /// The document filter. - /// The update definition to apply. - /// The value of the partition key. - public virtual long UpdateMany(FilterDefinition filter, UpdateDefinition updateDefinition, string partitionKey = null) + /// + public virtual async Task UpdateOneAsync(FilterDefinition filter, Expression> field, TField value, CancellationToken cancellationToken) where TDocument : IDocument { - return MongoDbUpdater.UpdateMany(filter, updateDefinition, partitionKey); + return await UpdateOneAsync(filter, field, value, null, cancellationToken); } - /// - /// For the entities selected by the filter, applies the update you have defined in MongoDb. - /// - /// The type representing a Document. - /// The document filter. - /// The update definition to apply. - /// The value of the partition key. - public long UpdateMany(Expression> filter, UpdateDefinition updateDefinition, string partitionKey = null) + /// + public virtual async Task UpdateOneAsync(FilterDefinition filter, Expression> field, TField value, string partitionKey) where TDocument : IDocument { - return MongoDbUpdater.UpdateMany(filter, updateDefinition, partitionKey); + return await UpdateOneAsync(filter, field, value, partitionKey, CancellationToken.None); + } + + /// + public virtual async Task UpdateOneAsync(FilterDefinition filter, Expression> field, TField value, string partitionKey, CancellationToken cancellationToken) + where TDocument : IDocument + { + return await MongoDbUpdater.UpdateOneAsync(filter, field, value, partitionKey, cancellationToken); + } + + /// + public virtual async Task UpdateOneAsync(Expression> filter, Expression> field, TField value) + where TDocument : IDocument + { + return await UpdateOneAsync(filter, field, value, null, CancellationToken.None); + } + + /// + public virtual async Task UpdateOneAsync(Expression> filter, Expression> field, TField value, CancellationToken cancellationToken) + where TDocument : IDocument + { + return await UpdateOneAsync(filter, field, value, null, cancellationToken); + } + + /// + public virtual async Task UpdateOneAsync(Expression> filter, Expression> field, TField value, string partitionKey) + where TDocument : IDocument + { + return await UpdateOneAsync(filter, field, value, partitionKey, CancellationToken.None); + } + + /// + public virtual async Task UpdateOneAsync(Expression> filter, Expression> field, TField value, string partitionKey, CancellationToken cancellationToken) + where TDocument : IDocument + { + return await MongoDbUpdater.UpdateOneAsync(filter, field, value, partitionKey, cancellationToken); + } + + /// + public virtual async Task UpdateManyAsync(FilterDefinition filter, Expression> field, TField value) + where TDocument : IDocument + { + return await UpdateManyAsync(filter, field, value, null, CancellationToken.None); + } + + /// + public virtual async Task UpdateManyAsync(FilterDefinition filter, Expression> field, TField value, CancellationToken cancellationToken) + where TDocument : IDocument + { + return await UpdateManyAsync(filter, field, value, null, cancellationToken); + } + + /// + public virtual async Task UpdateManyAsync(FilterDefinition filter, Expression> field, TField value, string partitionKey) + where TDocument : IDocument + { + return await UpdateManyAsync(filter, field, value, partitionKey, CancellationToken.None); + } + + /// + public virtual async Task UpdateManyAsync(FilterDefinition filter, Expression> field, TField value, string partitionKey, CancellationToken cancellationToken) + where TDocument : IDocument + { + return await MongoDbUpdater.UpdateManyAsync(filter, field, value, partitionKey, cancellationToken); + } + + /// + public virtual async Task UpdateManyAsync(Expression> filter, Expression> field, TField value) + where TDocument : IDocument + { + return await UpdateManyAsync(filter, field, value, null, CancellationToken.None); + } + + /// + public virtual async Task UpdateManyAsync(Expression> filter, Expression> field, TField value, CancellationToken cancellationToken) + where TDocument : IDocument + { + return await UpdateManyAsync(filter, field, value, null, cancellationToken); + } + + + /// + public virtual async Task UpdateManyAsync(Expression> filter, Expression> field, TField value, string partitionKey) + where TDocument : IDocument + { + return await UpdateManyAsync(filter, field, value, partitionKey, CancellationToken.None); + } + + /// + public virtual async Task UpdateManyAsync(Expression> filter, Expression> field, TField value, string partitionKey, CancellationToken cancellationToken) + where TDocument : IDocument + { + return await MongoDbUpdater.UpdateManyAsync(filter, field, value, partitionKey, cancellationToken); + } + + /// + public virtual async Task UpdateManyAsync(FilterDefinition filter, UpdateDefinition updateDefinition) + where TDocument : IDocument + { + return await UpdateManyAsync(filter, updateDefinition, null, CancellationToken.None); + } + + /// + public virtual async Task UpdateManyAsync(FilterDefinition filter, UpdateDefinition updateDefinition, CancellationToken cancellationToken) + where TDocument : IDocument + { + return await UpdateManyAsync(filter, updateDefinition, null, cancellationToken); + } + + /// + public virtual async Task UpdateManyAsync(FilterDefinition filter, UpdateDefinition updateDefinition, string partitionKey) + where TDocument : IDocument + { + return await UpdateManyAsync(filter, updateDefinition, partitionKey, CancellationToken.None); + } + + /// + public virtual async Task UpdateManyAsync(FilterDefinition filter, UpdateDefinition updateDefinition, string partitionKey, CancellationToken cancellationToken) + where TDocument : IDocument + { + return await MongoDbUpdater.UpdateManyAsync(filter, updateDefinition, partitionKey, cancellationToken); + } + + /// + public async Task UpdateManyAsync(Expression> filter, UpdateDefinition updateDefinition) + where TDocument : IDocument + { + return await UpdateManyAsync(filter, updateDefinition, null, CancellationToken.None); + } + + /// + public async Task UpdateManyAsync(Expression> filter, UpdateDefinition updateDefinition, CancellationToken cancellationToken) + where TDocument : IDocument + { + return await UpdateManyAsync(filter, updateDefinition, null, cancellationToken); + } + + /// + public async Task UpdateManyAsync(Expression> filter, UpdateDefinition updateDefinition, string partitionKey) + where TDocument : IDocument + { + return await UpdateManyAsync(filter, updateDefinition, partitionKey, CancellationToken.None); + } + + /// + public async Task UpdateManyAsync(Expression> filter, UpdateDefinition updateDefinition, string partitionKey, CancellationToken cancellationToken) + where TDocument : IDocument + { + return await MongoDbUpdater.UpdateManyAsync(filter, updateDefinition, partitionKey, cancellationToken); + } + + /// + public virtual long UpdateMany(FilterDefinition filter, Expression> field, TField value) + where TDocument : IDocument + { + return UpdateMany(filter, field, value, null, CancellationToken.None); + } + + /// + public virtual long UpdateMany(FilterDefinition filter, Expression> field, TField value, CancellationToken cancellationToken) + where TDocument : IDocument + { + return UpdateMany(filter, field, value, null, cancellationToken); + } + + /// + public virtual long UpdateMany(FilterDefinition filter, Expression> field, TField value, string partitionKey) + where TDocument : IDocument + { + return UpdateMany(filter, field, value, partitionKey, CancellationToken.None); + } + + /// + public virtual long UpdateMany(FilterDefinition filter, Expression> field, TField value, string partitionKey, CancellationToken cancellationToken) + where TDocument : IDocument + { + return MongoDbUpdater.UpdateMany(filter, field, value, partitionKey, cancellationToken); + } + + /// + public virtual long UpdateMany(Expression> filter, Expression> field, TField value) + where TDocument : IDocument + { + return UpdateMany(filter, field, value, null, CancellationToken.None); + } + + /// + public virtual long UpdateMany(Expression> filter, Expression> field, TField value, CancellationToken cancellationToken) + where TDocument : IDocument + { + return UpdateMany(filter, field, value, null, cancellationToken); + } + + /// + public virtual long UpdateMany(Expression> filter, Expression> field, TField value, string partitionKey) + where TDocument : IDocument + { + return UpdateMany(filter, field, value, partitionKey, CancellationToken.None); + } + + /// + public virtual long UpdateMany(Expression> filter, Expression> field, TField value, string partitionKey, CancellationToken cancellationToken) + where TDocument : IDocument + { + return MongoDbUpdater.UpdateMany(filter, field, value, partitionKey, cancellationToken); + } + + /// + public virtual long UpdateMany(FilterDefinition filter, UpdateDefinition updateDefinition) + where TDocument : IDocument + { + return UpdateMany(filter, updateDefinition, null, CancellationToken.None); + } + + /// + public virtual long UpdateMany(FilterDefinition filter, UpdateDefinition updateDefinition, CancellationToken cancellationToken) + where TDocument : IDocument + { + return UpdateMany(filter, updateDefinition, null, cancellationToken); + } + + /// + public virtual long UpdateMany(FilterDefinition filter, UpdateDefinition updateDefinition, string partitionKey) + where TDocument : IDocument + { + return UpdateMany(filter, updateDefinition, partitionKey, CancellationToken.None); + } + + /// + public virtual long UpdateMany(FilterDefinition filter, UpdateDefinition updateDefinition, string partitionKey, CancellationToken cancellationToken) + where TDocument : IDocument + { + return MongoDbUpdater.UpdateMany(filter, updateDefinition, partitionKey, cancellationToken); + } + + /// + public long UpdateMany(Expression> filter, UpdateDefinition updateDefinition) + where TDocument : IDocument + { + return UpdateMany(filter, updateDefinition, null, CancellationToken.None); + } + + /// + public long UpdateMany(Expression> filter, UpdateDefinition updateDefinition, CancellationToken cancellationToken) + where TDocument : IDocument + { + return UpdateMany(filter, updateDefinition, null, cancellationToken); + } + + /// + public long UpdateMany(Expression> filter, UpdateDefinition updateDefinition, string partitionKey) + where TDocument : IDocument + { + return UpdateMany(filter, updateDefinition, partitionKey, CancellationToken.None); + } + + /// + public long UpdateMany(Expression> filter, UpdateDefinition updateDefinition, string partitionKey, CancellationToken cancellationToken) + where TDocument : IDocument + { + return MongoDbUpdater.UpdateMany(filter, updateDefinition, partitionKey, cancellationToken); } #endregion Update #region Update TKey - /// - /// Asynchronously Updates a document. - /// - /// The type representing a Document. - /// The type of the primary key for a Document. - /// The document with the modifications you want to persist. + /// public virtual async Task UpdateOneAsync(TDocument modifiedDocument) where TDocument : IDocument where TKey : IEquatable { - return await MongoDbUpdater.UpdateOneAsync(modifiedDocument); + return await UpdateOneAsync(modifiedDocument, CancellationToken.None); } - /// - /// Updates a document. - /// - /// The type representing a Document. - /// The type of the primary key for a Document. - /// The document with the modifications you want to persist. + /// + public virtual async Task UpdateOneAsync(TDocument modifiedDocument, CancellationToken cancellationToken) + where TDocument : IDocument + where TKey : IEquatable + { + return await MongoDbUpdater.UpdateOneAsync(modifiedDocument, cancellationToken); + } + + /// public virtual bool UpdateOne(TDocument modifiedDocument) where TDocument : IDocument where TKey : IEquatable { - return MongoDbUpdater.UpdateOne(modifiedDocument); + return UpdateOne(modifiedDocument, CancellationToken.None); } - /// - /// Takes a document you want to modify and applies the update you have defined in MongoDb. - /// - /// The type representing a Document. - /// The type of the primary key for a Document. - /// The document you want to modify. - /// The update definition for the document. + /// + public virtual bool UpdateOne(TDocument modifiedDocument, CancellationToken cancellationToken) + where TDocument : IDocument + where TKey : IEquatable + { + return MongoDbUpdater.UpdateOne(modifiedDocument, cancellationToken); + } + + /// public virtual async Task UpdateOneAsync(TDocument documentToModify, UpdateDefinition update) where TDocument : IDocument where TKey : IEquatable { - return await MongoDbUpdater.UpdateOneAsync(documentToModify, update); + return await UpdateOneAsync(documentToModify, update, CancellationToken.None); } - /// - /// Takes a document you want to modify and applies the update you have defined in MongoDb. - /// - /// The type representing a Document. - /// The type of the primary key for a Document. - /// The document you want to modify. - /// The update definition for the document. + /// + public virtual async Task UpdateOneAsync(TDocument documentToModify, UpdateDefinition update, CancellationToken cancellationToken) + where TDocument : IDocument + where TKey : IEquatable + { + return await MongoDbUpdater.UpdateOneAsync(documentToModify, update, cancellationToken); + } + + /// public virtual bool UpdateOne(TDocument documentToModify, UpdateDefinition update) where TDocument : IDocument where TKey : IEquatable { - return MongoDbUpdater.UpdateOne(documentToModify, update); + return UpdateOne(documentToModify, update, CancellationToken.None); } - /// - /// Updates the property field with the given value update a property field in entities. - /// - /// The type representing a Document. - /// The type of the primary key for a Document. - /// The type of the field. - /// The document you want to modify. - /// The field selector. - /// The new value of the property field. + /// + public virtual bool UpdateOne(TDocument documentToModify, UpdateDefinition update, CancellationToken cancellationToken) + where TDocument : IDocument + where TKey : IEquatable + { + return MongoDbUpdater.UpdateOne(documentToModify, update, cancellationToken); + } + + /// public virtual bool UpdateOne(TDocument documentToModify, Expression> field, TField value) where TDocument : IDocument where TKey : IEquatable { - return MongoDbUpdater.UpdateOne(documentToModify, field, value); + return UpdateOne(documentToModify, field, value, CancellationToken.None); } - /// - /// Updates the property field with the given value update a property field in entities. - /// - /// The type representing a Document. - /// The type of the primary key for a Document. - /// The type of the field. - /// The document you want to modify. - /// The field selector. - /// The new value of the property field. + /// + public virtual bool UpdateOne(TDocument documentToModify, Expression> field, TField value, CancellationToken cancellationToken) + where TDocument : IDocument + where TKey : IEquatable + { + return MongoDbUpdater.UpdateOne(documentToModify, field, value, cancellationToken); + } + + /// public virtual async Task UpdateOneAsync(TDocument documentToModify, Expression> field, TField value) where TDocument : IDocument where TKey : IEquatable { - return await MongoDbUpdater.UpdateOneAsync(documentToModify, field, value); + return await UpdateOneAsync(documentToModify, field, value, CancellationToken.None); } - /// - /// Updates the property field with the given value. - /// - /// The type representing a Document. - /// The type of the primary key for a Document. - /// The type of the field. - /// The document filter. - /// The field selector. - /// The new value of the property field. - /// The value of the partition key. - public virtual bool UpdateOne(FilterDefinition filter, Expression> field, TField value, string partitionKey = null) + /// + public virtual async Task UpdateOneAsync(TDocument documentToModify, Expression> field, TField value, CancellationToken cancellationToken) where TDocument : IDocument where TKey : IEquatable { - return MongoDbUpdater.UpdateOne(filter, field, value, partitionKey); + return await MongoDbUpdater.UpdateOneAsync(documentToModify, field, value, cancellationToken); } - /// - /// For the entity selected by the filter, updates the property field with the given value. - /// - /// The type representing a Document. - /// The type of the primary key for a Document. - /// The type of the field. - /// The document filter. - /// The field selector. - /// The new value of the property field. - /// The partition key for the document. - public virtual bool UpdateOne(Expression> filter, Expression> field, TField value, string partitionKey = null) + /// + public virtual bool UpdateOne(FilterDefinition filter, Expression> field, TField value) where TDocument : IDocument where TKey : IEquatable { - return MongoDbUpdater.UpdateOne(filter, field, value, partitionKey); + return UpdateOne(filter, field, value, null, CancellationToken.None); } - /// - /// Updates the property field with the given value update a property field in entities. - /// - /// The type representing a Document. - /// The type of the primary key for a Document. - /// The type of the field. - /// The document filter. - /// The field selector. - /// The new value of the property field. - /// The value of the partition key. - public virtual async Task UpdateOneAsync(FilterDefinition filter, Expression> field, TField value, string partitionKey = null) + /// + public virtual bool UpdateOne(FilterDefinition filter, Expression> field, TField value, CancellationToken cancellationToken) where TDocument : IDocument where TKey : IEquatable { - return await MongoDbUpdater.UpdateOneAsync(filter, field, value, partitionKey); + return UpdateOne(filter, field, value, null, cancellationToken); } - /// - /// For the entity selected by the filter, updates the property field with the given value. - /// - /// The type representing a Document. - /// The type of the primary key for a Document. - /// The type of the field. - /// The document filter. - /// The field selector. - /// The new value of the property field. - /// The partition key for the document. - public virtual async Task UpdateOneAsync(Expression> filter, Expression> field, TField value, string partitionKey = null) + /// + public virtual bool UpdateOne(FilterDefinition filter, Expression> field, TField value, string partitionKey) where TDocument : IDocument where TKey : IEquatable { - return await MongoDbUpdater.UpdateOneAsync(Builders.Filter.Where(filter), field, value, partitionKey); + return UpdateOne(filter, field, value, partitionKey, CancellationToken.None); } - /// - /// For the entities selected by the filter, updates the property field with the given value. - /// - /// The type representing a Document. - /// The type of the primary key for a Document. - /// The type of the field. - /// The document filter. - /// The field selector. - /// The new value of the property field. - /// The partition key for the document. - public virtual async Task UpdateManyAsync(Expression> filter, Expression> field, TField value, string partitionKey = null) + /// + public virtual bool UpdateOne(FilterDefinition filter, Expression> field, TField value, string partitionKey, CancellationToken cancellationToken) where TDocument : IDocument where TKey : IEquatable { - return await MongoDbUpdater.UpdateManyAsync(filter, field, value, partitionKey); + return MongoDbUpdater.UpdateOne(filter, field, value, partitionKey, cancellationToken); } - /// - /// For the entities selected by the filter, updates the property field with the given value. - /// - /// The type representing a Document. - /// The type of the primary key for a Document. - /// The type of the field. - /// The document filter. - /// The field selector. - /// The new value of the property field. - /// The value of the partition key. - public virtual async Task UpdateManyAsync(FilterDefinition filter, Expression> field, TField value, string partitionKey = null) + /// + public virtual bool UpdateOne(Expression> filter, Expression> field, TField value) where TDocument : IDocument where TKey : IEquatable { - return await MongoDbUpdater.UpdateManyAsync(filter, field, value, partitionKey); + return UpdateOne(filter, field, value, null, CancellationToken.None); } - /// - /// For the entities selected by the filter, applies the update you have defined in MongoDb. - /// - /// The type representing a Document. - /// The type of the primary key for a Document. - /// The document filter. - /// The update definition to apply. - /// The value of the partition key. - public virtual async Task UpdateManyAsync(FilterDefinition filter, UpdateDefinition updateDefinition, string partitionKey = null) + /// + public virtual bool UpdateOne(Expression> filter, Expression> field, TField value, CancellationToken cancellationToken) where TDocument : IDocument where TKey : IEquatable { - return await MongoDbUpdater.UpdateManyAsync(filter, updateDefinition, partitionKey); + return UpdateOne(filter, field, value, null, cancellationToken); } - /// - /// For the entities selected by the filter, applies the update you have defined in MongoDb. - /// - /// The type representing a Document. - /// The type of the primary key for a Document. - /// The document filter. - /// The update definition to apply. - /// The value of the partition key. - public virtual async Task UpdateManyAsync(Expression> filter, UpdateDefinition updateDefinition, string partitionKey = null) + /// + public virtual bool UpdateOne(Expression> filter, Expression> field, TField value, string partitionKey) where TDocument : IDocument where TKey : IEquatable { - return await MongoDbUpdater.UpdateManyAsync(filter, updateDefinition, partitionKey); + return UpdateOne(filter, field, value, partitionKey, CancellationToken.None); } - /// - /// For the entities selected by the filter, updates the property field with the given value. - /// - /// The type representing a Document. - /// The type of the primary key for a Document. - /// The type of the field. - /// The document filter. - /// The field selector. - /// The new value of the property field. - /// The partition key for the document. - public virtual long UpdateMany(Expression> filter, Expression> field, TField value, string partitionKey = null) + /// + public virtual bool UpdateOne(Expression> filter, Expression> field, TField value, string partitionKey, CancellationToken cancellationToken) where TDocument : IDocument where TKey : IEquatable { - return MongoDbUpdater.UpdateMany(filter, field, value, partitionKey); + return MongoDbUpdater.UpdateOne(filter, field, value, partitionKey, cancellationToken); } - /// - /// For the entities selected by the filter, updates the property field with the given value. - /// - /// The type representing a Document. - /// The type of the primary key for a Document. - /// The type of the field. - /// The document filter. - /// The field selector. - /// The new value of the property field. - /// The value of the partition key. - public virtual long UpdateMany(FilterDefinition filter, Expression> field, TField value, string partitionKey = null) + /// + public virtual async Task UpdateOneAsync(FilterDefinition filter, Expression> field, TField value) where TDocument : IDocument where TKey : IEquatable { - return MongoDbUpdater.UpdateMany(filter, field, value, partitionKey); + return await UpdateOneAsync(filter, field, value, null, CancellationToken.None); } - /// - /// For the entities selected by the filter, applies the update you have defined in MongoDb. - /// - /// The type representing a Document. - /// The type of the primary key for a Document. - /// The document filter. - /// The update definition to apply. - /// The value of the partition key. - public virtual long UpdateMany(Expression> filter, UpdateDefinition updateDefinition, string partitionKey = null) + /// + public virtual async Task UpdateOneAsync(FilterDefinition filter, Expression> field, TField value, CancellationToken cancellationToken) where TDocument : IDocument where TKey : IEquatable { - return MongoDbUpdater.UpdateMany(filter, updateDefinition, partitionKey); + return await UpdateOneAsync(filter, field, value, null, cancellationToken); } - /// - /// For the entities selected by the filter, applies the update you have defined in MongoDb. - /// - /// The type representing a Document. - /// The type of the primary key for a Document. - /// The document filter. - /// The update definition to apply. - /// The value of the partition key. - public virtual long UpdateMany(FilterDefinition filter, UpdateDefinition updateDefinition, string partitionKey = null) + /// + public virtual async Task UpdateOneAsync(FilterDefinition filter, Expression> field, TField value, string partitionKey) where TDocument : IDocument where TKey : IEquatable { - return MongoDbUpdater.UpdateMany(filter, updateDefinition, partitionKey); + return await UpdateOneAsync(filter, field, value, partitionKey, CancellationToken.None); + } + + /// + public virtual async Task UpdateOneAsync(FilterDefinition filter, Expression> field, TField value, string partitionKey, CancellationToken cancellationToken) + where TDocument : IDocument + where TKey : IEquatable + { + return await MongoDbUpdater.UpdateOneAsync(filter, field, value, partitionKey, cancellationToken); + } + + /// + public virtual async Task UpdateOneAsync(Expression> filter, Expression> field, TField value) + where TDocument : IDocument + where TKey : IEquatable + { + return await UpdateOneAsync(Builders.Filter.Where(filter), field, value, null, CancellationToken.None); + } + + /// + public virtual async Task UpdateOneAsync(Expression> filter, Expression> field, TField value, CancellationToken cancellationToken) + where TDocument : IDocument + where TKey : IEquatable + { + return await UpdateOneAsync(Builders.Filter.Where(filter), field, value, null, cancellationToken); + } + + /// + public virtual async Task UpdateOneAsync(Expression> filter, Expression> field, TField value, string partitionKey) + where TDocument : IDocument + where TKey : IEquatable + { + return await UpdateOneAsync(Builders.Filter.Where(filter), field, value, partitionKey, CancellationToken.None); + } + + /// + public virtual async Task UpdateOneAsync(Expression> filter, Expression> field, TField value, string partitionKey, CancellationToken cancellationToken) + where TDocument : IDocument + where TKey : IEquatable + { + return await MongoDbUpdater.UpdateOneAsync(Builders.Filter.Where(filter), field, value, partitionKey, cancellationToken); + } + + /// + public virtual async Task UpdateManyAsync(Expression> filter, Expression> field, TField value) + where TDocument : IDocument + where TKey : IEquatable + { + return await UpdateManyAsync(filter, field, value, null, CancellationToken.None); + } + + /// + public virtual async Task UpdateManyAsync(Expression> filter, Expression> field, TField value, CancellationToken cancellationToken) + where TDocument : IDocument + where TKey : IEquatable + { + return await UpdateManyAsync(filter, field, value, null, cancellationToken); + } + + /// + public virtual async Task UpdateManyAsync(Expression> filter, Expression> field, TField value, string partitionKey) + where TDocument : IDocument + where TKey : IEquatable + { + return await UpdateManyAsync(filter, field, value, partitionKey, CancellationToken.None); + } + + /// + public virtual async Task UpdateManyAsync(Expression> filter, Expression> field, TField value, string partitionKey, CancellationToken cancellationToken) + where TDocument : IDocument + where TKey : IEquatable + { + return await MongoDbUpdater.UpdateManyAsync(filter, field, value, partitionKey, cancellationToken); + } + + /// + public virtual async Task UpdateManyAsync(FilterDefinition filter, Expression> field, TField value) + where TDocument : IDocument + where TKey : IEquatable + { + return await UpdateManyAsync(filter, field, value, null, CancellationToken.None); + } + + /// + public virtual async Task UpdateManyAsync(FilterDefinition filter, Expression> field, TField value, CancellationToken cancellationToken) + where TDocument : IDocument + where TKey : IEquatable + { + return await UpdateManyAsync(filter, field, value, null, cancellationToken); + } + + /// + public virtual async Task UpdateManyAsync(FilterDefinition filter, Expression> field, TField value, string partitionKey) + where TDocument : IDocument + where TKey : IEquatable + { + return await UpdateManyAsync(filter, field, value, partitionKey, CancellationToken.None); + } + + /// + public virtual async Task UpdateManyAsync(FilterDefinition filter, Expression> field, TField value, string partitionKey, CancellationToken cancellationToken) + where TDocument : IDocument + where TKey : IEquatable + { + return await MongoDbUpdater.UpdateManyAsync(filter, field, value, partitionKey, cancellationToken); + } + + /// + public virtual async Task UpdateManyAsync(FilterDefinition filter, UpdateDefinition updateDefinition) + where TDocument : IDocument + where TKey : IEquatable + { + return await UpdateManyAsync(filter, updateDefinition, null, CancellationToken.None); + } + + /// + public virtual async Task UpdateManyAsync(FilterDefinition filter, UpdateDefinition updateDefinition, CancellationToken cancellationToken) + where TDocument : IDocument + where TKey : IEquatable + { + return await UpdateManyAsync(filter, updateDefinition, null, cancellationToken); + } + + /// + public virtual async Task UpdateManyAsync(FilterDefinition filter, UpdateDefinition updateDefinition, string partitionKey) + where TDocument : IDocument + where TKey : IEquatable + { + return await UpdateManyAsync(filter, updateDefinition, partitionKey, CancellationToken.None); + } + + /// + public virtual async Task UpdateManyAsync(FilterDefinition filter, UpdateDefinition updateDefinition, string partitionKey, CancellationToken cancellationToken) + where TDocument : IDocument + where TKey : IEquatable + { + return await MongoDbUpdater.UpdateManyAsync(filter, updateDefinition, partitionKey, cancellationToken); + } + + /// + public virtual async Task UpdateManyAsync(Expression> filter, UpdateDefinition updateDefinition) + where TDocument : IDocument + where TKey : IEquatable + { + return await UpdateManyAsync(filter, updateDefinition, null, CancellationToken.None); + } + + /// + public virtual async Task UpdateManyAsync(Expression> filter, UpdateDefinition updateDefinition, CancellationToken cancellationToken) + where TDocument : IDocument + where TKey : IEquatable + { + return await UpdateManyAsync(filter, updateDefinition, null, cancellationToken); + } + + /// + public virtual async Task UpdateManyAsync(Expression> filter, UpdateDefinition updateDefinition, string partitionKey) + where TDocument : IDocument + where TKey : IEquatable + { + return await UpdateManyAsync(filter, updateDefinition, partitionKey, CancellationToken.None); + } + + /// + public virtual async Task UpdateManyAsync(Expression> filter, UpdateDefinition updateDefinition, string partitionKey, CancellationToken cancellationToken) + where TDocument : IDocument + where TKey : IEquatable + { + return await MongoDbUpdater.UpdateManyAsync(filter, updateDefinition, partitionKey, cancellationToken); + } + + /// + public virtual long UpdateMany(Expression> filter, Expression> field, TField value) + where TDocument : IDocument + where TKey : IEquatable + { + return UpdateMany(filter, field, value, null, CancellationToken.None); + } + + /// + public virtual long UpdateMany(Expression> filter, Expression> field, TField value, CancellationToken cancellationToken) + where TDocument : IDocument + where TKey : IEquatable + { + return UpdateMany(filter, field, value, null, cancellationToken); + } + + /// + public virtual long UpdateMany(Expression> filter, Expression> field, TField value, string partitionKey) + where TDocument : IDocument + where TKey : IEquatable + { + return UpdateMany(filter, field, value, partitionKey, CancellationToken.None); + } + + /// + public virtual long UpdateMany(Expression> filter, Expression> field, TField value, string partitionKey, CancellationToken cancellationToken) + where TDocument : IDocument + where TKey : IEquatable + { + return MongoDbUpdater.UpdateMany(filter, field, value, partitionKey, cancellationToken); + } + + /// + public virtual long UpdateMany(FilterDefinition filter, Expression> field, TField value) + where TDocument : IDocument + where TKey : IEquatable + { + return UpdateMany(filter, field, value, null, CancellationToken.None); + } + + /// + public virtual long UpdateMany(FilterDefinition filter, Expression> field, TField value, CancellationToken cancellationToken) + where TDocument : IDocument + where TKey : IEquatable + { + return UpdateMany(filter, field, value, null, cancellationToken); + } + + /// + public virtual long UpdateMany(FilterDefinition filter, Expression> field, TField value, string partitionKey) + where TDocument : IDocument + where TKey : IEquatable + { + return UpdateMany(filter, field, value, partitionKey, CancellationToken.None); + } + + /// + public virtual long UpdateMany(FilterDefinition filter, Expression> field, TField value, string partitionKey, CancellationToken cancellationToken) + where TDocument : IDocument + where TKey : IEquatable + { + return MongoDbUpdater.UpdateMany(filter, field, value, partitionKey, cancellationToken); + } + + /// + public virtual long UpdateMany(Expression> filter, UpdateDefinition updateDefinition) + where TDocument : IDocument + where TKey : IEquatable + { + return UpdateMany(filter, updateDefinition, null, CancellationToken.None); + } + + /// + public virtual long UpdateMany(Expression> filter, UpdateDefinition updateDefinition, CancellationToken cancellationToken) + where TDocument : IDocument + where TKey : IEquatable + { + return UpdateMany(filter, updateDefinition, null, cancellationToken); + } + + /// + public virtual long UpdateMany(Expression> filter, UpdateDefinition updateDefinition, string partitionKey) + where TDocument : IDocument + where TKey : IEquatable + { + return UpdateMany(filter, updateDefinition, partitionKey, CancellationToken.None); + } + + /// + public virtual long UpdateMany(Expression> filter, UpdateDefinition updateDefinition, string partitionKey, CancellationToken cancellationToken) + where TDocument : IDocument + where TKey : IEquatable + { + return MongoDbUpdater.UpdateMany(filter, updateDefinition, partitionKey, cancellationToken); + } + + /// + public virtual long UpdateMany(FilterDefinition filter, UpdateDefinition updateDefinition) + where TDocument : IDocument + where TKey : IEquatable + { + return UpdateMany(filter, updateDefinition, null, CancellationToken.None); + } + + /// + public virtual long UpdateMany(FilterDefinition filter, UpdateDefinition updateDefinition, CancellationToken cancellationToken) + where TDocument : IDocument + where TKey : IEquatable + { + return UpdateMany(filter, updateDefinition, null, cancellationToken); + } + + /// + public virtual long UpdateMany(FilterDefinition filter, UpdateDefinition updateDefinition, string partitionKey) + where TDocument : IDocument + where TKey : IEquatable + { + return UpdateMany(filter, updateDefinition, partitionKey, CancellationToken.None); + } + + /// + public virtual long UpdateMany(FilterDefinition filter, UpdateDefinition updateDefinition, string partitionKey, CancellationToken cancellationToken) + where TDocument : IDocument + where TKey : IEquatable + { + return MongoDbUpdater.UpdateMany(filter, updateDefinition, partitionKey, cancellationToken); } #endregion Update } -} +} \ No newline at end of file diff --git a/MongoDbGenericRepository/KeyTypedRepository/BaseMongoRepository.TKey.Update.cs b/MongoDbGenericRepository/KeyTypedRepository/BaseMongoRepository.TKey.Update.cs index 53015c1..3d66778 100644 --- a/MongoDbGenericRepository/KeyTypedRepository/BaseMongoRepository.TKey.Update.cs +++ b/MongoDbGenericRepository/KeyTypedRepository/BaseMongoRepository.TKey.Update.cs @@ -3,6 +3,7 @@ using MongoDbGenericRepository.DataAccess.Update; using MongoDbGenericRepository.Models; using System; using System.Linq.Expressions; +using System.Threading; using System.Threading.Tasks; namespace MongoDbGenericRepository @@ -34,247 +35,424 @@ namespace MongoDbGenericRepository set { _mongoDbUpdater = value; } } - /// - /// Asynchronously Updates a document. - /// - /// The type representing a Document. - /// The document with the modifications you want to persist. - public virtual async Task UpdateOneAsync(TDocument modifiedDocument) where TDocument : IDocument + /// + public virtual async Task UpdateOneAsync(TDocument modifiedDocument) + where TDocument : IDocument { - return await MongoDbUpdater.UpdateOneAsync(modifiedDocument); + return await UpdateOneAsync(modifiedDocument, CancellationToken.None); } - /// - /// Updates a document. - /// - /// The type representing a Document. - /// The document with the modifications you want to persist. - public virtual bool UpdateOne(TDocument modifiedDocument) where TDocument : IDocument + /// + public virtual async Task UpdateOneAsync(TDocument modifiedDocument, CancellationToken cancellationToken) + where TDocument : IDocument { - return MongoDbUpdater.UpdateOne(modifiedDocument); + return await MongoDbUpdater.UpdateOneAsync(modifiedDocument, cancellationToken); } - /// - /// Takes a document you want to modify and applies the update you have defined in MongoDb. - /// - /// The type representing a Document. - /// The document you want to modify. - /// The update definition for the document. + /// + public virtual bool UpdateOne(TDocument modifiedDocument) + where TDocument : IDocument + { + return UpdateOne(modifiedDocument, CancellationToken.None); + } + + /// + public virtual bool UpdateOne(TDocument modifiedDocument, CancellationToken cancellationToken) + where TDocument : IDocument + { + return MongoDbUpdater.UpdateOne(modifiedDocument, cancellationToken); + } + + /// public virtual async Task UpdateOneAsync(TDocument documentToModify, UpdateDefinition update) where TDocument : IDocument { - return await MongoDbUpdater.UpdateOneAsync(documentToModify, update); + return await UpdateOneAsync(documentToModify, update, CancellationToken.None); } - /// - /// Takes a document you want to modify and applies the update you have defined in MongoDb. - /// - /// The type representing a Document. - /// The document you want to modify. - /// The update definition for the document. + /// + public virtual async Task UpdateOneAsync(TDocument documentToModify, UpdateDefinition update, CancellationToken cancellationToken) + where TDocument : IDocument + { + return await MongoDbUpdater.UpdateOneAsync(documentToModify, update, cancellationToken); + } + + /// public virtual bool UpdateOne(TDocument documentToModify, UpdateDefinition update) where TDocument : IDocument { - return MongoDbUpdater.UpdateOne(documentToModify, update); + return UpdateOne(documentToModify, update, CancellationToken.None); } - /// - /// Updates the property field with the given value update a property field in entities. - /// - /// The type representing a Document. - /// The type of the field. - /// The document you want to modify. - /// The field selector. - /// The new value of the property field. + /// + public virtual bool UpdateOne(TDocument documentToModify, UpdateDefinition update, CancellationToken cancellationToken) + where TDocument : IDocument + { + return MongoDbUpdater.UpdateOne(documentToModify, update, cancellationToken); + } + + /// public virtual bool UpdateOne(TDocument documentToModify, Expression> field, TField value) where TDocument : IDocument { - return MongoDbUpdater.UpdateOne(documentToModify, field, value); + return UpdateOne(documentToModify, field, value, CancellationToken.None); } - /// - /// Updates the property field with the given value update a property field in entities. - /// - /// The type representing a Document. - /// The type of the field. - /// The document you want to modify. - /// The field selector. - /// The new value of the property field. + /// + public virtual bool UpdateOne(TDocument documentToModify, Expression> field, TField value, CancellationToken cancellationToken) + where TDocument : IDocument + { + return MongoDbUpdater.UpdateOne(documentToModify, field, value, cancellationToken); + } + + /// public virtual async Task UpdateOneAsync(TDocument documentToModify, Expression> field, TField value) where TDocument : IDocument { - return await MongoDbUpdater.UpdateOneAsync(documentToModify, field, value); + return await UpdateOneAsync(documentToModify, field, value, CancellationToken.None); } - /// - /// Updates the property field with the given value update a property field in entities. - /// - /// The type representing a Document. - /// The type of the field. - /// The document filter. - /// The field selector. - /// The new value of the property field. - /// The value of the partition key. - public virtual bool UpdateOne(FilterDefinition filter, Expression> field, TField value, string partitionKey = null) + /// + public virtual async Task UpdateOneAsync(TDocument documentToModify, Expression> field, TField value, CancellationToken cancellationToken) where TDocument : IDocument { - return MongoDbUpdater.UpdateOne(filter, field, value, partitionKey); + return await MongoDbUpdater.UpdateOneAsync(documentToModify, field, value, cancellationToken); } - /// - /// For the entity selected by the filter, updates the property field with the given value. - /// - /// The type representing a Document. - /// The type of the field. - /// The document filter. - /// The field selector. - /// The new value of the property field. - /// The partition key for the document. - public virtual bool UpdateOne(Expression> filter, Expression> field, TField value, string partitionKey = null) + /// + public virtual bool UpdateOne(FilterDefinition filter, Expression> field, TField value) where TDocument : IDocument { - return MongoDbUpdater.UpdateOne(filter, field, value, partitionKey); + return UpdateOne(filter, field, value, null, CancellationToken.None); } - /// - /// Updates the property field with the given value update a property field in entities. - /// - /// The type representing a Document. - /// The type of the field. - /// The document filter. - /// The field selector. - /// The new value of the property field. - /// The value of the partition key. - public virtual async Task UpdateOneAsync(FilterDefinition filter, Expression> field, TField value, string partitionKey = null) + /// + public virtual bool UpdateOne(FilterDefinition filter, Expression> field, TField value, CancellationToken cancellationToken) where TDocument : IDocument { - return await MongoDbUpdater.UpdateOneAsync(filter, field, value, partitionKey); + return UpdateOne(filter, field, value, null, cancellationToken); } - /// - /// For the entity selected by the filter, updates the property field with the given value. - /// - /// The type representing a Document. - /// The type of the field. - /// The document filter. - /// The field selector. - /// The new value of the property field. - /// The partition key for the document. - public virtual async Task UpdateOneAsync(Expression> filter, Expression> field, TField value, string partitionKey = null) + /// + public virtual bool UpdateOne(FilterDefinition filter, Expression> field, TField value, string partitionKey) where TDocument : IDocument { - return await MongoDbUpdater.UpdateOneAsync(filter, field, value, partitionKey); + return UpdateOne(filter, field, value, partitionKey, CancellationToken.None); } - /// - /// For the entities selected by the filter, updates the property field with the given value. - /// - /// The type representing a Document. - /// The type of the field. - /// The document filter. - /// The field selector. - /// The new value of the property field. - /// The partition key for the document. - public virtual async Task UpdateManyAsync(Expression> filter, Expression> field, TField value, string partitionKey = null) + /// + public virtual bool UpdateOne(FilterDefinition filter, Expression> field, TField value, string partitionKey, CancellationToken cancellationToken) where TDocument : IDocument { - return await MongoDbUpdater.UpdateManyAsync(filter, field, value, partitionKey); + return MongoDbUpdater.UpdateOne(filter, field, value, partitionKey, cancellationToken); } - /// - /// For the entities selected by the filter, updates the property field with the given value. - /// - /// The type representing a Document. - /// The type of the field. - /// The document filter. - /// The field selector. - /// The new value of the property field. - /// The value of the partition key. - public virtual async Task UpdateManyAsync(FilterDefinition filter, Expression> field, TField value, string partitionKey = null) + /// + public virtual bool UpdateOne(Expression> filter, Expression> field, TField value) where TDocument : IDocument { - return await MongoDbUpdater.UpdateManyAsync(filter, field, value, partitionKey); + return UpdateOne(filter, field, value, null, CancellationToken.None); } - /// - /// For the entities selected by the filter, applies the update you have defined in MongoDb. - /// - /// The type representing a Document. - /// The document filter. - /// The update definition to apply. - /// The value of the partition key. - public virtual async Task UpdateManyAsync(FilterDefinition filter, UpdateDefinition updateDefinition, string partitionKey = null) + /// + public virtual bool UpdateOne(Expression> filter, Expression> field, TField value, CancellationToken cancellationToken) where TDocument : IDocument { - return await MongoDbUpdater.UpdateManyAsync(filter, updateDefinition, partitionKey); + return UpdateOne(filter, field, value, null, cancellationToken); } - /// - /// For the entities selected by the filter, applies the update you have defined in MongoDb. - /// - /// The type representing a Document. - /// The document filter. - /// The update definition to apply. - /// The value of the partition key. - public virtual async Task UpdateManyAsync(Expression> filter, UpdateDefinition updateDefinition, string partitionKey = null) + /// + public virtual bool UpdateOne(Expression> filter, Expression> field, TField value, string partitionKey) where TDocument : IDocument { - return await MongoDbUpdater.UpdateManyAsync(filter, updateDefinition, partitionKey); + return UpdateOne(filter, field, value, partitionKey, CancellationToken.None); } - /// - /// For the entities selected by the filter, updates the property field with the given value. - /// - /// The type representing a Document. - /// The type of the field. - /// The document filter. - /// The field selector. - /// The new value of the property field. - /// The partition key for the document. - public virtual long UpdateMany(Expression> filter, Expression> field, TField value, string partitionKey = null) + /// + public virtual bool UpdateOne(Expression> filter, Expression> field, TField value, string partitionKey, CancellationToken cancellationToken) where TDocument : IDocument { - return MongoDbUpdater.UpdateMany(filter, field, value, partitionKey); + return MongoDbUpdater.UpdateOne(filter, field, value, partitionKey, cancellationToken); } - /// - /// For the entities selected by the filter, updates the property field with the given value. - /// - /// The type representing a Document. - /// The type of the field. - /// The document filter. - /// The field selector. - /// The new value of the property field. - /// The value of the partition key. - public virtual long UpdateMany(FilterDefinition filter, Expression> field, TField value, string partitionKey = null) + /// + public virtual async Task UpdateOneAsync(FilterDefinition filter, Expression> field, TField value) where TDocument : IDocument { - return MongoDbUpdater.UpdateMany(filter, field, value, partitionKey); + return await UpdateOneAsync(filter, field, value, null, CancellationToken.None); } - /// - /// For the entities selected by the filter, applies the update you have defined in MongoDb. - /// - /// The type representing a Document. - /// The document filter. - /// The update definition to apply. - /// The value of the partition key. - public virtual long UpdateMany(FilterDefinition filter, UpdateDefinition updateDefinition, string partitionKey = null) + /// + public virtual async Task UpdateOneAsync(FilterDefinition filter, Expression> field, TField value, CancellationToken cancellationToken) where TDocument : IDocument { - return MongoDbUpdater.UpdateMany(filter, updateDefinition, partitionKey); + return await UpdateOneAsync(filter, field, value, null, cancellationToken); } - /// - /// For the entities selected by the filter, applies the update you have defined in MongoDb. - /// - /// The type representing a Document. - /// The document filter. - /// The update definition to apply. - /// The value of the partition key. - public virtual long UpdateMany(Expression> filter, UpdateDefinition updateDefinition, string partitionKey = null) where TDocument : IDocument + /// + public virtual async Task UpdateOneAsync(FilterDefinition filter, Expression> field, TField value, string partitionKey) + where TDocument : IDocument { - return MongoDbUpdater.UpdateMany(filter, updateDefinition, partitionKey); + return await UpdateOneAsync(filter, field, value, partitionKey, CancellationToken.None); + } + + /// + public virtual async Task UpdateOneAsync(FilterDefinition filter, Expression> field, TField value, string partitionKey, CancellationToken cancellationToken) + where TDocument : IDocument + { + return await MongoDbUpdater.UpdateOneAsync(filter, field, value, partitionKey, cancellationToken); + } + + /// + public virtual async Task UpdateOneAsync(Expression> filter, Expression> field, TField value) + where TDocument : IDocument + { + return await UpdateOneAsync(filter, field, value, null, CancellationToken.None); + } + + /// + public virtual async Task UpdateOneAsync(Expression> filter, Expression> field, TField value, CancellationToken cancellationToken) + where TDocument : IDocument + { + return await UpdateOneAsync(filter, field, value, null, cancellationToken); + } + + /// + public virtual async Task UpdateOneAsync(Expression> filter, Expression> field, TField value, string partitionKey) + where TDocument : IDocument + { + return await UpdateOneAsync(filter, field, value, partitionKey, CancellationToken.None); + } + + /// + public virtual async Task UpdateOneAsync(Expression> filter, Expression> field, TField value, string partitionKey, CancellationToken cancellationToken) + where TDocument : IDocument + { + return await MongoDbUpdater.UpdateOneAsync(filter, field, value, partitionKey, cancellationToken); + } + + /// + public virtual async Task UpdateManyAsync(Expression> filter, Expression> field, TField value) + where TDocument : IDocument + { + return await UpdateManyAsync(filter, field, value, null, CancellationToken.None); + } + + /// + public virtual async Task UpdateManyAsync(Expression> filter, Expression> field, TField value, CancellationToken cancellationToken) + where TDocument : IDocument + { + return await UpdateManyAsync(filter, field, value, null, cancellationToken); + } + + /// + public virtual async Task UpdateManyAsync(Expression> filter, Expression> field, TField value, string partitionKey) + where TDocument : IDocument + { + return await UpdateManyAsync(filter, field, value, partitionKey, CancellationToken.None); + } + + /// + public virtual async Task UpdateManyAsync(Expression> filter, Expression> field, TField value, string partitionKey, CancellationToken cancellationToken) + where TDocument : IDocument + { + return await MongoDbUpdater.UpdateManyAsync(filter, field, value, partitionKey, cancellationToken); + } + + /// + public virtual async Task UpdateManyAsync(FilterDefinition filter, Expression> field, TField value) + where TDocument : IDocument + { + return await UpdateManyAsync(filter, field, value, null, CancellationToken.None); + } + + /// + public virtual async Task UpdateManyAsync(FilterDefinition filter, Expression> field, TField value, CancellationToken cancellationToken) + where TDocument : IDocument + { + return await UpdateManyAsync(filter, field, value, null, cancellationToken); + } + + /// + public virtual async Task UpdateManyAsync(FilterDefinition filter, Expression> field, TField value, string partitionKey) + where TDocument : IDocument + { + return await UpdateManyAsync(filter, field, value, partitionKey, CancellationToken.None); + } + + /// + public virtual async Task UpdateManyAsync(FilterDefinition filter, Expression> field, TField value, string partitionKey, CancellationToken cancellationToken) + where TDocument : IDocument + { + return await MongoDbUpdater.UpdateManyAsync(filter, field, value, partitionKey, cancellationToken); + } + + /// + public virtual async Task UpdateManyAsync(FilterDefinition filter, UpdateDefinition updateDefinition) + where TDocument : IDocument + { + return await UpdateManyAsync(filter, updateDefinition, null, CancellationToken.None); + } + + /// + public virtual async Task UpdateManyAsync(FilterDefinition filter, UpdateDefinition updateDefinition, CancellationToken cancellationToken) + where TDocument : IDocument + { + return await UpdateManyAsync(filter, updateDefinition, null, cancellationToken); + } + + /// + public virtual async Task UpdateManyAsync(FilterDefinition filter, UpdateDefinition updateDefinition, string partitionKey) + where TDocument : IDocument + { + return await UpdateManyAsync(filter, updateDefinition, partitionKey, CancellationToken.None); + } + + /// + public virtual async Task UpdateManyAsync(FilterDefinition filter, UpdateDefinition updateDefinition, string partitionKey, CancellationToken cancellationToken) + where TDocument : IDocument + { + return await MongoDbUpdater.UpdateManyAsync(filter, updateDefinition, partitionKey, cancellationToken); + } + + /// + public virtual async Task UpdateManyAsync(Expression> filter, UpdateDefinition updateDefinition) + where TDocument : IDocument + { + return await UpdateManyAsync(filter, updateDefinition, null, CancellationToken.None); + } + + /// + public virtual async Task UpdateManyAsync(Expression> filter, UpdateDefinition updateDefinition, CancellationToken cancellationToken) + where TDocument : IDocument + { + return await UpdateManyAsync(filter, updateDefinition, null, cancellationToken); + } + + /// + public virtual async Task UpdateManyAsync(Expression> filter, UpdateDefinition updateDefinition, string partitionKey) + where TDocument : IDocument + { + return await UpdateManyAsync(filter, updateDefinition, partitionKey, CancellationToken.None); + } + + /// + public virtual async Task UpdateManyAsync(Expression> filter, UpdateDefinition updateDefinition, string partitionKey, CancellationToken cancellationToken) + where TDocument : IDocument + { + return await MongoDbUpdater.UpdateManyAsync(filter, updateDefinition, partitionKey, cancellationToken); + } + + /// + public virtual long UpdateMany(Expression> filter, Expression> field, TField value) + where TDocument : IDocument + { + return UpdateMany(filter, field, value, null, CancellationToken.None); + } + + /// + public virtual long UpdateMany(Expression> filter, Expression> field, TField value, CancellationToken cancellationToken) + where TDocument : IDocument + { + return UpdateMany(filter, field, value, null, cancellationToken); + } + + /// + public virtual long UpdateMany(Expression> filter, Expression> field, TField value, string partitionKey) + where TDocument : IDocument + { + return UpdateMany(filter, field, value, partitionKey, CancellationToken.None); + } + + /// + public virtual long UpdateMany(Expression> filter, Expression> field, TField value, string partitionKey, CancellationToken cancellationToken) + where TDocument : IDocument + { + return MongoDbUpdater.UpdateMany(filter, field, value, partitionKey, cancellationToken); + } + + /// + public virtual long UpdateMany(FilterDefinition filter, Expression> field, TField value) + where TDocument : IDocument + { + return MongoDbUpdater.UpdateMany(filter, field, value, null, CancellationToken.None); + } + + /// + public virtual long UpdateMany(FilterDefinition filter, Expression> field, TField value, CancellationToken cancellationToken) + where TDocument : IDocument + { + return MongoDbUpdater.UpdateMany(filter, field, value, null, cancellationToken); + } + + /// + public virtual long UpdateMany(FilterDefinition filter, Expression> field, TField value, string partitionKey) + where TDocument : IDocument + { + return MongoDbUpdater.UpdateMany(filter, field, value, partitionKey, CancellationToken.None); + } + + /// + public virtual long UpdateMany(FilterDefinition filter, Expression> field, TField value, string partitionKey, CancellationToken cancellationToken) + where TDocument : IDocument + { + return MongoDbUpdater.UpdateMany(filter, field, value, partitionKey, cancellationToken); + } + + /// + public virtual long UpdateMany(FilterDefinition filter, UpdateDefinition updateDefinition) + where TDocument : IDocument + { + return UpdateMany(filter, updateDefinition, null, CancellationToken.None); + } + + /// + public virtual long UpdateMany(FilterDefinition filter, UpdateDefinition updateDefinition, CancellationToken cancellationToken) + where TDocument : IDocument + { + return UpdateMany(filter, updateDefinition, null, cancellationToken); + } + + /// + public virtual long UpdateMany(FilterDefinition filter, UpdateDefinition updateDefinition, string partitionKey) + where TDocument : IDocument + { + return UpdateMany(filter, updateDefinition, partitionKey, CancellationToken.None); + } + + /// + public virtual long UpdateMany(FilterDefinition filter, UpdateDefinition updateDefinition, string partitionKey, CancellationToken cancellationToken) + where TDocument : IDocument + { + return MongoDbUpdater.UpdateMany(filter, updateDefinition, partitionKey, cancellationToken); + } + + /// + public virtual long UpdateMany(Expression> filter, UpdateDefinition updateDefinition) + where TDocument : IDocument + { + return UpdateMany(filter, updateDefinition, null, CancellationToken.None); + } + + /// + public virtual long UpdateMany(Expression> filter, UpdateDefinition updateDefinition, CancellationToken cancellationToken) + where TDocument : IDocument + { + return UpdateMany(filter, updateDefinition, null, cancellationToken); + } + + /// + public virtual long UpdateMany(Expression> filter, UpdateDefinition updateDefinition, string partitionKey) + where TDocument : IDocument + { + return UpdateMany(filter, updateDefinition, partitionKey, CancellationToken.None); + } + + /// + public virtual long UpdateMany(Expression> filter, UpdateDefinition updateDefinition, string partitionKey, CancellationToken cancellationToken) + where TDocument : IDocument + { + return MongoDbUpdater.UpdateMany(filter, updateDefinition, partitionKey, cancellationToken); } } -} +} \ No newline at end of file diff --git a/MongoDbGenericRepository/KeyTypedRepository/IBaseMongoRepository.TKey.Update.cs b/MongoDbGenericRepository/KeyTypedRepository/IBaseMongoRepository.TKey.Update.cs index 45a9ebd..b7c4220 100644 --- a/MongoDbGenericRepository/KeyTypedRepository/IBaseMongoRepository.TKey.Update.cs +++ b/MongoDbGenericRepository/KeyTypedRepository/IBaseMongoRepository.TKey.Update.cs @@ -1,5 +1,6 @@ using System; using System.Linq.Expressions; +using System.Threading; using System.Threading.Tasks; using MongoDB.Driver; using MongoDbGenericRepository.Models; @@ -7,27 +8,48 @@ using MongoDbGenericRepository.Models; namespace MongoDbGenericRepository { /// - /// The base Mongo Repository Update interface. used to update documents in the collections. + /// The base Mongo Repository Update interface. used to update documents in the collections. /// /// - public interface IBaseMongoRepository_Update where TKey : IEquatable + public interface IBaseMongoRepository_Update + where TKey : IEquatable { /// - /// Asynchronously Updates a document. + /// Asynchronously Updates a document. /// /// The type representing a Document. /// The document with the modifications you want to persist. - Task UpdateOneAsync(TDocument modifiedDocument) where TDocument : IDocument; + Task UpdateOneAsync(TDocument modifiedDocument) + where TDocument : IDocument; /// - /// Updates a document. + /// Asynchronously Updates a document. /// /// The type representing a Document. /// The document with the modifications you want to persist. - bool UpdateOne(TDocument modifiedDocument) where TDocument : IDocument; + /// The cancellation token. + Task UpdateOneAsync(TDocument modifiedDocument, CancellationToken cancellationToken) + where TDocument : IDocument; /// - /// Takes a document you want to modify and applies the update you have defined in MongoDb. + /// Updates a document. + /// + /// The type representing a Document. + /// The document with the modifications you want to persist. + bool UpdateOne(TDocument modifiedDocument) + where TDocument : IDocument; + + /// + /// Updates a document. + /// + /// The type representing a Document. + /// The document with the modifications you want to persist. + /// The cancellation token. + bool UpdateOne(TDocument modifiedDocument, CancellationToken cancellationToken) + where TDocument : IDocument; + + /// + /// Takes a document you want to modify and applies the update you have defined in MongoDb. /// /// The type representing a Document. /// The document you want to modify. @@ -36,7 +58,17 @@ namespace MongoDbGenericRepository where TDocument : IDocument; /// - /// Takes a document you want to modify and applies the update you have defined in MongoDb. + /// Takes a document you want to modify and applies the update you have defined in MongoDb. + /// + /// The type representing a Document. + /// The document you want to modify. + /// The update definition for the document. + /// The cancellation token. + Task UpdateOneAsync(TDocument documentToModify, UpdateDefinition update, CancellationToken cancellationToken) + where TDocument : IDocument; + + /// + /// Takes a document you want to modify and applies the update you have defined in MongoDb. /// /// The type representing a Document. /// The document you want to modify. @@ -45,7 +77,17 @@ namespace MongoDbGenericRepository where TDocument : IDocument; /// - /// Updates the property field with the given value update a property field in entities. + /// Takes a document you want to modify and applies the update you have defined in MongoDb. + /// + /// The type representing a Document. + /// The document you want to modify. + /// The update definition for the document. + /// The cancellation token. + bool UpdateOne(TDocument documentToModify, UpdateDefinition update, CancellationToken cancellationToken) + where TDocument : IDocument; + + /// + /// Updates the property field with the given value update a property field in entities. /// /// The type representing a Document. /// The type of the field. @@ -56,7 +98,23 @@ namespace MongoDbGenericRepository where TDocument : IDocument; /// - /// Updates the property field with the given value update a property field in entities. + /// Updates the property field with the given value update a property field in entities. + /// + /// The type representing a Document. + /// The type of the field. + /// The document you want to modify. + /// The field selector. + /// The new value of the property field. + /// The cancellation token. + bool UpdateOne( + TDocument documentToModify, + Expression> field, + TField value, + CancellationToken cancellationToken) + where TDocument : IDocument; + + /// + /// Updates the property field with the given value update a property field in entities. /// /// The type representing a Document. /// The type of the field. @@ -67,7 +125,50 @@ namespace MongoDbGenericRepository where TDocument : IDocument; /// - /// Updates the property field with the given value update a property field in entities. + /// Updates the property field with the given value update a property field in entities. + /// + /// The type representing a Document. + /// The type of the field. + /// The document you want to modify. + /// The field selector. + /// The new value of the property field. + /// The cancellation token. + Task UpdateOneAsync( + TDocument documentToModify, + Expression> field, + TField value, + CancellationToken cancellationToken) + where TDocument : IDocument; + + /// + /// Updates the property field with the given value update a property field in entities. + /// + /// The type representing a Document. + /// The type of the field. + /// The document filter. + /// The field selector. + /// The new value of the property field. + bool UpdateOne(FilterDefinition filter, Expression> field, TField value) + where TDocument : IDocument; + + /// + /// Updates the property field with the given value update a property field in entities. + /// + /// The type representing a Document. + /// The type of the field. + /// The document filter. + /// The field selector. + /// The new value of the property field. + /// The cancellation token. + bool UpdateOne( + FilterDefinition filter, + Expression> field, + TField value, + CancellationToken cancellationToken) + where TDocument : IDocument; + + /// + /// Updates the property field with the given value update a property field in entities. /// /// The type representing a Document. /// The type of the field. @@ -75,11 +176,63 @@ namespace MongoDbGenericRepository /// The field selector. /// The new value of the property field. /// The value of the partition key. - bool UpdateOne(FilterDefinition filter, Expression> field, TField value, string partitionKey = null) + bool UpdateOne( + FilterDefinition filter, + Expression> field, + TField value, + string partitionKey) where TDocument : IDocument; /// - /// For the entity selected by the filter, updates the property field with the given value. + /// Updates the property field with the given value update a property field in entities. + /// + /// The type representing a Document. + /// The type of the field. + /// The document filter. + /// The field selector. + /// The new value of the property field. + /// The value of the partition key. + /// The cancellation token. + bool UpdateOne( + FilterDefinition filter, + Expression> field, + TField value, + string partitionKey, + CancellationToken cancellationToken) + where TDocument : IDocument; + + /// + /// For the entity selected by the filter, updates the property field with the given value. + /// + /// The type representing a Document. + /// The type of the field. + /// The document filter. + /// The field selector. + /// The new value of the property field. + bool UpdateOne( + Expression> filter, + Expression> field, + TField value) + where TDocument : IDocument; + + /// + /// For the entity selected by the filter, updates the property field with the given value. + /// + /// The type representing a Document. + /// The type of the field. + /// The document filter. + /// The field selector. + /// The new value of the property field. + /// The cancellation token. + bool UpdateOne( + Expression> filter, + Expression> field, + TField value, + CancellationToken cancellationToken) + where TDocument : IDocument; + + /// + /// For the entity selected by the filter, updates the property field with the given value. /// /// The type representing a Document. /// The type of the field. @@ -87,23 +240,15 @@ namespace MongoDbGenericRepository /// The field selector. /// The new value of the property field. /// The partition key for the document. - bool UpdateOne(Expression> filter, Expression> field, TField value, string partitionKey = null) + bool UpdateOne( + Expression> filter, + Expression> field, + TField value, + string partitionKey) where TDocument : IDocument; /// - /// Updates the property field with the given value update a property field in entities. - /// - /// The type representing a Document. - /// The type of the field. - /// The document filter. - /// The field selector. - /// The new value of the property field. - /// The value of the partition key. - Task UpdateOneAsync(FilterDefinition filter, Expression> field, TField value, string partitionKey = null) - where TDocument : IDocument; - - /// - /// For the entity selected by the filter, updates the property field with the given value. + /// For the entity selected by the filter, updates the property field with the given value. /// /// The type representing a Document. /// The type of the field. @@ -111,11 +256,105 @@ namespace MongoDbGenericRepository /// The field selector. /// The new value of the property field. /// The partition key for the document. - Task UpdateOneAsync(Expression> filter, Expression> field, TField value, string partitionKey = null) + /// The cancellation token. + bool UpdateOne( + Expression> filter, + Expression> field, + TField value, + string partitionKey, + CancellationToken cancellationToken) where TDocument : IDocument; /// - /// For the entities selected by the filter, updates the property field with the given value. + /// Updates the property field with the given value update a property field in entities. + /// + /// The type representing a Document. + /// The type of the field. + /// The document filter. + /// The field selector. + /// The new value of the property field. + Task UpdateOneAsync(FilterDefinition filter, Expression> field, TField value) + where TDocument : IDocument; + + /// + /// Updates the property field with the given value update a property field in entities. + /// + /// The type representing a Document. + /// The type of the field. + /// The document filter. + /// The field selector. + /// The new value of the property field. + /// The cancellation token. + Task UpdateOneAsync( + FilterDefinition filter, + Expression> field, + TField value, + CancellationToken cancellationToken) + where TDocument : IDocument; + + /// + /// Updates the property field with the given value update a property field in entities. + /// + /// The type representing a Document. + /// The type of the field. + /// The document filter. + /// The field selector. + /// The new value of the property field. + /// The value of the partition key. + Task UpdateOneAsync( + FilterDefinition filter, + Expression> field, + TField value, + string partitionKey) + where TDocument : IDocument; + + /// + /// Updates the property field with the given value update a property field in entities. + /// + /// The type representing a Document. + /// The type of the field. + /// The document filter. + /// The field selector. + /// The new value of the property field. + /// The value of the partition key. + /// The cancellation token. + Task UpdateOneAsync( + FilterDefinition filter, + Expression> field, + TField value, + string partitionKey, + CancellationToken cancellationToken) + where TDocument : IDocument; + + /// + /// For the entity selected by the filter, updates the property field with the given value. + /// + /// The type representing a Document. + /// The type of the field. + /// The document filter. + /// The field selector. + /// The new value of the property field. + Task UpdateOneAsync(Expression> filter, Expression> field, TField value) + where TDocument : IDocument; + + /// + /// For the entity selected by the filter, updates the property field with the given value. + /// + /// The type representing a Document. + /// The type of the field. + /// The document filter. + /// The field selector. + /// The new value of the property field. + /// The cancellation token. + Task UpdateOneAsync( + Expression> filter, + Expression> field, + TField value, + CancellationToken cancellationToken) + where TDocument : IDocument; + + /// + /// For the entity selected by the filter, updates the property field with the given value. /// /// The type representing a Document. /// The type of the field. @@ -123,43 +362,15 @@ namespace MongoDbGenericRepository /// The field selector. /// The new value of the property field. /// The partition key for the document. - Task UpdateManyAsync(Expression> filter, Expression> field, TField value, string partitionKey = null) + Task UpdateOneAsync( + Expression> filter, + Expression> field, + TField value, + string partitionKey) where TDocument : IDocument; /// - /// For the entities selected by the filter, updates the property field with the given value. - /// - /// The type representing a Document. - /// The type of the field. - /// The document filter. - /// The field selector. - /// The new value of the property field. - /// The value of the partition key. - Task UpdateManyAsync(FilterDefinition filter, Expression> field, TField value, string partitionKey = null) - where TDocument : IDocument; - - /// - /// For the entities selected by the filter, applies the update you have defined in MongoDb. - /// - /// The type representing a Document. - /// The document filter. - /// The update definition to apply. - /// The value of the partition key. - Task UpdateManyAsync(FilterDefinition filter, UpdateDefinition updateDefinition, string partitionKey = null) - where TDocument : IDocument; - - /// - /// For the entities selected by the filter, applies the update you have defined in MongoDb. - /// - /// The type representing a Document. - /// The document filter. - /// The update definition to apply. - /// The value of the partition key. - Task UpdateManyAsync(Expression> filter, UpdateDefinition updateDefinition, string partitionKey = null) - where TDocument : IDocument; - - /// - /// For the entities selected by the filter, updates the property field with the given value. + /// For the entity selected by the filter, updates the property field with the given value. /// /// The type representing a Document. /// The type of the field. @@ -167,11 +378,105 @@ namespace MongoDbGenericRepository /// The field selector. /// The new value of the property field. /// The partition key for the document. - long UpdateMany(Expression> filter, Expression> field, TField value, string partitionKey = null) + /// The cancellation token. + Task UpdateOneAsync( + Expression> filter, + Expression> field, + TField value, + string partitionKey, + CancellationToken cancellationToken) where TDocument : IDocument; /// - /// For the entities selected by the filter, updates the property field with the given value. + /// For the entities selected by the filter, updates the property field with the given value. + /// + /// The type representing a Document. + /// The type of the field. + /// The document filter. + /// The field selector. + /// The new value of the property field. + Task UpdateManyAsync(Expression> filter, Expression> field, TField value) + where TDocument : IDocument; + + /// + /// For the entities selected by the filter, updates the property field with the given value. + /// + /// The type representing a Document. + /// The type of the field. + /// The document filter. + /// The field selector. + /// The new value of the property field. + /// The cancellation token. + Task UpdateManyAsync( + Expression> filter, + Expression> field, + TField value, + CancellationToken cancellationToken) + where TDocument : IDocument; + + /// + /// For the entities selected by the filter, updates the property field with the given value. + /// + /// The type representing a Document. + /// The type of the field. + /// The document filter. + /// The field selector. + /// The new value of the property field. + /// The partition key for the document. + Task UpdateManyAsync( + Expression> filter, + Expression> field, + TField value, + string partitionKey) + where TDocument : IDocument; + + /// + /// For the entities selected by the filter, updates the property field with the given value. + /// + /// The type representing a Document. + /// The type of the field. + /// The document filter. + /// The field selector. + /// The new value of the property field. + /// The partition key for the document. + /// The cancellation token. + Task UpdateManyAsync( + Expression> filter, + Expression> field, + TField value, + string partitionKey, + CancellationToken cancellationToken) + where TDocument : IDocument; + + /// + /// For the entities selected by the filter, updates the property field with the given value. + /// + /// The type representing a Document. + /// The type of the field. + /// The document filter. + /// The field selector. + /// The new value of the property field. + Task UpdateManyAsync(FilterDefinition filter, Expression> field, TField value) + where TDocument : IDocument; + + /// + /// For the entities selected by the filter, updates the property field with the given value. + /// + /// The type representing a Document. + /// The type of the field. + /// The document filter. + /// The field selector. + /// The new value of the property field. + /// The cancellation token. + Task UpdateManyAsync( + FilterDefinition filter, + Expression> field, + TField value, + CancellationToken cancellationToken) + where TDocument : IDocument; + + /// + /// For the entities selected by the filter, updates the property field with the given value. /// /// The type representing a Document. /// The type of the field. @@ -179,27 +484,339 @@ namespace MongoDbGenericRepository /// The field selector. /// The new value of the property field. /// The value of the partition key. - long UpdateMany(FilterDefinition filter, Expression> field, TField value, string partitionKey = null) + Task UpdateManyAsync( + FilterDefinition filter, + Expression> field, + TField value, + string partitionKey) where TDocument : IDocument; /// - /// For the entities selected by the filter, applies the update you have defined in MongoDb. + /// For the entities selected by the filter, updates the property field with the given value. + /// + /// The type representing a Document. + /// The type of the field. + /// The document filter. + /// The field selector. + /// The new value of the property field. + /// The value of the partition key. + /// The cancellation token. + Task UpdateManyAsync( + FilterDefinition filter, + Expression> field, + TField value, + string partitionKey, + CancellationToken cancellationToken) + where TDocument : IDocument; + + /// + /// For the entities selected by the filter, applies the update you have defined in MongoDb. + /// + /// The type representing a Document. + /// The document filter. + /// The update definition to apply. + Task UpdateManyAsync(FilterDefinition filter, UpdateDefinition updateDefinition) + where TDocument : IDocument; + + /// + /// For the entities selected by the filter, applies the update you have defined in MongoDb. + /// + /// The type representing a Document. + /// The document filter. + /// The update definition to apply. + /// The cancellation token. + Task UpdateManyAsync( + FilterDefinition filter, + UpdateDefinition updateDefinition, + CancellationToken cancellationToken) + where TDocument : IDocument; + + /// + /// For the entities selected by the filter, applies the update you have defined in MongoDb. /// /// The type representing a Document. /// The document filter. /// The update definition to apply. /// The value of the partition key. - long UpdateMany(FilterDefinition filter, UpdateDefinition updateDefinition, string partitionKey = null) + Task UpdateManyAsync(FilterDefinition filter, UpdateDefinition updateDefinition, string partitionKey) where TDocument : IDocument; /// - /// For the entities selected by the filter, applies the update you have defined in MongoDb. + /// For the entities selected by the filter, applies the update you have defined in MongoDb. /// /// The type representing a Document. /// The document filter. /// The update definition to apply. /// The value of the partition key. - long UpdateMany(Expression> filter, UpdateDefinition updateDefinition, string partitionKey = null) + /// The cancellation token. + Task UpdateManyAsync( + FilterDefinition filter, + UpdateDefinition updateDefinition, + string partitionKey, + CancellationToken cancellationToken) + where TDocument : IDocument; + + /// + /// For the entities selected by the filter, applies the update you have defined in MongoDb. + /// + /// The type representing a Document. + /// The document filter. + /// The update definition to apply. + Task UpdateManyAsync(Expression> filter, UpdateDefinition updateDefinition) + where TDocument : IDocument; + + /// + /// For the entities selected by the filter, applies the update you have defined in MongoDb. + /// + /// The type representing a Document. + /// The document filter. + /// The update definition to apply. + /// The cancellation token. + Task UpdateManyAsync( + Expression> filter, + UpdateDefinition updateDefinition, + CancellationToken cancellationToken) + where TDocument : IDocument; + + /// + /// For the entities selected by the filter, applies the update you have defined in MongoDb. + /// + /// The type representing a Document. + /// The document filter. + /// The update definition to apply. + /// The value of the partition key. + Task UpdateManyAsync(Expression> filter, UpdateDefinition updateDefinition, string partitionKey) + where TDocument : IDocument; + + /// + /// For the entities selected by the filter, applies the update you have defined in MongoDb. + /// + /// The type representing a Document. + /// The document filter. + /// The update definition to apply. + /// The value of the partition key. + /// The cancellation token. + Task UpdateManyAsync( + Expression> filter, + UpdateDefinition updateDefinition, + string partitionKey, + CancellationToken cancellationToken) + where TDocument : IDocument; + + /// + /// For the entities selected by the filter, updates the property field with the given value. + /// + /// The type representing a Document. + /// The type of the field. + /// The document filter. + /// The field selector. + /// The new value of the property field. + long UpdateMany( + Expression> filter, + Expression> field, + TField value) + where TDocument : IDocument; + + /// + /// For the entities selected by the filter, updates the property field with the given value. + /// + /// The type representing a Document. + /// The type of the field. + /// The document filter. + /// The field selector. + /// The new value of the property field. + /// The cancellation token. + long UpdateMany( + Expression> filter, + Expression> field, + TField value, + CancellationToken cancellationToken) + where TDocument : IDocument; + + /// + /// For the entities selected by the filter, updates the property field with the given value. + /// + /// The type representing a Document. + /// The type of the field. + /// The document filter. + /// The field selector. + /// The new value of the property field. + /// The partition key for the document. + long UpdateMany( + Expression> filter, + Expression> field, + TField value, + string partitionKey) + where TDocument : IDocument; + + /// + /// For the entities selected by the filter, updates the property field with the given value. + /// + /// The type representing a Document. + /// The type of the field. + /// The document filter. + /// The field selector. + /// The new value of the property field. + /// The partition key for the document. + /// The cancellation token. + long UpdateMany( + Expression> filter, + Expression> field, + TField value, + string partitionKey, + CancellationToken cancellationToken) + where TDocument : IDocument; + + /// + /// For the entities selected by the filter, updates the property field with the given value. + /// + /// The type representing a Document. + /// The type of the field. + /// The document filter. + /// The field selector. + /// The new value of the property field. + long UpdateMany( + FilterDefinition filter, + Expression> field, + TField value) + where TDocument : IDocument; + + /// + /// For the entities selected by the filter, updates the property field with the given value. + /// + /// The type representing a Document. + /// The type of the field. + /// The document filter. + /// The field selector. + /// The new value of the property field. + /// The cancellation token. + long UpdateMany( + FilterDefinition filter, + Expression> field, + TField value, + CancellationToken cancellationToken) + where TDocument : IDocument; + + /// + /// For the entities selected by the filter, updates the property field with the given value. + /// + /// The type representing a Document. + /// The type of the field. + /// The document filter. + /// The field selector. + /// The new value of the property field. + /// The value of the partition key. + long UpdateMany( + FilterDefinition filter, + Expression> field, + TField value, + string partitionKey) + where TDocument : IDocument; + + /// + /// For the entities selected by the filter, updates the property field with the given value. + /// + /// The type representing a Document. + /// The type of the field. + /// The document filter. + /// The field selector. + /// The new value of the property field. + /// The value of the partition key. + /// The cancellation token. + long UpdateMany( + FilterDefinition filter, + Expression> field, + TField value, + string partitionKey, + CancellationToken cancellationToken) + where TDocument : IDocument; + + /// + /// For the entities selected by the filter, applies the update you have defined in MongoDb. + /// + /// The type representing a Document. + /// The document filter. + /// The update definition to apply. + long UpdateMany(FilterDefinition filter, UpdateDefinition updateDefinition) + where TDocument : IDocument; + + /// + /// For the entities selected by the filter, applies the update you have defined in MongoDb. + /// + /// The type representing a Document. + /// The document filter. + /// The update definition to apply. + /// The cancellation token. + long UpdateMany(FilterDefinition filter, UpdateDefinition updateDefinition, CancellationToken cancellationToken) + where TDocument : IDocument; + + /// + /// For the entities selected by the filter, applies the update you have defined in MongoDb. + /// + /// The type representing a Document. + /// The document filter. + /// The update definition to apply. + /// The value of the partition key. + long UpdateMany(FilterDefinition filter, UpdateDefinition updateDefinition, string partitionKey) + where TDocument : IDocument; + + /// + /// For the entities selected by the filter, applies the update you have defined in MongoDb. + /// + /// The type representing a Document. + /// The document filter. + /// The update definition to apply. + /// The value of the partition key. + /// The cancellation token. + long UpdateMany( + FilterDefinition filter, + UpdateDefinition updateDefinition, + string partitionKey, + CancellationToken cancellationToken) + where TDocument : IDocument; + + /// + /// For the entities selected by the filter, applies the update you have defined in MongoDb. + /// + /// The type representing a Document. + /// The document filter. + /// The update definition to apply. + long UpdateMany(Expression> filter, UpdateDefinition updateDefinition) + where TDocument : IDocument; + + /// + /// For the entities selected by the filter, applies the update you have defined in MongoDb. + /// + /// The type representing a Document. + /// The document filter. + /// The update definition to apply. + /// The cancellation token. + long UpdateMany(Expression> filter, UpdateDefinition updateDefinition, CancellationToken cancellationToken) + where TDocument : IDocument; + + /// + /// For the entities selected by the filter, applies the update you have defined in MongoDb. + /// + /// The type representing a Document. + /// The document filter. + /// The update definition to apply. + /// The value of the partition key. + long UpdateMany(Expression> filter, UpdateDefinition updateDefinition, string partitionKey) + where TDocument : IDocument; + + /// + /// For the entities selected by the filter, applies the update you have defined in MongoDb. + /// + /// The type representing a Document. + /// The document filter. + /// The update definition to apply. + /// The value of the partition key. + /// The cancellation token. + long UpdateMany( + Expression> filter, + UpdateDefinition updateDefinition, + string partitionKey, + CancellationToken cancellationToken) where TDocument : IDocument; } } \ No newline at end of file