reformatting

This commit is contained in:
Sean Garrett
2023-07-06 13:00:55 +01:00
parent c70727212e
commit 26b71ff76e
24 changed files with 3041 additions and 980 deletions
@@ -9,12 +9,12 @@ using MongoDbGenericRepository.Models;
namespace MongoDbGenericRepository.DataAccess.Update
{
/// <summary>
/// A interface for updating documents in MongoDb.
/// A interface for updating documents in MongoDb.
/// </summary>
public interface IMongoDbUpdater : IDataAccessBase
{
/// <summary>
/// Asynchronously Updates a document.
/// Asynchronously Updates a document.
/// </summary>
/// <typeparam name="TDocument">The type representing a Document.</typeparam>
/// <typeparam name="TKey">The type of the primary key for a Document.</typeparam>
@@ -25,19 +25,22 @@ namespace MongoDbGenericRepository.DataAccess.Update
where TKey : IEquatable<TKey>;
/// <summary>
/// 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.
/// </summary>
/// <typeparam name="TDocument">The type representing a Document.</typeparam>
/// <typeparam name="TKey">The type of the primary key for a Document.</typeparam>
/// <param name="documentToModify">The document you want to modify.</param>
/// <param name="update">The update definition for the document.</param>
/// <param name="cancellationToken">An optional cancellation token.</param>
Task<bool> UpdateOneAsync<TDocument, TKey>(TDocument documentToModify, UpdateDefinition<TDocument> update, CancellationToken cancellationToken = default)
Task<bool> UpdateOneAsync<TDocument, TKey>(
TDocument documentToModify,
UpdateDefinition<TDocument> update,
CancellationToken cancellationToken = default)
where TDocument : IDocument<TKey>
where TKey : IEquatable<TKey>;
/// <summary>
/// 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.
/// </summary>
/// <typeparam name="TDocument">The type representing a Document.</typeparam>
/// <typeparam name="TKey">The type of the primary key for a Document.</typeparam>
@@ -46,12 +49,16 @@ namespace MongoDbGenericRepository.DataAccess.Update
/// <param name="field">The field selector.</param>
/// <param name="value">The new value of the property field.</param>
/// <param name="cancellationToken">An optional cancellation token.</param>
Task<bool> UpdateOneAsync<TDocument, TKey, TField>(TDocument documentToModify, Expression<Func<TDocument, TField>> field, TField value, CancellationToken cancellationToken = default)
Task<bool> UpdateOneAsync<TDocument, TKey, TField>(
TDocument documentToModify,
Expression<Func<TDocument, TField>> field,
TField value,
CancellationToken cancellationToken = default)
where TDocument : IDocument<TKey>
where TKey : IEquatable<TKey>;
/// <summary>
/// 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.
/// </summary>
/// <typeparam name="TDocument">The type representing a Document.</typeparam>
/// <typeparam name="TKey">The type of the primary key for a Document.</typeparam>
@@ -61,12 +68,17 @@ namespace MongoDbGenericRepository.DataAccess.Update
/// <param name="value">The new value of the property field.</param>
/// <param name="partitionKey">The value of the partition key.</param>
/// <param name="cancellationToken">An optional cancellation token.</param>
Task<bool> UpdateOneAsync<TDocument, TKey, TField>(FilterDefinition<TDocument> filter, Expression<Func<TDocument, TField>> field, TField value, string partitionKey = null, CancellationToken cancellationToken = default)
Task<bool> UpdateOneAsync<TDocument, TKey, TField>(
FilterDefinition<TDocument> filter,
Expression<Func<TDocument, TField>> field,
TField value,
string partitionKey = null,
CancellationToken cancellationToken = default)
where TDocument : IDocument<TKey>
where TKey : IEquatable<TKey>;
/// <summary>
/// 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.
/// </summary>
/// <typeparam name="TDocument">The type representing a Document.</typeparam>
/// <typeparam name="TKey">The type of the primary key for a Document.</typeparam>
@@ -76,12 +88,17 @@ namespace MongoDbGenericRepository.DataAccess.Update
/// <param name="value">The new value of the property field.</param>
/// <param name="partitionKey">The partition key for the document.</param>
/// <param name="cancellationToken">An optional cancellation token.</param>
Task<bool> UpdateOneAsync<TDocument, TKey, TField>(Expression<Func<TDocument, bool>> filter, Expression<Func<TDocument, TField>> field, TField value, string partitionKey = null, CancellationToken cancellationToken = default)
Task<bool> UpdateOneAsync<TDocument, TKey, TField>(
Expression<Func<TDocument, bool>> filter,
Expression<Func<TDocument, TField>> field,
TField value,
string partitionKey = null,
CancellationToken cancellationToken = default)
where TDocument : IDocument<TKey>
where TKey : IEquatable<TKey>;
/// <summary>
/// Updates a document.
/// Updates a document.
/// </summary>
/// <typeparam name="TDocument">The type representing a Document.</typeparam>
/// <typeparam name="TKey">The type of the primary key for a Document.</typeparam>
@@ -94,7 +111,7 @@ namespace MongoDbGenericRepository.DataAccess.Update
where TKey : IEquatable<TKey>;
/// <summary>
/// Updates a document.
/// Updates a document.
/// </summary>
/// <typeparam name="TDocument">The type representing a Document.</typeparam>
/// <typeparam name="TKey">The type of the primary key for a Document.</typeparam>
@@ -103,12 +120,16 @@ namespace MongoDbGenericRepository.DataAccess.Update
/// <param name="update">The update definition.</param>
/// <param name="cancellationToken">The optional cancellation token.</param>
/// <returns></returns>
Task<bool> UpdateOneAsync<TDocument, TKey>(IClientSessionHandle session, TDocument documentToModify, UpdateDefinition<TDocument> update, CancellationToken cancellationToken = default)
Task<bool> UpdateOneAsync<TDocument, TKey>(
IClientSessionHandle session,
TDocument documentToModify,
UpdateDefinition<TDocument> update,
CancellationToken cancellationToken = default)
where TDocument : IDocument<TKey>
where TKey : IEquatable<TKey>;
/// <summary>
/// Updates a document.
/// Updates a document.
/// </summary>
/// <typeparam name="TDocument">The type representing a Document.</typeparam>
/// <typeparam name="TKey">The type of the primary key for a Document.</typeparam>
@@ -119,12 +140,17 @@ namespace MongoDbGenericRepository.DataAccess.Update
/// <param name="value">The value of the field.</param>
/// <param name="cancellationToken">The optional cancellation token.</param>
/// <returns></returns>
Task<bool> UpdateOneAsync<TDocument, TKey, TField>(IClientSessionHandle session, TDocument documentToModify, Expression<Func<TDocument, TField>> field, TField value, CancellationToken cancellationToken = default)
Task<bool> UpdateOneAsync<TDocument, TKey, TField>(
IClientSessionHandle session,
TDocument documentToModify,
Expression<Func<TDocument, TField>> field,
TField value,
CancellationToken cancellationToken = default)
where TDocument : IDocument<TKey>
where TKey : IEquatable<TKey>;
/// <summary>
/// Updates a document.
/// Updates a document.
/// </summary>
/// <typeparam name="TDocument">The type representing a Document.</typeparam>
/// <typeparam name="TKey">The type of the primary key for a Document.</typeparam>
@@ -136,12 +162,18 @@ namespace MongoDbGenericRepository.DataAccess.Update
/// <param name="partitionKey">The optional partition key.</param>
/// <param name="cancellationToken">The optional cancellation token.</param>
/// <returns></returns>
Task<bool> UpdateOneAsync<TDocument, TKey, TField>(IClientSessionHandle session, FilterDefinition<TDocument> filter, Expression<Func<TDocument, TField>> field, TField value, string partitionKey = null, CancellationToken cancellationToken = default)
Task<bool> UpdateOneAsync<TDocument, TKey, TField>(
IClientSessionHandle session,
FilterDefinition<TDocument> filter,
Expression<Func<TDocument, TField>> field,
TField value,
string partitionKey = null,
CancellationToken cancellationToken = default)
where TDocument : IDocument<TKey>
where TKey : IEquatable<TKey>;
/// <summary>
/// Updates a document.
/// Updates a document.
/// </summary>
/// <typeparam name="TDocument">The type representing a Document.</typeparam>
/// <typeparam name="TKey">The type of the primary key for a Document.</typeparam>
@@ -153,12 +185,18 @@ namespace MongoDbGenericRepository.DataAccess.Update
/// <param name="partitionKey">The optional partition key.</param>
/// <param name="cancellationToken">The optional cancellation token.</param>
/// <returns></returns>
Task<bool> UpdateOneAsync<TDocument, TKey, TField>(IClientSessionHandle session, Expression<Func<TDocument, bool>> filter, Expression<Func<TDocument, TField>> field, TField value, string partitionKey = null, CancellationToken cancellationToken = default)
Task<bool> UpdateOneAsync<TDocument, TKey, TField>(
IClientSessionHandle session,
Expression<Func<TDocument, bool>> filter,
Expression<Func<TDocument, TField>> field,
TField value,
string partitionKey = null,
CancellationToken cancellationToken = default)
where TDocument : IDocument<TKey>
where TKey : IEquatable<TKey>;
/// <summary>
/// Updates a document.
/// Updates a document.
/// </summary>
/// <typeparam name="TDocument">The type representing a Document.</typeparam>
/// <typeparam name="TKey">The type of the primary key for a Document.</typeparam>
@@ -169,7 +207,7 @@ namespace MongoDbGenericRepository.DataAccess.Update
where TKey : IEquatable<TKey>;
/// <summary>
/// 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.
/// </summary>
/// <typeparam name="TDocument">The type representing a Document.</typeparam>
/// <typeparam name="TKey">The type of the primary key for a Document.</typeparam>
@@ -181,7 +219,7 @@ namespace MongoDbGenericRepository.DataAccess.Update
where TKey : IEquatable<TKey>;
/// <summary>
/// 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.
/// </summary>
/// <typeparam name="TDocument">The type representing a Document.</typeparam>
/// <typeparam name="TKey">The type of the primary key for a Document.</typeparam>
@@ -190,12 +228,16 @@ namespace MongoDbGenericRepository.DataAccess.Update
/// <param name="field">The field selector.</param>
/// <param name="value">The new value of the property field.</param>
/// <param name="cancellationToken">The optional cancellation token.</param>
bool UpdateOne<TDocument, TKey, TField>(TDocument documentToModify, Expression<Func<TDocument, TField>> field, TField value, CancellationToken cancellationToken = default)
bool UpdateOne<TDocument, TKey, TField>(
TDocument documentToModify,
Expression<Func<TDocument, TField>> field,
TField value,
CancellationToken cancellationToken = default)
where TDocument : IDocument<TKey>
where TKey : IEquatable<TKey>;
/// <summary>
/// Updates the property field with the given value.
/// Updates the property field with the given value.
/// </summary>
/// <typeparam name="TDocument">The type representing a Document.</typeparam>
/// <typeparam name="TKey">The type of the primary key for a Document.</typeparam>
@@ -205,12 +247,17 @@ namespace MongoDbGenericRepository.DataAccess.Update
/// <param name="value">The new value of the property field.</param>
/// <param name="partitionKey">The value of the partition key.</param>
/// <param name="cancellationToken">The optional cancellation token.</param>
bool UpdateOne<TDocument, TKey, TField>(FilterDefinition<TDocument> filter, Expression<Func<TDocument, TField>> field, TField value, string partitionKey = null, CancellationToken cancellationToken = default)
bool UpdateOne<TDocument, TKey, TField>(
FilterDefinition<TDocument> filter,
Expression<Func<TDocument, TField>> field,
TField value,
string partitionKey = null,
CancellationToken cancellationToken = default)
where TDocument : IDocument<TKey>
where TKey : IEquatable<TKey>;
/// <summary>
/// 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.
/// </summary>
/// <typeparam name="TDocument">The type representing a Document.</typeparam>
/// <typeparam name="TKey">The type of the primary key for a Document.</typeparam>
@@ -220,12 +267,17 @@ namespace MongoDbGenericRepository.DataAccess.Update
/// <param name="value">The new value of the property field.</param>
/// <param name="partitionKey">The partition key for the document.</param>
/// <param name="cancellationToken">The optional cancellation token.</param>
bool UpdateOne<TDocument, TKey, TField>(Expression<Func<TDocument, bool>> filter, Expression<Func<TDocument, TField>> field, TField value, string partitionKey = null, CancellationToken cancellationToken = default)
bool UpdateOne<TDocument, TKey, TField>(
Expression<Func<TDocument, bool>> filter,
Expression<Func<TDocument, TField>> field,
TField value,
string partitionKey = null,
CancellationToken cancellationToken = default)
where TDocument : IDocument<TKey>
where TKey : IEquatable<TKey>;
/// <summary>
/// Updates a document.
/// Updates a document.
/// </summary>
/// <typeparam name="TDocument">The type representing a Document.</typeparam>
/// <typeparam name="TKey">The type of the primary key for a Document.</typeparam>
@@ -238,7 +290,7 @@ namespace MongoDbGenericRepository.DataAccess.Update
where TKey : IEquatable<TKey>;
/// <summary>
/// Updates a document.
/// Updates a document.
/// </summary>
/// <typeparam name="TDocument">The type representing a Document.</typeparam>
/// <typeparam name="TKey">The type of the primary key for a Document.</typeparam>
@@ -247,12 +299,16 @@ namespace MongoDbGenericRepository.DataAccess.Update
/// <param name="update">The update definition.</param>
/// <param name="cancellationToken">The optional cancellation token.</param>
/// <returns></returns>
bool UpdateOne<TDocument, TKey>(IClientSessionHandle session, TDocument documentToModify, UpdateDefinition<TDocument> update, CancellationToken cancellationToken = default)
bool UpdateOne<TDocument, TKey>(
IClientSessionHandle session,
TDocument documentToModify,
UpdateDefinition<TDocument> update,
CancellationToken cancellationToken = default)
where TDocument : IDocument<TKey>
where TKey : IEquatable<TKey>;
/// <summary>
/// Updates a document.
/// Updates a document.
/// </summary>
/// <typeparam name="TDocument">The type representing a Document.</typeparam>
/// <typeparam name="TKey">The type of the primary key for a Document.</typeparam>
@@ -263,12 +319,17 @@ namespace MongoDbGenericRepository.DataAccess.Update
/// <param name="value">The value of the field.</param>
/// <param name="cancellationToken">The optional cancellation token.</param>
/// <returns></returns>
bool UpdateOne<TDocument, TKey, TField>(IClientSessionHandle session, TDocument documentToModify, Expression<Func<TDocument, TField>> field, TField value, CancellationToken cancellationToken = default)
bool UpdateOne<TDocument, TKey, TField>(
IClientSessionHandle session,
TDocument documentToModify,
Expression<Func<TDocument, TField>> field,
TField value,
CancellationToken cancellationToken = default)
where TDocument : IDocument<TKey>
where TKey : IEquatable<TKey>;
/// <summary>
/// Updates a document.
/// Updates a document.
/// </summary>
/// <typeparam name="TDocument">The type representing a Document.</typeparam>
/// <typeparam name="TKey">The type of the primary key for a Document.</typeparam>
@@ -280,12 +341,18 @@ namespace MongoDbGenericRepository.DataAccess.Update
/// <param name="partitionKey">The optional partition key.</param>
/// <param name="cancellationToken">The optional cancellation token.</param>
/// <returns></returns>
bool UpdateOne<TDocument, TKey, TField>(IClientSessionHandle session, FilterDefinition<TDocument> filter, Expression<Func<TDocument, TField>> field, TField value, string partitionKey = null, CancellationToken cancellationToken = default)
bool UpdateOne<TDocument, TKey, TField>(
IClientSessionHandle session,
FilterDefinition<TDocument> filter,
Expression<Func<TDocument, TField>> field,
TField value,
string partitionKey = null,
CancellationToken cancellationToken = default)
where TDocument : IDocument<TKey>
where TKey : IEquatable<TKey>;
/// <summary>
/// Updates a document.
/// Updates a document.
/// </summary>
/// <typeparam name="TDocument">The type representing a Document.</typeparam>
/// <typeparam name="TKey">The type of the primary key for a Document.</typeparam>
@@ -297,12 +364,18 @@ namespace MongoDbGenericRepository.DataAccess.Update
/// <param name="partitionKey">The optional partition key.</param>
/// <param name="cancellationToken">The optional cancellation token.</param>
/// <returns></returns>
bool UpdateOne<TDocument, TKey, TField>(IClientSessionHandle session, Expression<Func<TDocument, bool>> filter, Expression<Func<TDocument, TField>> field, TField value, string partitionKey = null, CancellationToken cancellationToken = default)
bool UpdateOne<TDocument, TKey, TField>(
IClientSessionHandle session,
Expression<Func<TDocument, bool>> filter,
Expression<Func<TDocument, TField>> field,
TField value,
string partitionKey = null,
CancellationToken cancellationToken = default)
where TDocument : IDocument<TKey>
where TKey : IEquatable<TKey>;
/// <summary>
/// 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.
/// </summary>
/// <typeparam name="TDocument">The type representing a Document.</typeparam>
/// <typeparam name="TKey">The type of the primary key for a Document.</typeparam>
@@ -312,12 +385,17 @@ namespace MongoDbGenericRepository.DataAccess.Update
/// <param name="value">The new value of the property field.</param>
/// <param name="partitionKey">The partition key for the document.</param>
/// <param name="cancellationToken">The optional cancellation token.</param>
Task<long> UpdateManyAsync<TDocument, TKey, TField>(Expression<Func<TDocument, bool>> filter, Expression<Func<TDocument, TField>> field, TField value, string partitionKey = null, CancellationToken cancellationToken = default)
Task<long> UpdateManyAsync<TDocument, TKey, TField>(
Expression<Func<TDocument, bool>> filter,
Expression<Func<TDocument, TField>> field,
TField value,
string partitionKey = null,
CancellationToken cancellationToken = default)
where TDocument : IDocument<TKey>
where TKey : IEquatable<TKey>;
/// <summary>
/// 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.
/// </summary>
/// <typeparam name="TDocument">The type representing a Document.</typeparam>
/// <typeparam name="TKey">The type of the primary key for a Document.</typeparam>
@@ -327,12 +405,17 @@ namespace MongoDbGenericRepository.DataAccess.Update
/// <param name="value">The new value of the property field.</param>
/// <param name="partitionKey">The value of the partition key.</param>
/// <param name="cancellationToken">The optional cancellation token.</param>
Task<long> UpdateManyAsync<TDocument, TKey, TField>(FilterDefinition<TDocument> filter, Expression<Func<TDocument, TField>> field, TField value, string partitionKey = null, CancellationToken cancellationToken = default)
Task<long> UpdateManyAsync<TDocument, TKey, TField>(
FilterDefinition<TDocument> filter,
Expression<Func<TDocument, TField>> field,
TField value,
string partitionKey = null,
CancellationToken cancellationToken = default)
where TDocument : IDocument<TKey>
where TKey : IEquatable<TKey>;
/// <summary>
/// For the entities selected by the filter, apply the update definition.
/// For the entities selected by the filter, apply the update definition.
/// </summary>
/// <typeparam name="TDocument">The type representing a Document.</typeparam>
/// <typeparam name="TKey">The type of the primary key for a Document.</typeparam>
@@ -340,12 +423,16 @@ namespace MongoDbGenericRepository.DataAccess.Update
/// <param name="update">the update definition</param>
/// <param name="partitionKey">The value of the partition key.</param>
/// <param name="cancellationToken">The optional cancellation token.</param>
Task<long> UpdateManyAsync<TDocument, TKey>(Expression<Func<TDocument, bool>> filter, UpdateDefinition<TDocument> update, string partitionKey = null, CancellationToken cancellationToken = default)
Task<long> UpdateManyAsync<TDocument, TKey>(
Expression<Func<TDocument, bool>> filter,
UpdateDefinition<TDocument> update,
string partitionKey = null,
CancellationToken cancellationToken = default)
where TDocument : IDocument<TKey>
where TKey : IEquatable<TKey>;
/// <summary>
/// For the entities selected by the filter, apply the update definition.
/// For the entities selected by the filter, apply the update definition.
/// </summary>
/// <typeparam name="TDocument">The type representing a Document.</typeparam>
/// <typeparam name="TKey">The type of the primary key for a Document.</typeparam>
@@ -353,12 +440,16 @@ namespace MongoDbGenericRepository.DataAccess.Update
/// <param name="updateDefinition">The update definition.</param>
/// <param name="partitionKey">The value of the partition key.</param>
/// <param name="cancellationToken">The optional cancellation token.</param>
Task<long> UpdateManyAsync<TDocument, TKey>(FilterDefinition<TDocument> filter, UpdateDefinition<TDocument> updateDefinition, string partitionKey = null, CancellationToken cancellationToken = default)
Task<long> UpdateManyAsync<TDocument, TKey>(
FilterDefinition<TDocument> filter,
UpdateDefinition<TDocument> updateDefinition,
string partitionKey = null,
CancellationToken cancellationToken = default)
where TDocument : IDocument<TKey>
where TKey : IEquatable<TKey>;
/// <summary>
/// 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.
/// </summary>
/// <typeparam name="TDocument">The type representing a Document.</typeparam>
/// <typeparam name="TKey">The type of the primary key for a Document.</typeparam>
@@ -368,12 +459,17 @@ namespace MongoDbGenericRepository.DataAccess.Update
/// <param name="value">The new value of the property field.</param>
/// <param name="partitionKey">The partition key for the document.</param>
/// <param name="cancellationToken">The optional cancellation token.</param>
long UpdateMany<TDocument, TKey, TField>(Expression<Func<TDocument, bool>> filter, Expression<Func<TDocument, TField>> field, TField value, string partitionKey = null, CancellationToken cancellationToken = default)
long UpdateMany<TDocument, TKey, TField>(
Expression<Func<TDocument, bool>> filter,
Expression<Func<TDocument, TField>> field,
TField value,
string partitionKey = null,
CancellationToken cancellationToken = default)
where TDocument : IDocument<TKey>
where TKey : IEquatable<TKey>;
/// <summary>
/// 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.
/// </summary>
/// <typeparam name="TDocument">The type representing a Document.</typeparam>
/// <typeparam name="TKey">The type of the primary key for a Document.</typeparam>
@@ -383,12 +479,17 @@ namespace MongoDbGenericRepository.DataAccess.Update
/// <param name="value">The new value of the property field.</param>
/// <param name="partitionKey">The value of the partition key.</param>
/// <param name="cancellationToken">The optional cancellation token.</param>
long UpdateMany<TDocument, TKey, TField>(FilterDefinition<TDocument> filter, Expression<Func<TDocument, TField>> field, TField value, string partitionKey = null, CancellationToken cancellationToken = default)
long UpdateMany<TDocument, TKey, TField>(
FilterDefinition<TDocument> filter,
Expression<Func<TDocument, TField>> field,
TField value,
string partitionKey = null,
CancellationToken cancellationToken = default)
where TDocument : IDocument<TKey>
where TKey : IEquatable<TKey>;
/// <summary>
/// For the entities selected by the filter, apply the update definition.
/// For the entities selected by the filter, apply the update definition.
/// </summary>
/// <typeparam name="TDocument">The type representing a Document.</typeparam>
/// <typeparam name="TKey">The type of the primary key for a Document.</typeparam>
@@ -396,7 +497,11 @@ namespace MongoDbGenericRepository.DataAccess.Update
/// <param name="updateDefinition">The update definition.</param>
/// <param name="partitionKey">The value of the partition key.</param>
/// <param name="cancellationToken">The optional cancellation token.</param>
long UpdateMany<TDocument, TKey>(FilterDefinition<TDocument> filter, UpdateDefinition<TDocument> updateDefinition, string partitionKey = null, CancellationToken cancellationToken = default)
long UpdateMany<TDocument, TKey>(
FilterDefinition<TDocument> filter,
UpdateDefinition<TDocument> updateDefinition,
string partitionKey = null,
CancellationToken cancellationToken = default)
where TDocument : IDocument<TKey>
where TKey : IEquatable<TKey>;
}
@@ -1,23 +1,26 @@
using MongoDB.Driver;
using MongoDbGenericRepository.Models;
using System;
using System;
using System.Linq.Expressions;
using System.Threading;
using System.Threading.Tasks;
using MongoDB.Driver;
using MongoDbGenericRepository.Models;
namespace MongoDbGenericRepository.DataAccess.Update
{
public partial class MongoDbUpdater
{
/// <inheritdoc cref="IMongoDbUpdater" />
public virtual async Task<bool> UpdateOneAsync<TDocument, TKey>(IClientSessionHandle session, TDocument modifiedDocument, CancellationToken cancellationToken = default)
public virtual async Task<bool> UpdateOneAsync<TDocument, TKey>(
IClientSessionHandle session,
TDocument modifiedDocument,
CancellationToken cancellationToken = default)
where TDocument : IDocument<TKey>
where TKey : IEquatable<TKey>
{
var filter = Builders<TDocument>.Filter.Eq("Id", modifiedDocument.Id);
var updateRes = await HandlePartitioned<TDocument, TKey>(modifiedDocument)
.ReplaceOneAsync(session, filter, modifiedDocument, cancellationToken: cancellationToken)
.ConfigureAwait(false);
.ReplaceOneAsync(session, filter, modifiedDocument, cancellationToken: cancellationToken)
.ConfigureAwait(false);
return updateRes.ModifiedCount == 1;
}
@@ -27,22 +30,32 @@ namespace MongoDbGenericRepository.DataAccess.Update
where TKey : IEquatable<TKey>
{
var filter = Builders<TDocument>.Filter.Eq("Id", modifiedDocument.Id);
var updateRes = HandlePartitioned<TDocument, TKey>(modifiedDocument).ReplaceOne(session, filter, modifiedDocument, cancellationToken: cancellationToken);
var updateRes = HandlePartitioned<TDocument, TKey>(modifiedDocument)
.ReplaceOne(session, filter, modifiedDocument, cancellationToken: cancellationToken);
return updateRes.ModifiedCount == 1;
}
/// <inheritdoc cref="IMongoDbUpdater" />
public virtual async Task<bool> UpdateOneAsync<TDocument, TKey>(IClientSessionHandle session, TDocument documentToModify, UpdateDefinition<TDocument> update, CancellationToken cancellationToken = default)
public virtual async Task<bool> UpdateOneAsync<TDocument, TKey>(
IClientSessionHandle session,
TDocument documentToModify,
UpdateDefinition<TDocument> update,
CancellationToken cancellationToken = default)
where TDocument : IDocument<TKey>
where TKey : IEquatable<TKey>
{
var filter = Builders<TDocument>.Filter.Eq("Id", documentToModify.Id);
var updateRes = await HandlePartitioned<TDocument, TKey>(documentToModify).UpdateOneAsync(session, filter, update, null, cancellationToken).ConfigureAwait(false);
var updateRes = await HandlePartitioned<TDocument, TKey>(documentToModify).UpdateOneAsync(session, filter, update, null, cancellationToken)
.ConfigureAwait(false);
return updateRes.ModifiedCount == 1;
}
/// <inheritdoc cref="IMongoDbUpdater" />
public virtual bool UpdateOne<TDocument, TKey>(IClientSessionHandle session, TDocument documentToModify, UpdateDefinition<TDocument> update, CancellationToken cancellationToken = default)
public virtual bool UpdateOne<TDocument, TKey>(
IClientSessionHandle session,
TDocument documentToModify,
UpdateDefinition<TDocument> update,
CancellationToken cancellationToken = default)
where TDocument : IDocument<TKey>
where TKey : IEquatable<TKey>
{
@@ -52,40 +65,67 @@ namespace MongoDbGenericRepository.DataAccess.Update
}
/// <inheritdoc cref="IMongoDbUpdater" />
public virtual async Task<bool> UpdateOneAsync<TDocument, TKey, TField>(IClientSessionHandle session, TDocument documentToModify, Expression<Func<TDocument, TField>> field, TField value, CancellationToken cancellationToken = default)
public virtual async Task<bool> UpdateOneAsync<TDocument, TKey, TField>(
IClientSessionHandle session,
TDocument documentToModify,
Expression<Func<TDocument, TField>> field,
TField value,
CancellationToken cancellationToken = default)
where TDocument : IDocument<TKey>
where TKey : IEquatable<TKey>
{
var filter = Builders<TDocument>.Filter.Eq("Id", documentToModify.Id);
var updateRes = await HandlePartitioned<TDocument, TKey>(documentToModify)
.UpdateOneAsync(session, filter, Builders<TDocument>.Update.Set(field, value), cancellationToken: cancellationToken)
.ConfigureAwait(false);
.UpdateOneAsync(session, filter, Builders<TDocument>.Update.Set(field, value), cancellationToken: cancellationToken)
.ConfigureAwait(false);
return updateRes.ModifiedCount == 1;
}
/// <inheritdoc cref="IMongoDbUpdater" />
public virtual bool UpdateOne<TDocument, TKey, TField>(IClientSessionHandle session, TDocument documentToModify, Expression<Func<TDocument, TField>> field, TField value, CancellationToken cancellationToken = default)
public virtual bool UpdateOne<TDocument, TKey, TField>(
IClientSessionHandle session,
TDocument documentToModify,
Expression<Func<TDocument, TField>> field,
TField value,
CancellationToken cancellationToken = default)
where TDocument : IDocument<TKey>
where TKey : IEquatable<TKey>
{
var filter = Builders<TDocument>.Filter.Eq("Id", documentToModify.Id);
var updateRes = HandlePartitioned<TDocument, TKey>(documentToModify).UpdateOne(session, filter, Builders<TDocument>.Update.Set(field, value), cancellationToken: cancellationToken);
var updateRes = HandlePartitioned<TDocument, TKey>(documentToModify).UpdateOne(
session,
filter,
Builders<TDocument>.Update.Set(field, value),
cancellationToken: cancellationToken);
return updateRes.ModifiedCount == 1;
}
/// <inheritdoc cref="IMongoDbUpdater" />
public virtual async Task<bool> UpdateOneAsync<TDocument, TKey, TField>(IClientSessionHandle session, FilterDefinition<TDocument> filter, Expression<Func<TDocument, TField>> field, TField value, string partitionKey = null, CancellationToken cancellationToken = default)
public virtual async Task<bool> UpdateOneAsync<TDocument, TKey, TField>(
IClientSessionHandle session,
FilterDefinition<TDocument> filter,
Expression<Func<TDocument, TField>> field,
TField value,
string partitionKey = null,
CancellationToken cancellationToken = default)
where TDocument : IDocument<TKey>
where TKey : IEquatable<TKey>
{
var collection = string.IsNullOrEmpty(partitionKey) ? GetCollection<TDocument, TKey>() : GetCollection<TDocument, TKey>(partitionKey);
var updateRes = await collection.UpdateOneAsync(session, filter, Builders<TDocument>.Update.Set(field, value), cancellationToken: cancellationToken).ConfigureAwait(false);
var updateRes = await collection.UpdateOneAsync(session, filter, Builders<TDocument>.Update.Set(field, value), cancellationToken: cancellationToken)
.ConfigureAwait(false);
return updateRes.ModifiedCount == 1;
}
/// <inheritdoc cref="IMongoDbUpdater" />
public virtual Task<bool> UpdateOneAsync<TDocument, TKey, TField>(IClientSessionHandle session, Expression<Func<TDocument, bool>> filter, Expression<Func<TDocument, TField>> field, TField value, string partitionKey = null, CancellationToken cancellationToken = default)
public virtual Task<bool> UpdateOneAsync<TDocument, TKey, TField>(
IClientSessionHandle session,
Expression<Func<TDocument, bool>> filter,
Expression<Func<TDocument, TField>> field,
TField value,
string partitionKey = null,
CancellationToken cancellationToken = default)
where TDocument : IDocument<TKey>
where TKey : IEquatable<TKey>
{
@@ -93,7 +133,13 @@ namespace MongoDbGenericRepository.DataAccess.Update
}
/// <inheritdoc cref="IMongoDbUpdater" />
public virtual bool UpdateOne<TDocument, TKey, TField>(IClientSessionHandle session, FilterDefinition<TDocument> filter, Expression<Func<TDocument, TField>> field, TField value, string partitionKey = null, CancellationToken cancellationToken = default)
public virtual bool UpdateOne<TDocument, TKey, TField>(
IClientSessionHandle session,
FilterDefinition<TDocument> filter,
Expression<Func<TDocument, TField>> field,
TField value,
string partitionKey = null,
CancellationToken cancellationToken = default)
where TDocument : IDocument<TKey>
where TKey : IEquatable<TKey>
{
@@ -103,7 +149,13 @@ namespace MongoDbGenericRepository.DataAccess.Update
}
/// <inheritdoc cref="IMongoDbUpdater" />
public virtual bool UpdateOne<TDocument, TKey, TField>(IClientSessionHandle session, Expression<Func<TDocument, bool>> filter, Expression<Func<TDocument, TField>> field, TField value, string partitionKey = null, CancellationToken cancellationToken = default)
public virtual bool UpdateOne<TDocument, TKey, TField>(
IClientSessionHandle session,
Expression<Func<TDocument, bool>> filter,
Expression<Func<TDocument, TField>> field,
TField value,
string partitionKey = null,
CancellationToken cancellationToken = default)
where TDocument : IDocument<TKey>
where TKey : IEquatable<TKey>
{
@@ -56,7 +56,10 @@ namespace MongoDbGenericRepository.DataAccess.Update
}
/// <inheritdoc cref="IMongoDbUpdater" />
public virtual bool UpdateOne<TDocument, TKey>(TDocument documentToModify, UpdateDefinition<TDocument> update, CancellationToken cancellationToken = default)
public virtual bool UpdateOne<TDocument, TKey>(
TDocument documentToModify,
UpdateDefinition<TDocument> update,
CancellationToken cancellationToken = default)
where TDocument : IDocument<TKey>
where TKey : IEquatable<TKey>
{
@@ -83,12 +86,19 @@ namespace MongoDbGenericRepository.DataAccess.Update
}
/// <inheritdoc cref="IMongoDbUpdater" />
public virtual bool UpdateOne<TDocument, TKey, TField>(TDocument documentToModify, Expression<Func<TDocument, TField>> field, TField value, CancellationToken cancellationToken = default)
public virtual bool UpdateOne<TDocument, TKey, TField>(
TDocument documentToModify,
Expression<Func<TDocument, TField>> field,
TField value,
CancellationToken cancellationToken = default)
where TDocument : IDocument<TKey>
where TKey : IEquatable<TKey>
{
var filter = Builders<TDocument>.Filter.Eq("Id", documentToModify.Id);
var updateRes = HandlePartitioned<TDocument, TKey>(documentToModify).UpdateOne(filter, Builders<TDocument>.Update.Set(field, value), cancellationToken: cancellationToken);
var updateRes = HandlePartitioned<TDocument, TKey>(documentToModify).UpdateOne(
filter,
Builders<TDocument>.Update.Set(field, value),
cancellationToken: cancellationToken);
return updateRes.ModifiedCount == 1;
}