using MongoDbGenericRepository.DataAccess.Delete; using MongoDbGenericRepository.Models; using System; using System.Collections.Generic; using System.Linq.Expressions; using System.Threading.Tasks; namespace MongoDbGenericRepository { public abstract partial class BaseMongoRepository : IBaseMongoRepository_Delete { private IMongoDbEraser _mongoDbEraser; /// /// The MongoDbEraser used to delete documents. /// protected virtual IMongoDbEraser MongoDbEraser { get { if (_mongoDbEraser != null) { return _mongoDbEraser; } lock (_initLock) { if (_mongoDbEraser == null) { _mongoDbEraser = new MongoDbEraser(MongoDbContext); } } return _mongoDbEraser; } set { _mongoDbEraser = value; } } #region Delete /// /// Asynchronously deletes a document. /// /// The type representing a Document. /// The document you want to delete. /// The number of documents deleted. public virtual async Task DeleteOneAsync(TDocument document) where TDocument : IDocument { return await MongoDbEraser.DeleteOneAsync(document); } /// /// Deletes a document. /// /// The type representing a Document. /// The document you want to delete. /// The number of documents deleted. public virtual long DeleteOne(TDocument document) where TDocument : IDocument { return MongoDbEraser.DeleteOne(document); } /// /// Deletes a document matching the condition of the LINQ expression filter. /// /// The type representing a Document. /// A LINQ expression filter. /// An optional partition key. /// The number of documents deleted. public virtual long DeleteOne(Expression> filter, string partitionKey = null) where TDocument : IDocument { return MongoDbEraser.DeleteOne(filter, partitionKey); } /// /// Asynchronously deletes a document matching the condition of the LINQ expression filter. /// /// The type representing a Document. /// A LINQ expression filter. /// An optional partition key. /// The number of documents deleted. public virtual async Task DeleteOneAsync(Expression> filter, string partitionKey = null) where TDocument : IDocument { return await MongoDbEraser.DeleteOneAsync(filter, partitionKey); } /// /// Asynchronously deletes the documents matching the condition of the LINQ expression filter. /// /// The type representing a Document. /// A LINQ expression filter. /// An optional partition key. /// The number of documents deleted. public virtual async Task DeleteManyAsync(Expression> filter, string partitionKey = null) where TDocument : IDocument { return await MongoDbEraser.DeleteManyAsync(filter, partitionKey); } /// /// Asynchronously deletes a list of documents. /// /// The type representing a Document. /// The list of documents to delete. /// The number of documents deleted. public virtual async Task DeleteManyAsync(IEnumerable documents) where TDocument : IDocument { return await DeleteManyAsync(documents); } /// /// Deletes a list of documents. /// /// The type representing a Document. /// The list of documents to delete. /// The number of documents deleted. public virtual long DeleteMany(IEnumerable documents) where TDocument : IDocument { return DeleteMany(documents); } /// /// Deletes the documents matching the condition of the LINQ expression filter. /// /// The type representing a Document. /// A LINQ expression filter. /// An optional partition key. /// The number of documents deleted. public virtual long DeleteMany(Expression> filter, string partitionKey = null) where TDocument : IDocument { return MongoDbEraser.DeleteMany(filter, partitionKey); } #endregion Delete #region Delete TKey /// /// Deletes a document. /// /// The type representing a Document. /// The type of the primary key for a Document. /// The document you want to delete. /// The number of documents deleted. public virtual long DeleteOne(TDocument document) where TDocument : IDocument where TKey : IEquatable { return MongoDbEraser.DeleteOne(document); } /// /// Asynchronously deletes a document matching the condition of the LINQ expression filter. /// /// The type representing a Document. /// The type of the primary key for a Document. /// The document you want to delete. /// The number of documents deleted. public virtual async Task DeleteOneAsync(TDocument document) where TDocument : IDocument where TKey : IEquatable { return await MongoDbEraser.DeleteOneAsync(document); } /// /// Deletes a document matching the condition of the LINQ expression filter. /// /// The type representing a Document. /// The type of the primary key for a Document. /// A LINQ expression filter. /// An optional partition key. /// The number of documents deleted. public virtual long DeleteOne(Expression> filter, string partitionKey = null) where TDocument : IDocument where TKey : IEquatable { return MongoDbEraser.DeleteOne(filter, partitionKey); } /// /// Asynchronously deletes a document matching the condition of the LINQ expression filter. /// /// The type representing a Document. /// The type of the primary key for a Document. /// A LINQ expression filter. /// An optional partition key. /// The number of documents deleted. public virtual async Task DeleteOneAsync(Expression> filter, string partitionKey = null) where TDocument : IDocument where TKey : IEquatable { return await MongoDbEraser.DeleteOneAsync(filter, partitionKey); } /// /// Asynchronously deletes the documents matching the condition of the LINQ expression filter. /// /// The type representing a Document. /// The type of the primary key for a Document. /// A LINQ expression filter. /// An optional partition key. /// The number of documents deleted. public virtual async Task DeleteManyAsync(Expression> filter, string partitionKey = null) where TDocument : IDocument where TKey : IEquatable { return await MongoDbEraser.DeleteManyAsync(filter, partitionKey); } /// /// Asynchronously deletes a list of documents. /// /// The type representing a Document. /// The type of the primary key for a Document. /// The list of documents to delete. /// The number of documents deleted. public virtual async Task DeleteManyAsync(IEnumerable documents) where TDocument : IDocument where TKey : IEquatable { return await MongoDbEraser.DeleteManyAsync(documents); } /// /// Deletes a list of documents. /// /// The type representing a Document. /// The type of the primary key for a Document. /// The list of documents to delete. /// The number of documents deleted. public virtual long DeleteMany(IEnumerable documents) where TDocument : IDocument where TKey : IEquatable { return MongoDbEraser.DeleteMany(documents); } /// /// Deletes the documents matching the condition of the LINQ expression filter. /// /// The type representing a Document. /// The type of the primary key for a Document. /// A LINQ expression filter. /// An optional partition key. /// The number of documents deleted. public virtual long DeleteMany(Expression> filter, string partitionKey = null) where TDocument : IDocument where TKey : IEquatable { return MongoDbEraser.DeleteMany(filter, partitionKey); } #endregion } }