added some missing cancellation tokens and fixed incorrect tests

This commit is contained in:
Sean Garrett
2023-06-16 22:40:46 +01:00
parent f09cfc53c2
commit 23780697fb
25 changed files with 1077 additions and 175 deletions
@@ -36,6 +36,49 @@ namespace MongoDbGenericRepository
#region Delete
/// <inheritdoc />
public virtual long DeleteOne<TDocument>(TDocument document)
where TDocument : IDocument<Guid>
{
return DeleteOne(document, CancellationToken.None);
}
/// <inheritdoc />
public virtual long DeleteOne<TDocument>(TDocument document, CancellationToken cancellationToken)
where TDocument : IDocument<Guid>
{
return MongoDbEraser.DeleteOne<TDocument, Guid>(document, cancellationToken);
}
/// <inheritdoc />
public virtual long DeleteOne<TDocument>(Expression<Func<TDocument, bool>> filter)
where TDocument : IDocument<Guid>
{
return DeleteOne(filter, null, CancellationToken.None);
}
/// <inheritdoc />
public virtual long DeleteOne<TDocument>(Expression<Func<TDocument, bool>> filter, CancellationToken cancellationToken)
where TDocument : IDocument<Guid>
{
return DeleteOne(filter, null, cancellationToken);
}
/// <inheritdoc />
public virtual long DeleteOne<TDocument>(Expression<Func<TDocument, bool>> filter, string partitionKey)
where TDocument : IDocument<Guid>
{
return DeleteOne(filter, partitionKey, CancellationToken.None);
}
/// <inheritdoc />
public virtual long DeleteOne<TDocument>(Expression<Func<TDocument, bool>> filter, string partitionKey, CancellationToken cancellationToken)
where TDocument : IDocument<Guid>
{
return MongoDbEraser.DeleteOne<TDocument, Guid>(filter, partitionKey, cancellationToken);
}
/// <inheritdoc />
public virtual async Task<long> DeleteOneAsync<TDocument>(TDocument document)
where TDocument : IDocument<Guid>
@@ -50,20 +93,6 @@ namespace MongoDbGenericRepository
return await MongoDbEraser.DeleteOneAsync<TDocument, Guid>(document, cancellationToken);
}
/// <inheritdoc />
public virtual long DeleteOne<TDocument>(TDocument document)
where TDocument : IDocument<Guid>
{
return MongoDbEraser.DeleteOne<TDocument, Guid>(document);
}
/// <inheritdoc />
public virtual long DeleteOne<TDocument>(Expression<Func<TDocument, bool>> filter, string partitionKey = null)
where TDocument : IDocument<Guid>
{
return MongoDbEraser.DeleteOne<TDocument, Guid>(filter, partitionKey);
}
/// <inheritdoc />
public virtual async Task<long> DeleteOneAsync<TDocument>(Expression<Func<TDocument, bool>> filter)
@@ -118,7 +147,7 @@ namespace MongoDbGenericRepository
public async Task<long> DeleteManyAsync<TDocument>(Expression<Func<TDocument, bool>> filter, string partitionKey, CancellationToken cancellationToken)
where TDocument : IDocument<Guid>
{
return await MongoDbEraser.DeleteManyAsync<TDocument, Guid>(filter, partitionKey, CancellationToken.None);
return await MongoDbEraser.DeleteManyAsync<TDocument, Guid>(filter, partitionKey, cancellationToken);
}
/// <inheritdoc />
@@ -158,15 +187,47 @@ namespace MongoDbGenericRepository
where TDocument : IDocument<TKey>
where TKey : IEquatable<TKey>
{
return MongoDbEraser.DeleteOne<TDocument, TKey>(document);
return DeleteOne<TDocument, TKey>(document, CancellationToken.None);
}
/// <inheritdoc />
public virtual long DeleteOne<TDocument, TKey>(Expression<Func<TDocument, bool>> filter, string partitionKey = null)
public virtual long DeleteOne<TDocument, TKey>(TDocument document, CancellationToken cancellationToken)
where TDocument : IDocument<TKey>
where TKey : IEquatable<TKey>
{
return MongoDbEraser.DeleteOne<TDocument, TKey>(filter, partitionKey);
return MongoDbEraser.DeleteOne<TDocument, TKey>(document, cancellationToken);
}
/// <inheritdoc />
public virtual long DeleteOne<TDocument, TKey>(Expression<Func<TDocument, bool>> filter)
where TDocument : IDocument<TKey>
where TKey : IEquatable<TKey>
{
return DeleteOne<TDocument, TKey>(filter, null, CancellationToken.None);
}
/// <inheritdoc />
public virtual long DeleteOne<TDocument, TKey>(Expression<Func<TDocument, bool>> filter, CancellationToken cancellationToken)
where TDocument : IDocument<TKey>
where TKey : IEquatable<TKey>
{
return DeleteOne<TDocument, TKey>(filter, null, cancellationToken);
}
/// <inheritdoc />
public virtual long DeleteOne<TDocument, TKey>(Expression<Func<TDocument, bool>> filter, string partitionKey)
where TDocument : IDocument<TKey>
where TKey : IEquatable<TKey>
{
return DeleteOne<TDocument, TKey>(filter, partitionKey, CancellationToken.None);
}
/// <inheritdoc />
public virtual long DeleteOne<TDocument, TKey>(Expression<Func<TDocument, bool>> filter, string partitionKey, CancellationToken cancellationToken)
where TDocument : IDocument<TKey>
where TKey : IEquatable<TKey>
{
return MongoDbEraser.DeleteOne<TDocument, TKey>(filter, partitionKey, cancellationToken);
}
/// <inheritdoc />
@@ -265,13 +326,7 @@ namespace MongoDbGenericRepository
return await MongoDbEraser.DeleteManyAsync<TDocument, TKey>(documents, cancellationToken);
}
/// <summary>
/// Deletes a list of documents.
/// </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="documents">The list of documents to delete.</param>
/// <returns>The number of documents deleted.</returns>
/// <inheritdoc />
public virtual long DeleteMany<TDocument, TKey>(IEnumerable<TDocument> documents)
where TDocument : IDocument<TKey>
where TKey : IEquatable<TKey>
@@ -279,14 +334,7 @@ namespace MongoDbGenericRepository
return MongoDbEraser.DeleteMany<TDocument, TKey>(documents);
}
/// <summary>
/// Deletes the documents matching the condition of the LINQ expression filter.
/// </summary>
/// <typeparam name="TDocument">The type representing a Document.</typeparam>
/// <typeparam name="TKey">The type of the primary key for a Document.</typeparam>
/// <param name="filter">A LINQ expression filter.</param>
/// <param name="partitionKey">An optional partition key.</param>
/// <returns>The number of documents deleted.</returns>
/// <inheritdoc />
public virtual long DeleteMany<TDocument, TKey>(Expression<Func<TDocument, bool>> filter, string partitionKey = null)
where TDocument : IDocument<TKey>
where TKey : IEquatable<TKey>
@@ -19,8 +19,9 @@ namespace MongoDbGenericRepository.DataAccess.Delete
/// <typeparam name="TDocument">The type representing a Document.</typeparam>
/// <typeparam name="TKey">The type of the primary key for a Document.</typeparam>
/// <param name="document">The document you want to delete.</param>
/// <param name="cancellationToken">An optional cancellation token</param>
/// <returns>The number of documents deleted.</returns>
long DeleteOne<TDocument, TKey>(TDocument document)
long DeleteOne<TDocument, TKey>(TDocument document, CancellationToken cancellationToken = default)
where TDocument : IDocument<TKey>
where TKey : IEquatable<TKey>;
@@ -31,8 +32,9 @@ namespace MongoDbGenericRepository.DataAccess.Delete
/// <typeparam name="TKey">The type of the primary key for a Document.</typeparam>
/// <param name="filter">A LINQ expression filter.</param>
/// <param name="partitionKey">An optional partition key.</param>
/// <param name="cancellationToken">An optional cancellation token</param>
/// <returns>The number of documents deleted.</returns>
long DeleteOne<TDocument, TKey>(Expression<Func<TDocument, bool>> filter, string partitionKey = null)
long DeleteOne<TDocument, TKey>(Expression<Func<TDocument, bool>> filter, string partitionKey = null, CancellationToken cancellationToken = default)
where TDocument : IDocument<TKey>
where TKey : IEquatable<TKey>;
@@ -1,12 +1,12 @@
using MongoDB.Driver;
using MongoDbGenericRepository.DataAccess.Base;
using MongoDbGenericRepository.Models;
using System;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Linq.Expressions;
using System.Threading;
using System.Threading.Tasks;
using MongoDB.Driver;
using MongoDbGenericRepository.DataAccess.Base;
using MongoDbGenericRepository.Models;
namespace MongoDbGenericRepository.DataAccess.Delete
{
@@ -14,7 +14,7 @@ namespace MongoDbGenericRepository.DataAccess.Delete
public class MongoDbEraser : DataAccessBase, IMongoDbEraser
{
/// <summary>
/// The MongoDbEraser constructor.
/// The MongoDbEraser constructor.
/// </summary>
/// <param name="mongoDbContext">the MongoDb Context</param>
public MongoDbEraser(IMongoDbContext mongoDbContext) : base(mongoDbContext)
@@ -24,12 +24,20 @@ namespace MongoDbGenericRepository.DataAccess.Delete
#region Delete TKey
/// <inheritdoc />
public virtual long DeleteOne<TDocument, TKey>(TDocument document)
public virtual long DeleteOne<TDocument, TKey>(TDocument document, CancellationToken cancellationToken = default)
where TDocument : IDocument<TKey>
where TKey : IEquatable<TKey>
{
var filter = Builders<TDocument>.Filter.Eq("Id", document.Id);
return HandlePartitioned<TDocument, TKey>(document).DeleteOne(filter).DeletedCount;
return HandlePartitioned<TDocument, TKey>(document).DeleteOne(filter, cancellationToken).DeletedCount;
}
/// <inheritdoc />
public virtual long DeleteOne<TDocument, TKey>(Expression<Func<TDocument, bool>> filter, string partitionKey = null, CancellationToken cancellationToken = default)
where TDocument : IDocument<TKey>
where TKey : IEquatable<TKey>
{
return HandlePartitioned<TDocument, TKey>(partitionKey).DeleteOne(filter, cancellationToken).DeletedCount;
}
/// <inheritdoc />
@@ -42,15 +50,10 @@ namespace MongoDbGenericRepository.DataAccess.Delete
}
/// <inheritdoc />
public virtual long DeleteOne<TDocument, TKey>(Expression<Func<TDocument, bool>> filter, string partitionKey = null)
where TDocument : IDocument<TKey>
where TKey : IEquatable<TKey>
{
return HandlePartitioned<TDocument, TKey>(partitionKey).DeleteOne(filter).DeletedCount;
}
/// <inheritdoc />
public virtual async Task<long> DeleteOneAsync<TDocument, TKey>(Expression<Func<TDocument, bool>> filter, string partitionKey, CancellationToken cancellationToken)
public virtual async Task<long> DeleteOneAsync<TDocument, TKey>(
Expression<Func<TDocument, bool>> filter,
string partitionKey,
CancellationToken cancellationToken)
where TDocument : IDocument<TKey>
where TKey : IEquatable<TKey>
{
@@ -58,7 +61,10 @@ namespace MongoDbGenericRepository.DataAccess.Delete
}
/// <inheritdoc />
public virtual async Task<long> DeleteManyAsync<TDocument, TKey>(Expression<Func<TDocument, bool>> filter, string partitionKey, CancellationToken cancellationToken)
public virtual async Task<long> DeleteManyAsync<TDocument, TKey>(
Expression<Func<TDocument, bool>> filter,
string partitionKey,
CancellationToken cancellationToken)
where TDocument : IDocument<TKey>
where TKey : IEquatable<TKey>
{
@@ -71,7 +77,7 @@ namespace MongoDbGenericRepository.DataAccess.Delete
where TKey : IEquatable<TKey>
{
var documentList = documents.ToList();
if (!documentList.Any())
{
return 0;
@@ -81,22 +87,24 @@ namespace MongoDbGenericRepository.DataAccess.Delete
if (documentList.Any(e => e is IPartitionedDocument))
{
long deleteCount = 0;
foreach (var group in documentList.GroupBy(e => ((IPartitionedDocument)e).PartitionKey))
foreach (var group in documentList.GroupBy(e => ((IPartitionedDocument) e).PartitionKey))
{
var groupIdsToDelete = group.Select(e => e.Id).ToArray();
deleteCount += (await HandlePartitioned<TDocument, TKey>(group.FirstOrDefault())
.DeleteManyAsync(x => groupIdsToDelete.Contains(x.Id), cancellationToken: cancellationToken))
.DeleteManyAsync(x => groupIdsToDelete.Contains(x.Id), cancellationToken))
.DeletedCount;
}
return deleteCount;
}
var idsToDelete = documentList.Select(e => e.Id).ToArray();
return (await HandlePartitioned<TDocument, TKey>(documentList.FirstOrDefault()).DeleteManyAsync(x => idsToDelete.Contains(x.Id), cancellationToken: cancellationToken)).DeletedCount;
return (await HandlePartitioned<TDocument, TKey>(documentList.FirstOrDefault()).DeleteManyAsync(x => idsToDelete.Contains(x.Id), cancellationToken))
.DeletedCount;
}
/// <summary>
/// Deletes a list of documents.
/// Deletes a list of documents.
/// </summary>
/// <typeparam name="TDocument">The type representing a Document.</typeparam>
/// <typeparam name="TKey">The type of the primary key for a Document.</typeparam>
@@ -107,7 +115,7 @@ namespace MongoDbGenericRepository.DataAccess.Delete
where TKey : IEquatable<TKey>
{
var documentList = documents.ToList();
if (!documentList.Any())
{
return 0;
@@ -117,11 +125,12 @@ namespace MongoDbGenericRepository.DataAccess.Delete
if (documentList.Any(e => e is IPartitionedDocument))
{
long deleteCount = 0;
foreach (var group in documentList.GroupBy(e => ((IPartitionedDocument)e).PartitionKey))
foreach (var group in documentList.GroupBy(e => ((IPartitionedDocument) e).PartitionKey))
{
var groupIdsToDelete = group.Select(e => e.Id).ToArray();
deleteCount += (HandlePartitioned<TDocument, TKey>(group.FirstOrDefault()).DeleteMany(x => groupIdsToDelete.Contains(x.Id))).DeletedCount;
deleteCount += HandlePartitioned<TDocument, TKey>(group.FirstOrDefault()).DeleteMany(x => groupIdsToDelete.Contains(x.Id)).DeletedCount;
}
return deleteCount;
}
@@ -130,7 +139,7 @@ namespace MongoDbGenericRepository.DataAccess.Delete
}
/// <summary>
/// Deletes the documents matching the condition of the LINQ expression filter.
/// Deletes the documents matching the condition of the LINQ expression filter.
/// </summary>
/// <typeparam name="TDocument">The type representing a Document.</typeparam>
/// <typeparam name="TKey">The type of the primary key for a Document.</typeparam>
@@ -145,6 +154,5 @@ namespace MongoDbGenericRepository.DataAccess.Delete
}
#endregion
}
}
}
@@ -8,12 +8,12 @@ using MongoDbGenericRepository.Models;
namespace MongoDbGenericRepository
{
/// <summary>
/// The base Mongo Repository Delete interface. used to delete documents from the collections.
/// The base Mongo Repository Delete interface. used to delete documents from the collections.
/// </summary>
public interface IBaseMongoRepository_Delete : IBaseMongoRepository_Delete<Guid>
{
/// <summary>
/// Deletes a document.
/// Deletes 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>
@@ -24,7 +24,67 @@ namespace MongoDbGenericRepository
where TKey : IEquatable<TKey>;
/// <summary>
/// Asynchronously deletes a document matching the condition of the LINQ expression filter.
/// Deletes 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>
/// <param name="document">The document you want to delete.</param>
/// <param name="cancellationToken">The cancellation token.</param>
/// <returns>The number of documents deleted.</returns>
long DeleteOne<TDocument, TKey>(TDocument document, CancellationToken cancellationToken)
where TDocument : IDocument<TKey>
where TKey : IEquatable<TKey>;
/// <summary>
/// Deletes a document matching the condition of the LINQ expression filter.
/// </summary>
/// <typeparam name="TDocument">The type representing a Document.</typeparam>
/// <typeparam name="TKey">The type of the primary key for a Document.</typeparam>
/// <param name="filter">A LINQ expression filter.</param>
/// <returns>The number of documents deleted.</returns>
long DeleteOne<TDocument, TKey>(Expression<Func<TDocument, bool>> filter)
where TDocument : IDocument<TKey>
where TKey : IEquatable<TKey>;
/// <summary>
/// Deletes a document matching the condition of the LINQ expression filter.
/// </summary>
/// <typeparam name="TDocument">The type representing a Document.</typeparam>
/// <typeparam name="TKey">The type of the primary key for a Document.</typeparam>
/// <param name="filter">A LINQ expression filter.</param>
/// <param name="cancellationToken">The cancellation token</param>
/// <returns>The number of documents deleted.</returns>
long DeleteOne<TDocument, TKey>(Expression<Func<TDocument, bool>> filter, CancellationToken cancellationToken)
where TDocument : IDocument<TKey>
where TKey : IEquatable<TKey>;
/// <summary>
/// Deletes a document matching the condition of the LINQ expression filter.
/// </summary>
/// <typeparam name="TDocument">The type representing a Document.</typeparam>
/// <typeparam name="TKey">The type of the primary key for a Document.</typeparam>
/// <param name="filter">A LINQ expression filter.</param>
/// <param name="partitionKey">An optional partition key.</param>
/// <returns>The number of documents deleted.</returns>
long DeleteOne<TDocument, TKey>(Expression<Func<TDocument, bool>> filter, string partitionKey)
where TDocument : IDocument<TKey>
where TKey : IEquatable<TKey>;
/// <summary>
/// Deletes a document matching the condition of the LINQ expression filter.
/// </summary>
/// <typeparam name="TDocument">The type representing a Document.</typeparam>
/// <typeparam name="TKey">The type of the primary key for a Document.</typeparam>
/// <param name="filter">A LINQ expression filter.</param>
/// <param name="partitionKey">An optional partition key.</param>
/// <param name="cancellationToken">The cancellation token.</param>
/// <returns>The number of documents deleted.</returns>
long DeleteOne<TDocument, TKey>(Expression<Func<TDocument, bool>> filter, string partitionKey, CancellationToken cancellationToken)
where TDocument : IDocument<TKey>
where TKey : IEquatable<TKey>;
/// <summary>
/// Asynchronously deletes a document matching the condition of the LINQ expression filter.
/// </summary>
/// <typeparam name="TDocument">The type representing a Document.</typeparam>
/// <typeparam name="TKey">The type of the primary key for a Document.</typeparam>
@@ -35,7 +95,7 @@ namespace MongoDbGenericRepository
where TKey : IEquatable<TKey>;
/// <summary>
/// Asynchronously deletes a document matching the condition of the LINQ expression filter.
/// Asynchronously deletes a document matching the condition of the LINQ expression filter.
/// </summary>
/// <typeparam name="TDocument">The type representing a Document.</typeparam>
/// <typeparam name="TKey">The type of the primary key for a Document.</typeparam>
@@ -47,19 +107,7 @@ namespace MongoDbGenericRepository
where TKey : IEquatable<TKey>;
/// <summary>
/// Deletes a document matching the condition of the LINQ expression filter.
/// </summary>
/// <typeparam name="TDocument">The type representing a Document.</typeparam>
/// <typeparam name="TKey">The type of the primary key for a Document.</typeparam>
/// <param name="filter">A LINQ expression filter.</param>
/// <param name="partitionKey">An optional partition key.</param>
/// <returns>The number of documents deleted.</returns>
long DeleteOne<TDocument, TKey>(Expression<Func<TDocument, bool>> filter, string partitionKey = null)
where TDocument : IDocument<TKey>
where TKey : IEquatable<TKey>;
/// <summary>
/// Asynchronously deletes a document matching the condition of the LINQ expression filter.
/// Asynchronously deletes a document matching the condition of the LINQ expression filter.
/// </summary>
/// <typeparam name="TDocument">The type representing a Document.</typeparam>
/// <typeparam name="TKey">The type of the primary key for a Document.</typeparam>
@@ -70,7 +118,7 @@ namespace MongoDbGenericRepository
where TKey : IEquatable<TKey>;
/// <summary>
/// Asynchronously deletes a document matching the condition of the LINQ expression filter.
/// Asynchronously deletes a document matching the condition of the LINQ expression filter.
/// </summary>
/// <typeparam name="TDocument">The type representing a Document.</typeparam>
/// <typeparam name="TKey">The type of the primary key for a Document.</typeparam>
@@ -82,7 +130,7 @@ namespace MongoDbGenericRepository
where TKey : IEquatable<TKey>;
/// <summary>
/// Asynchronously deletes a document matching the condition of the LINQ expression filter.
/// Asynchronously deletes a document matching the condition of the LINQ expression filter.
/// </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 +142,7 @@ namespace MongoDbGenericRepository
where TKey : IEquatable<TKey>;
/// <summary>
/// Asynchronously deletes a document matching the condition of the LINQ expression filter.
/// Asynchronously deletes a document matching the condition of the LINQ expression filter.
/// </summary>
/// <typeparam name="TDocument">The type representing a Document.</typeparam>
/// <typeparam name="TKey">The type of the primary key for a Document.</typeparam>
@@ -107,7 +155,7 @@ namespace MongoDbGenericRepository
where TKey : IEquatable<TKey>;
/// <summary>
/// Asynchronously deletes the documents matching the condition of the LINQ expression filter.
/// Asynchronously deletes the documents matching the condition of the LINQ expression filter.
/// </summary>
/// <typeparam name="TDocument">The type representing a Document.</typeparam>
/// <typeparam name="TKey">The type of the primary key for a Document.</typeparam>
@@ -118,7 +166,7 @@ namespace MongoDbGenericRepository
where TKey : IEquatable<TKey>;
/// <summary>
/// Asynchronously deletes the documents matching the condition of the LINQ expression filter.
/// Asynchronously deletes the documents matching the condition of the LINQ expression filter.
/// </summary>
/// <typeparam name="TDocument">The type representing a Document.</typeparam>
/// <typeparam name="TKey">The type of the primary key for a Document.</typeparam>
@@ -130,7 +178,7 @@ namespace MongoDbGenericRepository
where TKey : IEquatable<TKey>;
/// <summary>
/// Asynchronously deletes the documents matching the condition of the LINQ expression filter.
/// Asynchronously deletes the documents matching the condition of the LINQ expression filter.
/// </summary>
/// <typeparam name="TDocument">The type representing a Document.</typeparam>
/// <typeparam name="TKey">The type of the primary key for a Document.</typeparam>
@@ -142,7 +190,7 @@ namespace MongoDbGenericRepository
where TKey : IEquatable<TKey>;
/// <summary>
/// Asynchronously deletes the documents matching the condition of the LINQ expression filter.
/// Asynchronously deletes the documents matching the condition of the LINQ expression filter.
/// </summary>
/// <typeparam name="TDocument">The type representing a Document.</typeparam>
/// <typeparam name="TKey">The type of the primary key for a Document.</typeparam>
@@ -155,7 +203,7 @@ namespace MongoDbGenericRepository
where TKey : IEquatable<TKey>;
/// <summary>
/// Asynchronously deletes a list of documents.
/// Asynchronously deletes a list of documents.
/// </summary>
/// <typeparam name="TDocument">The type representing a Document.</typeparam>
/// <typeparam name="TKey">The type of the primary key for a Document.</typeparam>
@@ -166,7 +214,7 @@ namespace MongoDbGenericRepository
where TKey : IEquatable<TKey>;
/// <summary>
/// Asynchronously deletes a list of documents.
/// Asynchronously deletes a list of documents.
/// </summary>
/// <typeparam name="TDocument">The type representing a Document.</typeparam>
/// <typeparam name="TKey">The type of the primary key for a Document.</typeparam>
@@ -178,7 +226,7 @@ namespace MongoDbGenericRepository
where TKey : IEquatable<TKey>;
/// <summary>
/// Deletes a list of documents.
/// Deletes a list of documents.
/// </summary>
/// <typeparam name="TDocument">The type representing a Document.</typeparam>
/// <typeparam name="TKey">The type of the primary key for a Document.</typeparam>
@@ -189,7 +237,7 @@ namespace MongoDbGenericRepository
where TKey : IEquatable<TKey>;
/// <summary>
/// Deletes the documents matching the condition of the LINQ expression filter.
/// Deletes the documents matching the condition of the LINQ expression filter.
/// </summary>
/// <typeparam name="TDocument">The type representing a Document.</typeparam>
/// <typeparam name="TKey">The type of the primary key for a Document.</typeparam>
@@ -38,14 +38,42 @@ namespace MongoDbGenericRepository
public virtual long DeleteOne<TDocument>(TDocument document)
where TDocument : IDocument<TKey>
{
return MongoDbEraser.DeleteOne<TDocument, TKey>(document);
return DeleteOne(document, CancellationToken.None);
}
/// <inheritdoc />
public virtual long DeleteOne<TDocument>(Expression<Func<TDocument, bool>> filter, string partitionKey = null)
public virtual long DeleteOne<TDocument>(TDocument document, CancellationToken cancellationToken)
where TDocument : IDocument<TKey>
{
return MongoDbEraser.DeleteOne<TDocument, TKey>(filter, partitionKey);
return MongoDbEraser.DeleteOne<TDocument, TKey>(document, cancellationToken);
}
/// <inheritdoc />
public virtual long DeleteOne<TDocument>(Expression<Func<TDocument, bool>> filter)
where TDocument : IDocument<TKey>
{
return DeleteOne(filter, null, CancellationToken.None);
}
/// <inheritdoc />
public virtual long DeleteOne<TDocument>(Expression<Func<TDocument, bool>> filter, CancellationToken cancellationToken)
where TDocument : IDocument<TKey>
{
return DeleteOne(filter, null, cancellationToken);
}
/// <inheritdoc />
public virtual long DeleteOne<TDocument>(Expression<Func<TDocument, bool>> filter, string partitionKey)
where TDocument : IDocument<TKey>
{
return DeleteOne(filter, partitionKey, CancellationToken.None);
}
/// <inheritdoc />
public virtual long DeleteOne<TDocument>(Expression<Func<TDocument, bool>> filter, string partitionKey, CancellationToken cancellationToken)
where TDocument : IDocument<TKey>
{
return MongoDbEraser.DeleteOne<TDocument, TKey>(filter, partitionKey, cancellationToken);
}
/// <inheritdoc />
@@ -23,6 +23,56 @@ namespace MongoDbGenericRepository
long DeleteOne<TDocument>(TDocument document)
where TDocument : IDocument<TKey>;
/// <summary>
/// Deletes a document.
/// </summary>
/// <typeparam name="TDocument">The type representing a Document.</typeparam>
/// <param name="document">The document you want to delete.</param>
/// <param name="cancellationToken">The cancellation token.</param>
/// <returns>The number of documents deleted.</returns>
long DeleteOne<TDocument>(TDocument document, CancellationToken cancellationToken)
where TDocument : IDocument<TKey>;
/// <summary>
/// Deletes a document matching the condition of the LINQ expression filter.
/// </summary>
/// <typeparam name="TDocument">The type representing a Document.</typeparam>
/// <param name="filter">A LINQ expression filter.</param>
/// <returns>The number of documents deleted.</returns>
long DeleteOne<TDocument>(Expression<Func<TDocument, bool>> filter)
where TDocument : IDocument<TKey>;
/// <summary>
/// Deletes a document matching the condition of the LINQ expression filter.
/// </summary>
/// <typeparam name="TDocument">The type representing a Document.</typeparam>
/// <param name="filter">A LINQ expression filter.</param>
/// <param name="cancellationToken">The cancellation token.</param>
/// <returns>The number of documents deleted.</returns>
long DeleteOne<TDocument>(Expression<Func<TDocument, bool>> filter, CancellationToken cancellationToken)
where TDocument : IDocument<TKey>;
/// <summary>
/// Deletes a document matching the condition of the LINQ expression filter.
/// </summary>
/// <typeparam name="TDocument">The type representing a Document.</typeparam>
/// <param name="filter">A LINQ expression filter.</param>
/// <param name="partitionKey">An optional partition key.</param>
/// <returns>The number of documents deleted.</returns>
long DeleteOne<TDocument>(Expression<Func<TDocument, bool>> filter, string partitionKey)
where TDocument : IDocument<TKey>;
/// <summary>
/// Deletes a document matching the condition of the LINQ expression filter.
/// </summary>
/// <typeparam name="TDocument">The type representing a Document.</typeparam>
/// <param name="filter">A LINQ expression filter.</param>
/// <param name="partitionKey">An optional partition key.</param>
/// <param name="cancellationToken">The cancellation token.</param>
/// <returns>The number of documents deleted.</returns>
long DeleteOne<TDocument>(Expression<Func<TDocument, bool>> filter, string partitionKey, CancellationToken cancellationToken)
where TDocument : IDocument<TKey>;
/// <summary>
/// Asynchronously deletes a document matching the condition of the LINQ expression filter.
/// </summary>
@@ -42,15 +92,6 @@ namespace MongoDbGenericRepository
Task<long> DeleteOneAsync<TDocument>(TDocument document, CancellationToken cancellationToken)
where TDocument : IDocument<TKey>;
/// <summary>
/// Deletes a document matching the condition of the LINQ expression filter.
/// </summary>
/// <typeparam name="TDocument">The type representing a Document.</typeparam>
/// <param name="filter">A LINQ expression filter.</param>
/// <param name="partitionKey">An optional partition key.</param>
/// <returns>The number of documents deleted.</returns>
long DeleteOne<TDocument>(Expression<Func<TDocument, bool>> filter, string partitionKey = null)
where TDocument : IDocument<TKey>;
/// <summary>
/// Asynchronously deletes a document matching the condition of the LINQ expression filter.