From 40e287418b7f37ae898e79bcfa8b92f4474c879a Mon Sep 17 00:00:00 2001 From: Sean Garrett Date: Sat, 1 Jul 2023 22:27:11 +0100 Subject: [PATCH] read only and tests --- .../Infrastructure/Model/TestDocument.cs | 9 +- .../Infrastructure/Model/TestProjection.cs | 2 + .../TestKeyedMongoRepository.cs | 22 +- .../TestKeyedMongoRepositoryContext.cs | 24 +- .../TestKeyedReadOnlyMongoRepository.cs | 30 + ...TestKeyedReadOnlyMongoRepositoryContext.cs | 45 + .../GetSortedPaginatedAsyncTests.cs | 246 +++ .../GroupByTests.cs | 243 +++ .../IReadOnlyMongoRepository.TKey.cs | 1018 +++++++++++-- .../BaseMongoRepository.TKey.ReadOnly.cs | 1319 ++++++++++++----- 10 files changed, 2466 insertions(+), 492 deletions(-) create mode 100644 CoreUnitTests/Infrastructure/TestKeyedReadOnlyMongoRepository.cs create mode 100644 CoreUnitTests/Infrastructure/TestKeyedReadOnlyMongoRepositoryContext.cs create mode 100644 CoreUnitTests/ReadOnlyMongoRepositoryTests/GetSortedPaginatedAsyncTests.cs create mode 100644 CoreUnitTests/ReadOnlyMongoRepositoryTests/GroupByTests.cs diff --git a/CoreUnitTests/Infrastructure/Model/TestDocument.cs b/CoreUnitTests/Infrastructure/Model/TestDocument.cs index 51f87f7..5f92e89 100644 --- a/CoreUnitTests/Infrastructure/Model/TestDocument.cs +++ b/CoreUnitTests/Infrastructure/Model/TestDocument.cs @@ -4,23 +4,21 @@ using MongoDbGenericRepository.Models; namespace CoreUnitTests.Infrastructure.Model; - public class TestDocument : Document { public TestDocument() { Version = 2; - Nested = new Nested - { - SomeDate = DateTime.UtcNow - }; + Nested = new Nested {SomeDate = DateTime.UtcNow}; Children = new List(); } public int SomeValue { get; set; } public string SomeContent { get; set; } + public string SomeContent2 { get; set; } + public string SomeContent3 { get; set; } public int GroupingKey { get; set; } @@ -29,4 +27,3 @@ public class TestDocument : Document public List Children { get; set; } } - diff --git a/CoreUnitTests/Infrastructure/Model/TestProjection.cs b/CoreUnitTests/Infrastructure/Model/TestProjection.cs index 7d278a1..c1c8714 100644 --- a/CoreUnitTests/Infrastructure/Model/TestProjection.cs +++ b/CoreUnitTests/Infrastructure/Model/TestProjection.cs @@ -7,4 +7,6 @@ public class TestProjection public Guid TestDocumentId { get; set; } public DateTime NestedData { get; set; } + + public int Count { get; set; } } diff --git a/CoreUnitTests/Infrastructure/TestKeyedMongoRepository.cs b/CoreUnitTests/Infrastructure/TestKeyedMongoRepository.cs index 8780599..69f219d 100644 --- a/CoreUnitTests/Infrastructure/TestKeyedMongoRepository.cs +++ b/CoreUnitTests/Infrastructure/TestKeyedMongoRepository.cs @@ -16,23 +16,11 @@ public class TestKeyedMongoRepository : BaseMongoRepository { } - public void SetIndexHandler(IMongoDbIndexHandler indexHandler) - { - MongoDbIndexHandler = indexHandler; - } + public void SetIndexHandler(IMongoDbIndexHandler indexHandler) => MongoDbIndexHandler = indexHandler; - public void SetDbCreator(IMongoDbCreator creator) - { - MongoDbCreator = creator; - } + public void SetDbCreator(IMongoDbCreator creator) => MongoDbCreator = creator; - public void SetReader(IMongoDbReader reader) - { - MongoDbReader = reader; - } + public void SetReader(IMongoDbReader reader) => MongoDbReader = reader; - public void SetEraser(IMongoDbEraser eraser) - { - MongoDbEraser = eraser; - } -} \ No newline at end of file + public void SetEraser(IMongoDbEraser eraser) => MongoDbEraser = eraser; +} diff --git a/CoreUnitTests/Infrastructure/TestKeyedMongoRepositoryContext.cs b/CoreUnitTests/Infrastructure/TestKeyedMongoRepositoryContext.cs index 55b4bd5..2b86c1a 100644 --- a/CoreUnitTests/Infrastructure/TestKeyedMongoRepositoryContext.cs +++ b/CoreUnitTests/Infrastructure/TestKeyedMongoRepositoryContext.cs @@ -12,13 +12,13 @@ namespace CoreUnitTests.Infrastructure; public class TestKeyedMongoRepositoryContext where TKey : IEquatable { - private readonly Mock _mongoDatabase; + private readonly Mock mongoDatabase; - private TestKeyedMongoRepository _sut; + private TestKeyedMongoRepository sut; protected TestKeyedMongoRepositoryContext() { - _mongoDatabase = new Mock(); + mongoDatabase = new Mock(); Fixture = new Fixture(); } @@ -28,33 +28,33 @@ public class TestKeyedMongoRepositoryContext { get { - if (_sut != null) + if (sut != null) { - return _sut; + return sut; } - _sut = new TestKeyedMongoRepository(_mongoDatabase.Object); + sut = new TestKeyedMongoRepository(mongoDatabase.Object); if (IndexHandler != null) { - _sut.SetIndexHandler(IndexHandler.Object); + sut.SetIndexHandler(IndexHandler.Object); } if (Creator != null) { - _sut.SetDbCreator(Creator.Object); + sut.SetDbCreator(Creator.Object); } if (Reader != null) { - _sut.SetReader(Reader.Object); + sut.SetReader(Reader.Object); } if (Eraser != null) { - _sut.SetEraser(Eraser.Object); + sut.SetEraser(Eraser.Object); } - return _sut; + return sut; } } @@ -65,4 +65,4 @@ public class TestKeyedMongoRepositoryContext protected Mock Reader { get; set; } protected Mock Eraser { get; set; } -} \ No newline at end of file +} diff --git a/CoreUnitTests/Infrastructure/TestKeyedReadOnlyMongoRepository.cs b/CoreUnitTests/Infrastructure/TestKeyedReadOnlyMongoRepository.cs new file mode 100644 index 0000000..5b6efac --- /dev/null +++ b/CoreUnitTests/Infrastructure/TestKeyedReadOnlyMongoRepository.cs @@ -0,0 +1,30 @@ +using System; +using MongoDB.Driver; +using MongoDbGenericRepository; +using MongoDbGenericRepository.DataAccess.Read; + +namespace CoreUnitTests.Infrastructure; + +public class TestKeyedReadOnlyMongoRepository : ReadOnlyMongoRepository + where TKey : IEquatable +{ + /// + public TestKeyedReadOnlyMongoRepository(string connectionString, string databaseName = null) + : base(connectionString, databaseName) + { + } + + /// + public TestKeyedReadOnlyMongoRepository(IMongoDatabase mongoDatabase) + : base(mongoDatabase) + { + } + + /// + public TestKeyedReadOnlyMongoRepository(IMongoDbContext mongoDbContext) + : base(mongoDbContext) + { + } + + public void SetReader(IMongoDbReader reader) => MongoDbReader = reader; +} diff --git a/CoreUnitTests/Infrastructure/TestKeyedReadOnlyMongoRepositoryContext.cs b/CoreUnitTests/Infrastructure/TestKeyedReadOnlyMongoRepositoryContext.cs new file mode 100644 index 0000000..fab275e --- /dev/null +++ b/CoreUnitTests/Infrastructure/TestKeyedReadOnlyMongoRepositoryContext.cs @@ -0,0 +1,45 @@ +using System; +using AutoFixture; +using MongoDB.Driver; +using MongoDbGenericRepository.DataAccess.Read; +using Moq; + +namespace CoreUnitTests.Infrastructure; + +public class TestKeyedReadOnlyMongoRepositoryContext + where TKey : IEquatable +{ + private readonly Mock mongoDatabase; + + private TestKeyedReadOnlyMongoRepository sut; + + protected TestKeyedReadOnlyMongoRepositoryContext() + { + mongoDatabase = new Mock(); + Fixture = new Fixture(); + } + + protected Fixture Fixture { get; set; } + + protected TestKeyedReadOnlyMongoRepository Sut + { + get + { + if (sut != null) + { + return sut; + } + + sut = new TestKeyedReadOnlyMongoRepository(mongoDatabase.Object); + + if (Reader != null) + { + sut.SetReader(Reader.Object); + } + + return sut; + } + } + + protected Mock Reader { get; set; } +} diff --git a/CoreUnitTests/ReadOnlyMongoRepositoryTests/GetSortedPaginatedAsyncTests.cs b/CoreUnitTests/ReadOnlyMongoRepositoryTests/GetSortedPaginatedAsyncTests.cs new file mode 100644 index 0000000..3fe29a1 --- /dev/null +++ b/CoreUnitTests/ReadOnlyMongoRepositoryTests/GetSortedPaginatedAsyncTests.cs @@ -0,0 +1,246 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Linq.Expressions; +using System.Threading; +using System.Threading.Tasks; +using AutoFixture; +using CoreUnitTests.Infrastructure; +using CoreUnitTests.Infrastructure.Model; +using FluentAssertions; +using MongoDB.Driver; +using MongoDbGenericRepository.DataAccess.Read; +using Moq; +using Xunit; + +namespace CoreUnitTests.ReadOnlyMongoRepositoryTests; + +public class GetSortedPaginatedAsyncTests : TestKeyedReadOnlyMongoRepositoryContext +{ + private readonly Expression> filter = document => document.GroupingKey == 1; + private readonly Expression> selector = document => document.GroupingKey; + private readonly SortDefinition sortDefinition = Builders.Sort.Ascending(document => document.GroupingKey); + + private const bool DefaultAscending = true; + private const int DefaultSkipNumber = 0; + private const int DefaultTakeNumber = 50; + + [Fact] + public async Task WithFilterAndSortSelector_GetsResults() + { + // Arrange + var documents = SetupReaderWithSortSelector(); + + // Act + var result = await Sut.GetSortedPaginatedAsync(filter, selector); + + // Assert + VerifySelector(result, documents, DefaultAscending, DefaultSkipNumber, DefaultTakeNumber, null, CancellationToken.None); + } + + [Fact] + public async Task WithFilterAndSortSelectorAndAscending_GetsResults() + { + // Arrange + var documents = SetupReaderWithSortSelector(); + var ascending = Fixture.Create(); + + // Act + var result = await Sut.GetSortedPaginatedAsync(filter, selector, ascending); + + // Assert + VerifySelector(result, documents, ascending, DefaultSkipNumber, DefaultTakeNumber, null, CancellationToken.None); + } + + [Fact] + public async Task WithFilterAndSortSelectorAndSkipNumber_GetsResults() + { + // Arrange + var documents = SetupReaderWithSortSelector(); + var skipNumber = Fixture.Create(); + + // Act + var result = await Sut.GetSortedPaginatedAsync(filter, selector, skipNumber: skipNumber); + + // Assert + VerifySelector(result, documents, DefaultAscending, skipNumber, DefaultTakeNumber, null, CancellationToken.None); + } + + [Fact] + public async Task WithFilterAndSortSelectorAndTakeNumber_GetsResults() + { + // Arrange + var documents = SetupReaderWithSortSelector(); + var ascending = Fixture.Create(); + var takeNumber = Fixture.Create(); + + // Act + var result = await Sut.GetSortedPaginatedAsync(filter, selector, ascending, takeNumber: takeNumber); + + // Assert + VerifySelector(result, documents, ascending, DefaultSkipNumber, takeNumber, null, CancellationToken.None); + } + + [Fact] + public async Task WithFilterAndSortSelectorAndPartitionKey_GetsResults() + { + // Arrange + var documents = SetupReaderWithSortSelector(); + var partitionKey = Fixture.Create(); + + // Act + var result = await Sut.GetSortedPaginatedAsync(filter, selector, partitionKey: partitionKey); + + // Assert + VerifySelector(result, documents, DefaultAscending, DefaultSkipNumber, DefaultTakeNumber, partitionKey, CancellationToken.None); + } + + [Fact] + public async Task WithFilterAndSortSelectorAndCancellationToken_GetsResults() + { + // Arrange + var documents = SetupReaderWithSortSelector(); + var cancellationToken = new CancellationToken(true); + + // Act + var result = await Sut.GetSortedPaginatedAsync(filter, selector, cancellationToken: cancellationToken); + + // Assert + VerifySelector(result, documents, DefaultAscending, DefaultSkipNumber, DefaultTakeNumber, null, cancellationToken); + } + + [Fact] + public async Task WithFilterAndSortDefinition_GetsResults() + { + // Arrange + var documents = SetupReaderWithSortDefinition(); + + // Act + var result = await Sut.GetSortedPaginatedAsync(filter, sortDefinition); + + // Assert + VerifyDefinition(result, documents, DefaultSkipNumber, DefaultTakeNumber, null, CancellationToken.None); + } + + [Fact] + public async Task WithFilterAndSortDefinitionAndSkipNumber_GetsResults() + { + // Arrange + var documents = SetupReaderWithSortDefinition(); + var skipNumber = Fixture.Create(); + + // Act + var result = await Sut.GetSortedPaginatedAsync(filter, sortDefinition, skipNumber); + + // Assert + VerifyDefinition(result, documents, skipNumber, DefaultTakeNumber, null, CancellationToken.None); + } + + [Fact] + public async Task WithFilterAndSortDefinitionAndTakeNumber_GetsResults() + { + // Arrange + var documents = SetupReaderWithSortDefinition(); + var takeNumber = Fixture.Create(); + + // Act + var result = await Sut.GetSortedPaginatedAsync(filter, sortDefinition, takeNumber: takeNumber); + + // Assert + VerifyDefinition(result, documents, DefaultSkipNumber, takeNumber, null, CancellationToken.None); + } + + [Fact] + public async Task WithFilterAndSortDefinitionAndPartitionKey_GetsResults() + { + // Arrange + var documents = SetupReaderWithSortDefinition(); + var partitionKey = Fixture.Create(); + + // Act + var result = await Sut.GetSortedPaginatedAsync(filter, sortDefinition, partitionKey: partitionKey); + + // Assert + VerifyDefinition(result, documents, DefaultSkipNumber, DefaultTakeNumber, partitionKey, CancellationToken.None); + } + + [Fact] + public async Task WithFilterAndSortDefinitionAndCancellationToken_GetsResults() + { + // Arrange + var documents = SetupReaderWithSortDefinition(); + var token = new CancellationToken(true); + + // Act + var result = await Sut.GetSortedPaginatedAsync(filter, sortDefinition, cancellationToken: token); + + // Assert + VerifyDefinition(result, documents, DefaultSkipNumber, DefaultTakeNumber, null, token); + } + + private List SetupReaderWithSortSelector() + { + var documents = Fixture.CreateMany().ToList(); + Reader = new Mock(); + + Reader.Setup( + x => x.GetSortedPaginatedAsync( + It.IsAny>>(), + It.IsAny>>(), + It.IsAny(), + It.IsAny(), + It.IsAny(), + It.IsAny(), + It.IsAny())) + .ReturnsAsync(documents); + return documents; + } + + private void VerifySelector(List result, List documents, bool ascending, int skipNumber, int takeNumber, string partitionKey, CancellationToken cancellationToken) + { + result.Should().NotBeNull(); + result.Should().BeEquivalentTo(documents); + Reader.Verify( + x => x.GetSortedPaginatedAsync( + filter, + selector, + ascending, + skipNumber, + takeNumber, + partitionKey, + cancellationToken), + Times.Once); + } + + private List SetupReaderWithSortDefinition() + { + var documents = Fixture.CreateMany().ToList(); + Reader = new Mock(); + + Reader.Setup( + x => x.GetSortedPaginatedAsync( + It.IsAny>>(), + It.IsAny>(), + It.IsAny(), + It.IsAny(), + It.IsAny(), + It.IsAny())) + .ReturnsAsync(documents); + return documents; + } + + private void VerifyDefinition(List result, List documents, int skipNumber, int takeNumber, string partitionKey, CancellationToken cancellationToken) + { + result.Should().NotBeNull(); + result.Should().BeEquivalentTo(documents); + Reader.Verify( + x => x.GetSortedPaginatedAsync( + filter, + sortDefinition, + skipNumber, + takeNumber, + partitionKey, + cancellationToken), + Times.Once); + } +} diff --git a/CoreUnitTests/ReadOnlyMongoRepositoryTests/GroupByTests.cs b/CoreUnitTests/ReadOnlyMongoRepositoryTests/GroupByTests.cs new file mode 100644 index 0000000..abbdca7 --- /dev/null +++ b/CoreUnitTests/ReadOnlyMongoRepositoryTests/GroupByTests.cs @@ -0,0 +1,243 @@ +using System; +using System.Linq; +using System.Linq.Expressions; +using System.Threading; +using AutoFixture; +using CoreUnitTests.Infrastructure; +using CoreUnitTests.Infrastructure.Model; +using FluentAssertions; +using MongoDbGenericRepository.DataAccess.Read; +using Moq; +using Xunit; + +namespace CoreUnitTests.ReadOnlyMongoRepositoryTests; + +public class GroupByTests : TestKeyedReadOnlyMongoRepositoryContext +{ + private readonly Expression> grouping = document => document.GroupingKey; + private readonly Expression, TestProjection>> projection = documents => new TestProjection {Count = documents.Count()}; + private readonly Expression> filter = document => document.GroupingKey == 1; + + [Fact] + public void WithGroupingCriteriaAndProjection_Groups() + { + // Arrange + var projections = Fixture.CreateMany().ToList(); + Reader = new Mock(); + + Reader.Setup( + x => x.GroupBy( + It.IsAny>>(), + It.IsAny, TestProjection>>>(), + It.IsAny(), + It.IsAny())) + .Returns(projections); + + // Act + var result = Sut.GroupBy(grouping, projection); + + // Assert + result.Should().NotBeNull(); + result.Should().BeEquivalentTo(projections); + Reader.Verify( + x => x.GroupBy(grouping, projection, null, CancellationToken.None), + Times.Once); + } + + [Fact] + public void WithGroupingCriteriaAndProjectionAndCancellationToken_Groups() + { + // Arrange + var projections = Fixture.CreateMany().ToList(); + var token = new CancellationToken(true); + Reader = new Mock(); + + Reader + .Setup( + x => x.GroupBy( + It.IsAny>>(), + It.IsAny, TestProjection>>>(), + It.IsAny(), + It.IsAny())) + .Returns(projections); + + // Act + var result = Sut.GroupBy(grouping, projection, token); + + // Assert + result.Should().NotBeNull(); + result.Should().BeEquivalentTo(projections); + Reader.Verify( + x => x.GroupBy(grouping, projection, null, token), + Times.Once); + } + + [Fact] + public void WithGroupingCriteriaAndProjectionAndPartitionKey_Groups() + { + // Arrange + var projections = Fixture.CreateMany().ToList(); + var partitionKey = Fixture.Create(); + Reader = new Mock(); + + Reader + .Setup( + x => x.GroupBy( + It.IsAny>>(), + It.IsAny, TestProjection>>>(), + It.IsAny(), + It.IsAny())) + .Returns(projections); + + // Act + var result = Sut.GroupBy(grouping, projection, partitionKey); + + // Assert + result.Should().NotBeNull(); + result.Should().BeEquivalentTo(projections); + Reader.Verify( + x => x.GroupBy(grouping, projection, partitionKey, CancellationToken.None), + Times.Once); + } + + [Fact] + public void WithGroupingCriteriaAndProjectionAndPartitionKeyAndCancellationToken_Groups() + { + // Arrange + var projections = Fixture.CreateMany().ToList(); + var partitionKey = Fixture.Create(); + var token = new CancellationToken(true); + Reader = new Mock(); + + Reader + .Setup( + x => x.GroupBy( + It.IsAny>>(), + It.IsAny, TestProjection>>>(), + It.IsAny(), + It.IsAny())) + .Returns(projections); + + // Act + var result = Sut.GroupBy(grouping, projection, partitionKey, token); + + // Assert + result.Should().NotBeNull(); + result.Should().BeEquivalentTo(projections); + Reader.Verify( + x => x.GroupBy(grouping, projection, partitionKey, token), + Times.Once); + } + + [Fact] + public void WithFilterAndGroupingCriteriaAndProjection_Groups() + { + // Arrange + var projections = Fixture.CreateMany().ToList(); + Reader = new Mock(); + + Reader.Setup( + x => x.GroupBy( + It.IsAny>>(), + It.IsAny>>(), + It.IsAny, TestProjection>>>(), + It.IsAny(), + It.IsAny())) + .Returns(projections); + + // Act + var result = Sut.GroupBy(filter, grouping, projection); + + // Assert + result.Should().NotBeNull(); + result.Should().BeEquivalentTo(projections); + Reader.Verify( + x => x.GroupBy(filter, grouping, projection, null, CancellationToken.None), + Times.Once); + } + + [Fact] + public void WithFilterAndGroupingCriteriaAndProjectionAndCancellationToken_Groups() + { + // Arrange + var projections = Fixture.CreateMany().ToList(); + var token = new CancellationToken(true); + Reader = new Mock(); + + Reader.Setup( + x => x.GroupBy( + It.IsAny>>(), + It.IsAny>>(), + It.IsAny, TestProjection>>>(), + It.IsAny(), + It.IsAny())) + .Returns(projections); + + // Act + var result = Sut.GroupBy(filter, grouping, projection, token); + + // Assert + result.Should().NotBeNull(); + result.Should().BeEquivalentTo(projections); + Reader.Verify( + x => x.GroupBy(filter, grouping, projection, null, token), + Times.Once); + } + + [Fact] + public void WithFilterAndGroupingCriteriaAndProjectionAndPartitionKey_Groups() + { + // Arrange + var projections = Fixture.CreateMany().ToList(); + var partitionKey = Fixture.Create(); + Reader = new Mock(); + + Reader.Setup( + x => x.GroupBy( + It.IsAny>>(), + It.IsAny>>(), + It.IsAny, TestProjection>>>(), + It.IsAny(), + It.IsAny())) + .Returns(projections); + + // Act + var result = Sut.GroupBy(filter, grouping, projection, partitionKey); + + // Assert + result.Should().NotBeNull(); + result.Should().BeEquivalentTo(projections); + Reader.Verify( + x => x.GroupBy(filter, grouping, projection, partitionKey, CancellationToken.None), + Times.Once); + } + + [Fact] + public void WithFilterAndGroupingCriteriaAndProjectionAndPartitionKeyAndCancellationToken_Groups() + { + // Arrange + var projections = Fixture.CreateMany().ToList(); + var partitionKey = Fixture.Create(); + var token = new CancellationToken(true); + Reader = new Mock(); + + Reader.Setup( + x => x.GroupBy( + It.IsAny>>(), + It.IsAny>>(), + It.IsAny, TestProjection>>>(), + It.IsAny(), + It.IsAny())) + .Returns(projections); + + // Act + var result = Sut.GroupBy(filter, grouping, projection, partitionKey, token); + + // Assert + result.Should().NotBeNull(); + result.Should().BeEquivalentTo(projections); + Reader.Verify( + x => x.GroupBy(filter, grouping, projection, partitionKey, token), + Times.Once); + } +} diff --git a/MongoDbGenericRepository/Abstractions/IReadOnlyMongoRepository.TKey.cs b/MongoDbGenericRepository/Abstractions/IReadOnlyMongoRepository.TKey.cs index 6e93142..d7d2124 100644 --- a/MongoDbGenericRepository/Abstractions/IReadOnlyMongoRepository.TKey.cs +++ b/MongoDbGenericRepository/Abstractions/IReadOnlyMongoRepository.TKey.cs @@ -2,6 +2,7 @@ using System.Collections.Generic; using System.Linq; using System.Linq.Expressions; +using System.Threading; using System.Threading.Tasks; using MongoDB.Driver; using MongoDbGenericRepository.Models; @@ -9,188 +10,746 @@ using MongoDbGenericRepository.Models; namespace MongoDbGenericRepository { /// - /// read only repository interface + /// read only repository interface /// /// The key type - public interface IReadOnlyMongoRepository where TKey : IEquatable + public interface IReadOnlyMongoRepository + where TKey : IEquatable { #region Read /// - /// Asynchronously returns one document given its id. + /// Asynchronously returns one document given its id. + /// + /// The type representing a Document. + /// The Id of the document you want to get. + Task GetByIdAsync(TKey id) + where TDocument : IDocument; + + /// + /// Asynchronously returns one document given its id. + /// + /// The type representing a Document. + /// The Id of the document you want to get. + /// The cancellation token. + Task GetByIdAsync(TKey id, CancellationToken cancellationToken) + where TDocument : IDocument; + + /// + /// Asynchronously returns one document given its id. /// /// The type representing a Document. /// The Id of the document you want to get. /// An optional partition key. - Task GetByIdAsync(TKey id, string partitionKey = null) where TDocument : IDocument; + Task GetByIdAsync(TKey id, string partitionKey) + where TDocument : IDocument; /// - /// Returns one document given its id. + /// Asynchronously returns one document given its id. /// /// The type representing a Document. /// The Id of the document you want to get. /// An optional partition key. - TDocument GetById(TKey id, string partitionKey = null) where TDocument : IDocument; + /// The cancellation token. + Task GetByIdAsync(TKey id, string partitionKey, CancellationToken cancellationToken) + where TDocument : IDocument; /// - /// Asynchronously returns one document given an expression filter. + /// Returns one document given its id. + /// + /// The type representing a Document. + /// The Id of the document you want to get. + TDocument GetById(TKey id) + where TDocument : IDocument; + + /// + /// Returns one document given its id. + /// + /// The type representing a Document. + /// The Id of the document you want to get. + /// The cancellation token. + TDocument GetById(TKey id, CancellationToken cancellationToken) + where TDocument : IDocument; + + /// + /// Returns one document given its id. + /// + /// The type representing a Document. + /// The Id of the document you want to get. + /// An optional partition key. + TDocument GetById(TKey id, string partitionKey) + where TDocument : IDocument; + + /// + /// Returns one document given its id. + /// + /// The type representing a Document. + /// The Id of the document you want to get. + /// An optional partition key. + /// The cancellation token. + TDocument GetById(TKey id, string partitionKey, CancellationToken cancellationToken) + where TDocument : IDocument; + + /// + /// Asynchronously returns one document given an expression filter. + /// + /// The type representing a Document. + /// A LINQ expression filter. + Task GetOneAsync(Expression> filter) + where TDocument : IDocument; + + + /// + /// Asynchronously returns one document given an expression filter. + /// + /// The type representing a Document. + /// A LINQ expression filter. + /// The cancellation token + Task GetOneAsync(Expression> filter, CancellationToken cancellationToken) + where TDocument : IDocument; + + /// + /// Asynchronously returns one document given an expression filter. /// /// The type representing a Document. /// A LINQ expression filter. /// An optional partition key. - Task GetOneAsync(Expression> filter, string partitionKey = null) where TDocument : IDocument; + Task GetOneAsync(Expression> filter, string partitionKey) + where TDocument : IDocument; /// - /// Returns one document given an expression filter. + /// Asynchronously returns one document given an expression filter. /// /// The type representing a Document. /// A LINQ expression filter. /// An optional partition key. - TDocument GetOne(Expression> filter, string partitionKey = null) where TDocument : IDocument; + /// The cancellation token + Task GetOneAsync(Expression> filter, string partitionKey, CancellationToken cancellationToken) + where TDocument : IDocument; /// - /// Returns a collection cursor. + /// Returns one document given an expression filter. + /// + /// The type representing a Document. + /// A LINQ expression filter. + TDocument GetOne(Expression> filter) + where TDocument : IDocument; + + /// + /// Returns one document given an expression filter. + /// + /// The type representing a Document. + /// A LINQ expression filter. + /// The cancellation token + TDocument GetOne(Expression> filter, CancellationToken cancellationToken) + where TDocument : IDocument; + + /// + /// Returns one document given an expression filter. /// /// The type representing a Document. /// A LINQ expression filter. /// An optional partition key. - IFindFluent GetCursor(Expression> filter, string partitionKey = null) where TDocument : IDocument; + TDocument GetOne(Expression> filter, string partitionKey) + where TDocument : IDocument; /// - /// Asynchronously returns true if any of the document of the collection matches the filter condition. + /// Returns one document given an expression filter. /// /// The type representing a Document. /// A LINQ expression filter. /// An optional partition key. - Task AnyAsync(Expression> filter, string partitionKey = null) where TDocument : IDocument; + /// The cancellation token + TDocument GetOne(Expression> filter, string partitionKey, CancellationToken cancellationToken) + where TDocument : IDocument; /// - /// Returns true if any of the document of the collection matches the filter condition. + /// Returns a collection cursor. /// /// The type representing a Document. /// A LINQ expression filter. /// An optional partition key. - bool Any(Expression> filter, string partitionKey = null) where TDocument : IDocument; + IFindFluent GetCursor(Expression> filter, string partitionKey = null) + where TDocument : IDocument; /// - /// Asynchronously returns a list of the documents matching the filter condition. + /// Asynchronously returns true if any of the document of the collection matches the filter condition. + /// + /// The type representing a Document. + /// A LINQ expression filter. + Task AnyAsync(Expression> filter) + where TDocument : IDocument; + + /// + /// Asynchronously returns true if any of the document of the collection matches the filter condition. + /// + /// The type representing a Document. + /// A LINQ expression filter. + /// The cancellation token. + Task AnyAsync(Expression> filter, CancellationToken cancellationToken) + where TDocument : IDocument; + + /// + /// Asynchronously returns true if any of the document of the collection matches the filter condition. /// /// The type representing a Document. /// A LINQ expression filter. /// An optional partition key. - Task> GetAllAsync(Expression> filter, string partitionKey = null) where TDocument : IDocument; + Task AnyAsync(Expression> filter, string partitionKey) + where TDocument : IDocument; /// - /// Returns a list of the documents matching the filter condition. + /// Asynchronously returns true if any of the document of the collection matches the filter condition. /// /// The type representing a Document. /// A LINQ expression filter. /// An optional partition key. - List GetAll(Expression> filter, string partitionKey = null) where TDocument : IDocument; + /// The cancellation token. + Task AnyAsync(Expression> filter, string partitionKey, CancellationToken cancellationToken) + where TDocument : IDocument; /// - /// Asynchronously counts how many documents match the filter condition. + /// Returns true if any of the document of the collection matches the filter condition. + /// + /// The type representing a Document. + /// A LINQ expression filter. + bool Any(Expression> filter) + where TDocument : IDocument; + + /// + /// Returns true if any of the document of the collection matches the filter condition. + /// + /// The type representing a Document. + /// A LINQ expression filter. + /// The cancellation token + bool Any(Expression> filter, CancellationToken cancellationToken) + where TDocument : IDocument; + + /// + /// Returns true if any of the document of the collection matches the filter condition. /// /// The type representing a Document. /// A LINQ expression filter. /// An optional partition key. - Task CountAsync(Expression> filter, string partitionKey = null) where TDocument : IDocument; + bool Any(Expression> filter, string partitionKey) + where TDocument : IDocument; /// - /// Counts how many documents match the filter condition. + /// Returns true if any of the document of the collection matches the filter condition. /// /// The type representing a Document. /// A LINQ expression filter. /// An optional partition key. - long Count(Expression> filter, string partitionKey = null) where TDocument : IDocument; + /// The cancellation token + bool Any(Expression> filter, string partitionKey, CancellationToken cancellationToken) + where TDocument : IDocument; + + /// + /// Asynchronously returns a list of the documents matching the filter condition. + /// + /// The type representing a Document. + /// A LINQ expression filter. + Task> GetAllAsync(Expression> filter) + where TDocument : IDocument; + + /// + /// Asynchronously returns a list of the documents matching the filter condition. + /// + /// The type representing a Document. + /// A LINQ expression filter. + /// The cancellation token + Task> GetAllAsync(Expression> filter, CancellationToken cancellationToken) + where TDocument : IDocument; + + /// + /// Asynchronously returns a list of the documents matching the filter condition. + /// + /// The type representing a Document. + /// A LINQ expression filter. + /// An optional partition key. + Task> GetAllAsync(Expression> filter, string partitionKey) + where TDocument : IDocument; + + /// + /// Asynchronously returns a list of the documents matching the filter condition. + /// + /// The type representing a Document. + /// A LINQ expression filter. + /// An optional partition key. + /// The cancellation token + Task> GetAllAsync(Expression> filter, string partitionKey, CancellationToken cancellationToken) + where TDocument : IDocument; + + /// + /// Returns a list of the documents matching the filter condition. + /// + /// The type representing a Document. + /// A LINQ expression filter. + List GetAll(Expression> filter) + where TDocument : IDocument; + + /// + /// Returns a list of the documents matching the filter condition. + /// + /// The type representing a Document. + /// A LINQ expression filter. + /// The cancellation token. + List GetAll(Expression> filter, CancellationToken cancellationToken) + where TDocument : IDocument; + + /// + /// Returns a list of the documents matching the filter condition. + /// + /// The type representing a Document. + /// A LINQ expression filter. + /// An optional partition key. + List GetAll(Expression> filter, string partitionKey) + where TDocument : IDocument; + + /// + /// Returns a list of the documents matching the filter condition. + /// + /// The type representing a Document. + /// A LINQ expression filter. + /// An optional partition key. + /// The cancellation token. + List GetAll(Expression> filter, string partitionKey, CancellationToken cancellationToken) + where TDocument : IDocument; + + /// + /// Asynchronously counts how many documents match the filter condition. + /// + /// The type representing a Document. + /// A LINQ expression filter. + Task CountAsync(Expression> filter) + where TDocument : IDocument; + + /// + /// Asynchronously counts how many documents match the filter condition. + /// + /// The type representing a Document. + /// A LINQ expression filter. + /// The cancellation token. + Task CountAsync(Expression> filter, CancellationToken cancellationToken) + where TDocument : IDocument; + + /// + /// Asynchronously counts how many documents match the filter condition. + /// + /// The type representing a Document. + /// A LINQ expression filter. + /// An optional partition key. + Task CountAsync(Expression> filter, string partitionKey) + where TDocument : IDocument; + + /// + /// Asynchronously counts how many documents match the filter condition. + /// + /// The type representing a Document. + /// A LINQ expression filter. + /// An optional partition key. + /// The cancellation token. + Task CountAsync(Expression> filter, string partitionKey, CancellationToken cancellationToken) + where TDocument : IDocument; + + /// + /// Counts how many documents match the filter condition. + /// + /// The type representing a Document. + /// A LINQ expression filter. + long Count(Expression> filter) + where TDocument : IDocument; + + /// + /// Counts how many documents match the filter condition. + /// + /// The type representing a Document. + /// A LINQ expression filter. + /// The Cancellation token. + long Count(Expression> filter, CancellationToken cancellationToken) + where TDocument : IDocument; + + /// + /// Counts how many documents match the filter condition. + /// + /// The type representing a Document. + /// A LINQ expression filter. + /// An optional partition key. + long Count(Expression> filter, string partitionKey) + where TDocument : IDocument; + + /// + /// Counts how many documents match the filter condition. + /// + /// The type representing a Document. + /// A LINQ expression filter. + /// An optional partition key. + /// The Cancellation token. + long Count(Expression> filter, string partitionKey, CancellationToken cancellationToken) + where TDocument : IDocument; #endregion #region Min / Max /// - /// Gets the document with the maximum value of a specified property in a MongoDB collections that is satisfying the filter. + /// Gets the document with the maximum value of a specified property in a MongoDB collections that is satisfying the + /// filter. + /// + /// The document type. + /// A LINQ expression filter. + /// A property selector to order by descending. + Task GetByMaxAsync(Expression> filter, Expression> orderByDescending) + where TDocument : IDocument; + + /// + /// Gets the document with the maximum value of a specified property in a MongoDB collections that is satisfying the + /// filter. + /// + /// The document type. + /// A LINQ expression filter. + /// A property selector to order by descending. + /// The cancellation token. + Task GetByMaxAsync(Expression> filter, Expression> orderByDescending, CancellationToken cancellationToken) + where TDocument : IDocument; + + /// + /// Gets the document with the maximum value of a specified property in a MongoDB collections that is satisfying the + /// filter. /// /// The document type. /// A LINQ expression filter. /// A property selector to order by descending. /// An optional partitionKey. - Task GetByMaxAsync(Expression> filter, Expression> orderByDescending, string partitionKey = null) + Task GetByMaxAsync(Expression> filter, Expression> orderByDescending, string partitionKey) where TDocument : IDocument; /// - /// Gets the document with the maximum value of a specified property in a MongoDB collections that is satisfying the filter. + /// Gets the document with the maximum value of a specified property in a MongoDB collections that is satisfying the + /// filter. + /// + /// The document type. + /// A LINQ expression filter. + /// A property selector to order by descending. + /// An optional partitionKey. + /// The cancellation token. + Task GetByMaxAsync(Expression> filter, Expression> orderByDescending, string partitionKey, CancellationToken cancellationToken) + where TDocument : IDocument; + + /// + /// Gets the document with the maximum value of a specified property in a MongoDB collections that is satisfying the + /// filter. + /// + /// The document type. + /// A LINQ expression filter. + /// A property selector to order by descending. + /// + TDocument GetByMax(Expression> filter, Expression> orderByDescending) + where TDocument : IDocument; + + /// + /// Gets the document with the maximum value of a specified property in a MongoDB collections that is satisfying the + /// filter. + /// + /// The document type. + /// A LINQ expression filter. + /// A property selector to order by descending. + /// The cancellation token. + /// + TDocument GetByMax(Expression> filter, Expression> orderByDescending, CancellationToken cancellationToken) + where TDocument : IDocument; + + /// + /// Gets the document with the maximum value of a specified property in a MongoDB collections that is satisfying the + /// filter. /// /// The document type. /// A LINQ expression filter. /// A property selector to order by descending. /// An optional partitionKey. /// - TDocument GetByMax(Expression> filter, Expression> orderByDescending, string partitionKey = null) + TDocument GetByMax(Expression> filter, Expression> orderByDescending, string partitionKey) where TDocument : IDocument; /// - /// Gets the document with the maximum value of a specified property in a MongoDB collections that is satisfying the filter. + /// Gets the document with the maximum value of a specified property in a MongoDB collections that is satisfying the + /// filter. + /// + /// The document type. + /// A LINQ expression filter. + /// A property selector to order by descending. + /// An optional partitionKey. + /// The cancellation token. + /// + TDocument GetByMax(Expression> filter, Expression> orderByDescending, string partitionKey, CancellationToken cancellationToken) + where TDocument : IDocument; + + /// + /// Gets the document with the maximum value of a specified property in a MongoDB collections that is satisfying the + /// filter. + /// + /// The document type. + /// A LINQ expression filter. + /// A property selector to order by ascending. + Task GetByMinAsync(Expression> filter, Expression> orderByAscending) + where TDocument : IDocument; + + /// + /// Gets the document with the maximum value of a specified property in a MongoDB collections that is satisfying the + /// filter. + /// + /// The document type. + /// A LINQ expression filter. + /// A property selector to order by ascending. + /// The cancellation token. + Task GetByMinAsync(Expression> filter, Expression> orderByAscending, CancellationToken cancellationToken) + where TDocument : IDocument; + + /// + /// Gets the document with the maximum value of a specified property in a MongoDB collections that is satisfying the + /// filter. /// /// The document type. /// A LINQ expression filter. /// A property selector to order by ascending. /// An optional partitionKey. - Task GetByMinAsync(Expression> filter, Expression> orderByAscending, string partitionKey = null) + Task GetByMinAsync(Expression> filter, Expression> orderByAscending, string partitionKey) where TDocument : IDocument; /// - /// Gets the document with the maximum value of a specified property in a MongoDB collections that is satisfying the filter. + /// Gets the document with the maximum value of a specified property in a MongoDB collections that is satisfying the + /// filter. /// /// The document type. /// A LINQ expression filter. /// A property selector to order by ascending. /// An optional partitionKey. - TDocument GetByMin(Expression> filter, Expression> orderByAscending, string partitionKey = null) + /// The cancellation token. + Task GetByMinAsync(Expression> filter, Expression> orderByAscending, string partitionKey, CancellationToken cancellationToken) where TDocument : IDocument; /// - /// Gets the maximum value of a property in a mongodb collections that is satisfying the filter. + /// Gets the document with the maximum value of a specified property in a MongoDB collections that is satisfying the + /// filter. + /// + /// The document type. + /// A LINQ expression filter. + /// A property selector to order by ascending. + TDocument GetByMin(Expression> filter, Expression> orderByAscending) + where TDocument : IDocument; + + /// + /// Gets the document with the maximum value of a specified property in a MongoDB collections that is satisfying the + /// filter. + /// + /// The document type. + /// A LINQ expression filter. + /// A property selector to order by ascending. + /// The cancellation token. + TDocument GetByMin(Expression> filter, Expression> orderByAscending, CancellationToken cancellationToken) + where TDocument : IDocument; + + /// + /// Gets the document with the maximum value of a specified property in a MongoDB collections that is satisfying the + /// filter. + /// + /// The document type. + /// A LINQ expression filter. + /// A property selector to order by ascending. + /// An optional partitionKey. + TDocument GetByMin(Expression> filter, Expression> orderByAscending, string partitionKey) + where TDocument : IDocument; + + /// + /// Gets the document with the maximum value of a specified property in a MongoDB collections that is satisfying the + /// filter. + /// + /// The document type. + /// A LINQ expression filter. + /// A property selector to order by ascending. + /// An optional partitionKey. + /// The cancellation token. + TDocument GetByMin(Expression> filter, Expression> orderByAscending, string partitionKey, CancellationToken cancellationToken) + where TDocument : IDocument; + + /// + /// Gets the maximum value of a property in a mongodb collections that is satisfying the filter. + /// + /// The document type. + /// The type of the value used to order the query. + /// A LINQ expression filter. + /// A property selector to order by ascending. + Task GetMaxValueAsync(Expression> filter, Expression> maxValueSelector) + where TDocument : IDocument; + + /// + /// Gets the maximum value of a property in a mongodb collections that is satisfying the filter. + /// + /// The document type. + /// The type of the value used to order the query. + /// A LINQ expression filter. + /// A property selector to order by ascending. + /// The cancellation token. + Task GetMaxValueAsync(Expression> filter, Expression> maxValueSelector, CancellationToken cancellationToken) + where TDocument : IDocument; + + /// + /// Gets the maximum value of a property in a mongodb collections that is satisfying the filter. /// /// The document type. /// The type of the value used to order the query. /// A LINQ expression filter. /// A property selector to order by ascending. /// An optional partitionKey. - Task GetMaxValueAsync(Expression> filter, Expression> maxValueSelector, string partitionKey = null) + Task GetMaxValueAsync(Expression> filter, Expression> maxValueSelector, string partitionKey) where TDocument : IDocument; /// - /// Gets the maximum value of a property in a mongodb collections that is satisfying the filter. + /// Gets the maximum value of a property in a mongodb collections that is satisfying the filter. /// /// The document type. /// The type of the value used to order the query. /// A LINQ expression filter. /// A property selector to order by ascending. /// An optional partitionKey. - TValue GetMaxValue(Expression> filter, Expression> maxValueSelector, string partitionKey = null) + /// The cancellation token. + Task GetMaxValueAsync(Expression> filter, Expression> maxValueSelector, string partitionKey, CancellationToken cancellationToken) where TDocument : IDocument; /// - /// Gets the minimum value of a property in a mongodb collections that is satisfying the filter. + /// Gets the maximum value of a property in a mongodb collections that is satisfying the filter. + /// + /// The document type. + /// The type of the value used to order the query. + /// A LINQ expression filter. + /// A property selector to order by ascending. + TValue GetMaxValue(Expression> filter, Expression> maxValueSelector) + where TDocument : IDocument; + + /// + /// Gets the maximum value of a property in a mongodb collections that is satisfying the filter. + /// + /// The document type. + /// The type of the value used to order the query. + /// A LINQ expression filter. + /// A property selector to order by ascending. + /// The cancellation token. + TValue GetMaxValue(Expression> filter, Expression> maxValueSelector, CancellationToken cancellationToken) + where TDocument : IDocument; + + + /// + /// Gets the maximum value of a property in a mongodb collections that is satisfying the filter. + /// + /// The document type. + /// The type of the value used to order the query. + /// A LINQ expression filter. + /// A property selector to order by ascending. + /// An optional partitionKey. + TValue GetMaxValue(Expression> filter, Expression> maxValueSelector, string partitionKey) + where TDocument : IDocument; + + /// + /// Gets the maximum value of a property in a mongodb collections that is satisfying the filter. + /// + /// The document type. + /// The type of the value used to order the query. + /// A LINQ expression filter. + /// A property selector to order by ascending. + /// An optional partitionKey. + /// The cancellation token. + TValue GetMaxValue(Expression> filter, Expression> maxValueSelector, string partitionKey, CancellationToken cancellationToken) + where TDocument : IDocument; + + /// + /// Gets the minimum value of a property in a mongodb collections that is satisfying the filter. + /// + /// The document type. + /// The type of the value used to order the query. + /// A LINQ expression filter. + /// A property selector to order by ascending. + Task GetMinValueAsync(Expression> filter, Expression> minValueSelector) + where TDocument : IDocument; + + + /// + /// Gets the minimum value of a property in a mongodb collections that is satisfying the filter. + /// + /// The document type. + /// The type of the value used to order the query. + /// A LINQ expression filter. + /// A property selector to order by ascending. + /// The cancellation token. + Task GetMinValueAsync(Expression> filter, Expression> minValueSelector, CancellationToken cancellationToken) + where TDocument : IDocument; + + + /// + /// Gets the minimum value of a property in a mongodb collections that is satisfying the filter. /// /// The document type. /// The type of the value used to order the query. /// A LINQ expression filter. /// A property selector to order by ascending. /// An optional partition key. - Task GetMinValueAsync(Expression> filter, Expression> minValueSelector, string partitionKey = null) + Task GetMinValueAsync(Expression> filter, Expression> minValueSelector, string partitionKey) where TDocument : IDocument; /// - /// Gets the minimum value of a property in a mongodb collections that is satisfying the filter. + /// Gets the minimum value of a property in a mongodb collections that is satisfying the filter. /// /// The document type. /// The type of the value used to order the query. /// A LINQ expression filter. /// A property selector to order by ascending. /// An optional partition key. - TValue GetMinValue(Expression> filter, Expression> minValueSelector, string partitionKey = null) + /// The cancellation token. + Task GetMinValueAsync(Expression> filter, Expression> minValueSelector, string partitionKey, CancellationToken cancellationToken) + where TDocument : IDocument; + + /// + /// Gets the minimum value of a property in a mongodb collections that is satisfying the filter. + /// + /// The document type. + /// The type of the value used to order the query. + /// A LINQ expression filter. + /// A property selector to order by ascending. + TValue GetMinValue(Expression> filter, Expression> minValueSelector) + where TDocument : IDocument; + + /// + /// Gets the minimum value of a property in a mongodb collections that is satisfying the filter. + /// + /// The document type. + /// The type of the value used to order the query. + /// A LINQ expression filter. + /// A property selector to order by ascending. + /// The cancellation token. + TValue GetMinValue(Expression> filter, Expression> minValueSelector, CancellationToken cancellationToken) + where TDocument : IDocument; + + + /// + /// Gets the minimum value of a property in a mongodb collections that is satisfying the filter. + /// + /// The document type. + /// The type of the value used to order the query. + /// A LINQ expression filter. + /// A property selector to order by ascending. + /// An optional partition key. + TValue GetMinValue(Expression> filter, Expression> minValueSelector, string partitionKey) + where TDocument : IDocument; + + /// + /// Gets the minimum value of a property in a mongodb collections that is satisfying the filter. + /// + /// The document type. + /// The type of the value used to order the query. + /// A LINQ expression filter. + /// A property selector to order by ascending. + /// An optional partition key. + /// The cancellation token. + TValue GetMinValue(Expression> filter, Expression> minValueSelector, string partitionKey, CancellationToken cancellationToken) where TDocument : IDocument; #endregion @@ -198,51 +757,109 @@ namespace MongoDbGenericRepository #region Maths /// - /// Sums the values of a selected field for a given filtered collection of documents. + /// Sums the values of a selected field for a given filtered collection of documents. /// /// The type representing a Document. /// A LINQ expression filter. /// The field you want to sum. - /// The partition key of your document, if any. - Task SumByAsync(Expression> filter, - Expression> selector, - string partitionKey = null) + Task SumByAsync(Expression> filter, Expression> selector) where TDocument : IDocument; /// - /// Sums the values of a selected field for a given filtered collection of documents. + /// Sums the values of a selected field for a given filtered collection of documents. /// /// The type representing a Document. /// A LINQ expression filter. /// The field you want to sum. - /// The partition key of your document, if any. - Task SumByAsync(Expression> filter, - Expression> selector, - string partitionKey = null) + /// The cancellation token. + Task SumByAsync(Expression> filter, Expression> selector, CancellationToken cancellationToken) where TDocument : IDocument; /// - /// Sums the values of a selected field for a given filtered collection of documents. + /// Sums the values of a selected field for a given filtered collection of documents. /// /// The type representing a Document. /// A LINQ expression filter. /// The field you want to sum. /// The partition key of your document, if any. - int SumBy(Expression> filter, - Expression> selector, - string partitionKey = null) + Task SumByAsync(Expression> filter, Expression> selector, string partitionKey) where TDocument : IDocument; /// - /// Sums the values of a selected field for a given filtered collection of documents. + /// Sums the values of a selected field for a given filtered collection of documents. /// /// The type representing a Document. /// A LINQ expression filter. /// The field you want to sum. /// The partition key of your document, if any. - decimal SumBy(Expression> filter, - Expression> selector, - string partitionKey = null) + /// The cancellation token. + Task SumByAsync(Expression> filter, Expression> selector, string partitionKey, CancellationToken cancellationToken) + where TDocument : IDocument; + + /// + /// Sums the values of a selected field for a given filtered collection of documents. + /// + /// The type representing a Document. + /// A LINQ expression filter. + /// The field you want to sum. + Task SumByAsync(Expression> filter, Expression> selector) + where TDocument : IDocument; + + /// + /// Sums the values of a selected field for a given filtered collection of documents. + /// + /// The type representing a Document. + /// A LINQ expression filter. + /// The field you want to sum. + /// The cancellation token. + Task SumByAsync(Expression> filter, Expression> selector, CancellationToken cancellationToken) + where TDocument : IDocument; + + /// + /// Sums the values of a selected field for a given filtered collection of documents. + /// + /// The type representing a Document. + /// A LINQ expression filter. + /// The field you want to sum. + /// The partition key of your document, if any. + Task SumByAsync(Expression> filter, Expression> selector, string partitionKey) + where TDocument : IDocument; + + /// + /// Sums the values of a selected field for a given filtered collection of documents. + /// + /// The type representing a Document. + /// A LINQ expression filter. + /// The field you want to sum. + /// The partition key of your document, if any. + /// The cancellation token. + Task SumByAsync(Expression> filter, Expression> selector, string partitionKey, CancellationToken cancellationToken) + where TDocument : IDocument; + + /// + /// Sums the values of a selected field for a given filtered collection of documents. + /// + /// The type representing a Document. + /// A LINQ expression filter. + /// The field you want to sum. + /// The partition key of your document, if any. + int SumBy( + Expression> filter, + Expression> selector, + string partitionKey = null) + where TDocument : IDocument; + + /// + /// Sums the values of a selected field for a given filtered collection of documents. + /// + /// The type representing a Document. + /// A LINQ expression filter. + /// The field you want to sum. + /// The partition key of your document, if any. + decimal SumBy( + Expression> filter, + Expression> selector, + string partitionKey = null) where TDocument : IDocument; #endregion Maths @@ -250,50 +867,193 @@ namespace MongoDbGenericRepository #region Project /// - /// Asynchronously returns a projected document matching the filter condition. + /// Asynchronously returns a projected document matching the filter condition. /// /// The type representing a Document. /// The type representing the model you want to project to. /// A LINQ expression filter. /// The projection expression. - /// An optional partition key. - Task ProjectOneAsync(Expression> filter, Expression> projection, string partitionKey = null) + Task ProjectOneAsync(Expression> filter, Expression> projection) where TDocument : IDocument where TProjection : class; /// - /// Returns a projected document matching the filter condition. + /// Asynchronously returns a projected document matching the filter condition. /// /// The type representing a Document. /// The type representing the model you want to project to. /// A LINQ expression filter. /// The projection expression. - /// An optional partition key. - TProjection ProjectOne(Expression> filter, Expression> projection, string partitionKey = null) + /// The cancellation token + Task ProjectOneAsync(Expression> filter, Expression> projection, CancellationToken cancellationToken) where TDocument : IDocument where TProjection : class; /// - /// Asynchronously returns a list of projected documents matching the filter condition. + /// Asynchronously returns a projected document matching the filter condition. /// /// The type representing a Document. /// The type representing the model you want to project to. /// A LINQ expression filter. /// The projection expression. /// An optional partition key. - Task> ProjectManyAsync(Expression> filter, Expression> projection, string partitionKey = null) + Task ProjectOneAsync(Expression> filter, Expression> projection, string partitionKey) where TDocument : IDocument where TProjection : class; /// - /// Asynchronously returns a list of projected documents matching the filter condition. + /// Asynchronously returns a projected document matching the filter condition. /// /// The type representing a Document. /// The type representing the model you want to project to. /// A LINQ expression filter. /// The projection expression. /// An optional partition key. - List ProjectMany(Expression> filter, Expression> projection, string partitionKey = null) + /// The cancellation token + Task ProjectOneAsync(Expression> filter, Expression> projection, string partitionKey, CancellationToken cancellationToken) + where TDocument : IDocument + where TProjection : class; + /// + /// Returns a projected document matching the filter condition. + /// + /// The type representing a Document. + /// The type representing the model you want to project to. + /// A LINQ expression filter. + /// The projection expression. + TProjection ProjectOne(Expression> filter, Expression> projection) + where TDocument : IDocument + where TProjection : class; + + /// + /// Returns a projected document matching the filter condition. + /// + /// The type representing a Document. + /// The type representing the model you want to project to. + /// A LINQ expression filter. + /// The projection expression. + /// The cancellation token. + TProjection ProjectOne(Expression> filter, Expression> projection, CancellationToken cancellationToken) + where TDocument : IDocument + where TProjection : class; + + /// + /// Returns a projected document matching the filter condition. + /// + /// The type representing a Document. + /// The type representing the model you want to project to. + /// A LINQ expression filter. + /// The projection expression. + /// An optional partition key. + TProjection ProjectOne(Expression> filter, Expression> projection, string partitionKey) + where TDocument : IDocument + where TProjection : class; + + /// + /// Returns a projected document matching the filter condition. + /// + /// The type representing a Document. + /// The type representing the model you want to project to. + /// A LINQ expression filter. + /// The projection expression. + /// An optional partition key. + /// The cancellation token. + TProjection ProjectOne(Expression> filter, Expression> projection, string partitionKey, CancellationToken cancellationToken) + where TDocument : IDocument + where TProjection : class; + + /// + /// Asynchronously returns a list of projected documents matching the filter condition. + /// + /// The type representing a Document. + /// The type representing the model you want to project to. + /// A LINQ expression filter. + /// The projection expression. + Task> ProjectManyAsync(Expression> filter, Expression> projection) + where TDocument : IDocument + where TProjection : class; + + /// + /// Asynchronously returns a list of projected documents matching the filter condition. + /// + /// The type representing a Document. + /// The type representing the model you want to project to. + /// A LINQ expression filter. + /// The projection expression. + /// The cancellation token. + Task> ProjectManyAsync(Expression> filter, Expression> projection, CancellationToken cancellationToken) + where TDocument : IDocument + where TProjection : class; + + /// + /// Asynchronously returns a list of projected documents matching the filter condition. + /// + /// The type representing a Document. + /// The type representing the model you want to project to. + /// A LINQ expression filter. + /// The projection expression. + /// An optional partition key. + Task> ProjectManyAsync(Expression> filter, Expression> projection, string partitionKey) + where TDocument : IDocument + where TProjection : class; + + /// + /// Asynchronously returns a list of projected documents matching the filter condition. + /// + /// The type representing a Document. + /// The type representing the model you want to project to. + /// A LINQ expression filter. + /// The projection expression. + /// An optional partition key. + /// The cancellation token. + Task> ProjectManyAsync(Expression> filter, Expression> projection, string partitionKey, CancellationToken cancellationToken) + where TDocument : IDocument + where TProjection : class; + + /// + /// Asynchronously returns a list of projected documents matching the filter condition. + /// + /// The type representing a Document. + /// The type representing the model you want to project to. + /// A LINQ expression filter. + /// The projection expression. + List ProjectMany(Expression> filter, Expression> projection) + where TDocument : IDocument + where TProjection : class; + + /// + /// Asynchronously returns a list of projected documents matching the filter condition. + /// + /// The type representing a Document. + /// The type representing the model you want to project to. + /// A LINQ expression filter. + /// The projection expression. + /// The cancellation token + List ProjectMany(Expression> filter, Expression> projection, CancellationToken cancellationToken) + where TDocument : IDocument + where TProjection : class; + + /// + /// Asynchronously returns a list of projected documents matching the filter condition. + /// + /// The type representing a Document. + /// The type representing the model you want to project to. + /// A LINQ expression filter. + /// The projection expression. + /// An optional partition key. + List ProjectMany(Expression> filter, Expression> projection, string partitionKey) + where TDocument : IDocument + where TProjection : class; + + /// + /// Asynchronously returns a list of projected documents matching the filter condition. + /// + /// The type representing a Document. + /// The type representing the model you want to project to. + /// A LINQ expression filter. + /// The projection expression. + /// An optional partition key. + /// The cancellation token + List ProjectMany(Expression> filter, Expression> projection, string partitionKey, CancellationToken cancellationToken) where TDocument : IDocument where TProjection : class; @@ -302,8 +1062,35 @@ namespace MongoDbGenericRepository #region Group By /// - /// Groups a collection of documents given a grouping criteria, - /// and returns a dictionary of listed document groups with keys having the different values of the grouping criteria. + /// Groups a collection of documents given a grouping criteria, + /// and returns a dictionary of listed document groups with keys having the different values of the grouping criteria. + /// + /// The type representing a Document. + /// The type of the grouping criteria. + /// The type of the projected group. + /// The grouping criteria. + /// The projected group result. + List GroupBy(Expression> groupingCriteria, Expression, TProjection>> groupProjection) + where TDocument : IDocument + where TProjection : class, new(); + + /// + /// Groups a collection of documents given a grouping criteria, + /// and returns a dictionary of listed document groups with keys having the different values of the grouping criteria. + /// + /// The type representing a Document. + /// The type of the grouping criteria. + /// The type of the projected group. + /// The grouping criteria. + /// The projected group result. + /// The cancellation token. + List GroupBy(Expression> groupingCriteria, Expression, TProjection>> groupProjection, CancellationToken cancellationToken) + where TDocument : IDocument + where TProjection : class, new(); + + /// + /// Groups a collection of documents given a grouping criteria, + /// and returns a dictionary of listed document groups with keys having the different values of the grouping criteria. /// /// The type representing a Document. /// The type of the grouping criteria. @@ -311,16 +1098,57 @@ namespace MongoDbGenericRepository /// The grouping criteria. /// The projected group result. /// The partition key of your document, if any. - List GroupBy( - Expression> groupingCriteria, - Expression, TProjection>> groupProjection, - string partitionKey = null) + List GroupBy(Expression> groupingCriteria, Expression, TProjection>> groupProjection, string partitionKey) where TDocument : IDocument where TProjection : class, new(); /// - /// Groups filtered a collection of documents given a grouping criteria, - /// and returns a dictionary of listed document groups with keys having the different values of the grouping criteria. + /// Groups a collection of documents given a grouping criteria, + /// and returns a dictionary of listed document groups with keys having the different values of the grouping criteria. + /// + /// The type representing a Document. + /// The type of the grouping criteria. + /// The type of the projected group. + /// The grouping criteria. + /// The projected group result. + /// The partition key of your document, if any. + /// The cancellation token. + List GroupBy(Expression> groupingCriteria, Expression, TProjection>> groupProjection, string partitionKey, CancellationToken cancellationToken) + where TDocument : IDocument + where TProjection : class, new(); + + /// + /// Groups filtered a collection of documents given a grouping criteria, + /// and returns a dictionary of listed document groups with keys having the different values of the grouping criteria. + /// + /// The type representing a Document. + /// The type of the grouping criteria. + /// The type of the projected group. + /// A LINQ expression filter. + /// The grouping criteria. + /// The projected group result. + List GroupBy(Expression> filter, Expression> groupingCriteria, Expression, TProjection>> groupProjection) + where TDocument : IDocument + where TProjection : class, new(); + + /// + /// Groups filtered a collection of documents given a grouping criteria, + /// and returns a dictionary of listed document groups with keys having the different values of the grouping criteria. + /// + /// The type representing a Document. + /// The type of the grouping criteria. + /// The type of the projected group. + /// A LINQ expression filter. + /// The grouping criteria. + /// The projected group result. + /// The cancellation token. + List GroupBy(Expression> filter, Expression> groupingCriteria, Expression, TProjection>> groupProjection, CancellationToken cancellationToken) + where TDocument : IDocument + where TProjection : class, new(); + + /// + /// Groups filtered a collection of documents given a grouping criteria, + /// and returns a dictionary of listed document groups with keys having the different values of the grouping criteria. /// /// The type representing a Document. /// The type of the grouping criteria. @@ -329,20 +1157,32 @@ namespace MongoDbGenericRepository /// The grouping criteria. /// The projected group result. /// The partition key of your document, if any. - List GroupBy( - Expression> filter, - Expression> groupingCriteria, - Expression, TProjection>> groupProjection, - string partitionKey = null) - where TDocument : IDocument - where TProjection : class, new(); + List GroupBy(Expression> filter, Expression> groupingCriteria, Expression, TProjection>> groupProjection, string partitionKey) + where TDocument : IDocument + where TProjection : class, new(); + + /// + /// Groups filtered a collection of documents given a grouping criteria, + /// and returns a dictionary of listed document groups with keys having the different values of the grouping criteria. + /// + /// The type representing a Document. + /// The type of the grouping criteria. + /// The type of the projected group. + /// A LINQ expression filter. + /// The grouping criteria. + /// The projected group result. + /// The partition key of your document, if any. + /// The cancellation token. + List GroupBy(Expression> filter, Expression> groupingCriteria, Expression, TProjection>> groupProjection, string partitionKey, CancellationToken cancellationToken) + where TDocument : IDocument + where TProjection : class, new(); #endregion Group By #region Pagination /// - /// Asynchronously returns a paginated list of the documents matching the filter condition. + /// Asynchronously returns a paginated list of the documents matching the filter condition. /// /// The type representing a Document. /// A LINQ expression filter. @@ -351,17 +1191,19 @@ namespace MongoDbGenericRepository /// The number of documents you want to skip. Default value is 0. /// The number of documents you want to take. Default value is 50. /// An optional partition key. + /// An optional cancellation token. Task> GetSortedPaginatedAsync( Expression> filter, Expression> sortSelector, bool ascending = true, int skipNumber = 0, int takeNumber = 50, - string partitionKey = null) + string partitionKey = null, + CancellationToken cancellationToken = default) where TDocument : IDocument; /// - /// Asynchronously returns a paginated list of the documents matching the filter condition. + /// Asynchronously returns a paginated list of the documents matching the filter condition. /// /// The type representing a Document. /// A LINQ expression filter. @@ -369,12 +1211,14 @@ namespace MongoDbGenericRepository /// The number of documents you want to skip. Default value is 0. /// The number of documents you want to take. Default value is 50. /// An optional partition key. + /// An optional cancellation token. Task> GetSortedPaginatedAsync( Expression> filter, SortDefinition sortDefinition, int skipNumber = 0, int takeNumber = 50, - string partitionKey = null) + string partitionKey = null, + CancellationToken cancellationToken = default) where TDocument : IDocument; #endregion Pagination diff --git a/MongoDbGenericRepository/KeyTypedRepository/BaseMongoRepository.TKey.ReadOnly.cs b/MongoDbGenericRepository/KeyTypedRepository/BaseMongoRepository.TKey.ReadOnly.cs index 55691d4..8cbe59a 100644 --- a/MongoDbGenericRepository/KeyTypedRepository/BaseMongoRepository.TKey.ReadOnly.cs +++ b/MongoDbGenericRepository/KeyTypedRepository/BaseMongoRepository.TKey.ReadOnly.cs @@ -1,42 +1,34 @@ -using MongoDB.Driver; -using MongoDbGenericRepository.DataAccess.Read; -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.Read; +using MongoDbGenericRepository.Models; namespace MongoDbGenericRepository { /// - /// The base Repository, it is meant to be inherited from by your custom custom MongoRepository implementation. - /// Its constructor must be given a connection string and a database name. + /// The base Repository, it is meant to be inherited from by your custom custom MongoRepository implementation. + /// Its constructor must be given a connection string and a database name. /// - public abstract partial class ReadOnlyMongoRepository : IReadOnlyMongoRepository where TKey : IEquatable + public abstract class ReadOnlyMongoRepository : IReadOnlyMongoRepository + where TKey : IEquatable { /// - /// The connection string. + /// The MongoDbContext /// - public string ConnectionString { get; protected set; } + protected IMongoDbContext MongoDbContext { get; set; } /// - /// The database name. + /// A MongoDb Reader for read operations /// - public string DatabaseName { get; protected set; } + protected IMongoDbReader MongoDbReader { get; set; } /// - /// The MongoDbContext - /// - protected IMongoDbContext MongoDbContext; - - /// - /// A MongoDb Reader for read operations - /// - protected IMongoDbReader MongoDbReader; - - /// - /// The constructor taking a connection string and a database name. + /// The constructor taking a connection string and a database name. /// /// The connection string of the MongoDb server. /// The name of the database against which you want to perform operations. @@ -46,24 +38,167 @@ namespace MongoDbGenericRepository } /// - /// The constructor taking a . + /// The constructor taking a . /// - /// A mongodb context implementing - protected ReadOnlyMongoRepository(IMongoDatabase mongoDatabase) : this(new MongoDbContext(mongoDatabase)) + /// A mongodb context implementing + protected ReadOnlyMongoRepository(IMongoDatabase mongoDatabase) + : this(new MongoDbContext(mongoDatabase)) { } /// - /// The constructor taking a . + /// The constructor taking a . /// - /// A mongodb context implementing + /// A mongodb context implementing protected ReadOnlyMongoRepository(IMongoDbContext mongoDbContext) { SetupMongoDbContext(mongoDbContext); } /// - /// Setups the repository with a . + /// The connection string. + /// + public string ConnectionString { get; protected set; } + + /// + /// The database name. + /// + public string DatabaseName { get; protected set; } + + /// + public virtual List GroupBy( + Expression> groupingCriteria, + Expression, TProjection>> groupProjection) + where TDocument : IDocument + where TProjection : class, new() + { + return GroupBy(groupingCriteria, groupProjection, null, CancellationToken.None); + } + + /// + public virtual List GroupBy( + Expression> groupingCriteria, + Expression, TProjection>> groupProjection, + CancellationToken cancellationToken) + where TDocument : IDocument + where TProjection : class, new() + { + return GroupBy(groupingCriteria, groupProjection, null, cancellationToken); + } + + /// + public virtual List GroupBy( + Expression> groupingCriteria, + Expression, TProjection>> groupProjection, + string partitionKey) + where TDocument : IDocument + where TProjection : class, new() + { + return GroupBy(groupingCriteria, groupProjection, partitionKey, CancellationToken.None); + } + + /// + public virtual List GroupBy( + Expression> groupingCriteria, + Expression, TProjection>> groupProjection, + string partitionKey, + CancellationToken cancellationToken) + where TDocument : IDocument + where TProjection : class, new() + { + return MongoDbReader.GroupBy(groupingCriteria, groupProjection, partitionKey, cancellationToken); + } + + /// + public virtual List GroupBy( + Expression> filter, + Expression> groupingCriteria, + Expression, TProjection>> groupProjection) + where TDocument : IDocument + where TProjection : class, new() + { + return GroupBy(filter, groupingCriteria, groupProjection, null, CancellationToken.None); + } + + /// + public virtual List GroupBy( + Expression> filter, + Expression> groupingCriteria, + Expression, TProjection>> groupProjection, + CancellationToken cancellationToken) + where TDocument : IDocument + where TProjection : class, new() + { + return GroupBy(filter, groupingCriteria, groupProjection, null, cancellationToken); + } + + /// + public virtual List GroupBy( + Expression> filter, + Expression> groupingCriteria, + Expression, TProjection>> groupProjection, + string partitionKey) + where TDocument : IDocument + where TProjection : class, new() + { + return GroupBy(filter, groupingCriteria, groupProjection, partitionKey, CancellationToken.None); + } + + /// + public virtual List GroupBy( + Expression> filter, + Expression> groupingCriteria, + Expression, TProjection>> groupProjection, + string partitionKey, + CancellationToken cancellationToken) + where TDocument : IDocument + where TProjection : class, new() + { + return MongoDbReader.GroupBy(filter, groupingCriteria, groupProjection, partitionKey, cancellationToken); + } + + /// + public virtual async Task> GetSortedPaginatedAsync( + Expression> filter, + Expression> sortSelector, + bool ascending = true, + int skipNumber = 0, + int takeNumber = 50, + string partitionKey = null, + CancellationToken cancellationToken = default) + where TDocument : IDocument + { + return await MongoDbReader.GetSortedPaginatedAsync( + filter, + sortSelector, + ascending, + skipNumber, + takeNumber, + partitionKey, + cancellationToken); + } + + /// + public virtual async Task> GetSortedPaginatedAsync( + Expression> filter, + SortDefinition sortDefinition, + int skipNumber = 0, + int takeNumber = 50, + string partitionKey = null, + CancellationToken cancellationToken = default) + where TDocument : IDocument + { + return await MongoDbReader.GetSortedPaginatedAsync( + filter, + sortDefinition, + skipNumber, + takeNumber, + partitionKey, + cancellationToken); + } + + /// + /// Setups the repository with a . /// /// protected void SetupMongoDbContext(IMongoDbContext mongoDbContext) @@ -73,10 +208,13 @@ namespace MongoDbGenericRepository } /// - /// Setups the repository with a connection string and a database name. + /// Setups the repository with a connection string and a database name. /// /// - /// The database name. If the database name is null or whitespace it is taken from the connection string + /// + /// The database name. If the database name is null or whitespace it is taken from the + /// connection string + /// protected void SetupMongoDbContext(string connectionString, string databaseName) { if (string.IsNullOrWhiteSpace(databaseName)) @@ -92,295 +230,697 @@ namespace MongoDbGenericRepository #region Read - /// - /// Asynchronously returns one document given its id. - /// - /// The type representing a Document. - /// The Id of the document you want to get. - /// An optional partition key. - public async Task GetByIdAsync(TKey id, string partitionKey = null) where TDocument : IDocument + /// + public async Task GetByIdAsync(TKey id) + where TDocument : IDocument { - return await MongoDbReader.GetByIdAsync(id, partitionKey); + return await GetByIdAsync(id, null, CancellationToken.None); } - /// - /// Returns one document given its id. - /// - /// The type representing a Document. - /// The Id of the document you want to get. - /// An optional partition key. - public TDocument GetById(TKey id, string partitionKey = null) where TDocument : IDocument + /// + public async Task GetByIdAsync(TKey id, CancellationToken cancellationToken) + where TDocument : IDocument { - return MongoDbReader.GetById(id, partitionKey); + return await GetByIdAsync(id, null, cancellationToken); } - /// - /// Asynchronously returns one document given an expression filter. - /// - /// The type representing a Document. - /// A LINQ expression filter. - /// An optional partition key. - public async Task GetOneAsync(Expression> filter, string partitionKey = null) where TDocument : IDocument + /// + public async Task GetByIdAsync(TKey id, string partitionKey) + where TDocument : IDocument { - return await MongoDbReader.GetOneAsync(filter, partitionKey); + return await GetByIdAsync(id, partitionKey, CancellationToken.None); } - /// - /// Returns one document given an expression filter. - /// - /// The type representing a Document. - /// A LINQ expression filter. - /// An optional partition key. - public TDocument GetOne(Expression> filter, string partitionKey = null) where TDocument : IDocument + /// + public async Task GetByIdAsync(TKey id, string partitionKey, CancellationToken cancellationToken) + where TDocument : IDocument { - return MongoDbReader.GetOne(filter, partitionKey); + return await MongoDbReader.GetByIdAsync(id, partitionKey, cancellationToken); } - /// - /// Returns a collection cursor. - /// - /// The type representing a Document. - /// A LINQ expression filter. - /// An optional partition key. - public IFindFluent GetCursor(Expression> filter, string partitionKey = null) where TDocument : IDocument + /// + public TDocument GetById(TKey id) + where TDocument : IDocument + { + return GetById(id, null, CancellationToken.None); + } + + /// + public TDocument GetById(TKey id, CancellationToken cancellationToken) + where TDocument : IDocument + { + return GetById(id, null, cancellationToken); + } + + /// + public TDocument GetById(TKey id, string partitionKey) + where TDocument : IDocument + { + return GetById(id, partitionKey, CancellationToken.None); + } + + /// + public TDocument GetById(TKey id, string partitionKey, CancellationToken cancellationToken) + where TDocument : IDocument + { + return MongoDbReader.GetById(id, partitionKey, cancellationToken); + } + + /// + public async Task GetOneAsync(Expression> filter) + where TDocument : IDocument + { + return await GetOneAsync(filter, null, CancellationToken.None); + } + + /// + public async Task GetOneAsync(Expression> filter, CancellationToken cancellationToken) + where TDocument : IDocument + { + return await GetOneAsync(filter, null, cancellationToken); + } + + /// + public async Task GetOneAsync(Expression> filter, string partitionKey) + where TDocument : IDocument + { + return await GetOneAsync(filter, partitionKey, CancellationToken.None); + } + + /// + public async Task GetOneAsync(Expression> filter, string partitionKey, CancellationToken cancellationToken) + where TDocument : IDocument + { + return await MongoDbReader.GetOneAsync(filter, partitionKey, cancellationToken); + } + + /// + public TDocument GetOne(Expression> filter) + where TDocument : IDocument + { + return GetOne(filter, null, CancellationToken.None); + } + + /// + public TDocument GetOne(Expression> filter, CancellationToken cancellationToken) + where TDocument : IDocument + { + return GetOne(filter, null, cancellationToken); + } + + /// + public TDocument GetOne(Expression> filter, string partitionKey) + where TDocument : IDocument + { + return GetOne(filter, partitionKey, CancellationToken.None); + } + + /// + public TDocument GetOne(Expression> filter, string partitionKey, CancellationToken cancellationToken) + where TDocument : IDocument + { + return MongoDbReader.GetOne(filter, partitionKey, cancellationToken); + } + + /// + public IFindFluent GetCursor(Expression> filter, string partitionKey = null) + where TDocument : IDocument { return MongoDbReader.GetCursor(filter, partitionKey); } - /// - /// Returns true if any of the document of the collection matches the filter condition. - /// - /// The type representing a Document. - /// A LINQ expression filter. - /// An optional partition key. - public async Task AnyAsync(Expression> filter, string partitionKey = null) where TDocument : IDocument - { - return await MongoDbReader.AnyAsync(filter, partitionKey); - } - - /// - /// Returns true if any of the document of the collection matches the filter condition. - /// - /// The type representing a Document. - /// A LINQ expression filter. - /// An optional partition key. - public bool Any(Expression> filter, string partitionKey = null) where TDocument : IDocument - { - return MongoDbReader.Any(filter, partitionKey); - } - - /// - /// Asynchronously returns a list of the documents matching the filter condition. - /// - /// The type representing a Document. - /// A LINQ expression filter. - /// An optional partition key. - public async Task> GetAllAsync(Expression> filter, string partitionKey = null) where TDocument : IDocument - { - return await MongoDbReader.GetAllAsync(filter, partitionKey); - } - - /// - /// Returns a list of the documents matching the filter condition. - /// - /// The type representing a Document. - /// A LINQ expression filter. - /// An optional partition key. - public List GetAll(Expression> filter, string partitionKey = null) where TDocument : IDocument - { - return MongoDbReader.GetAll(filter, partitionKey); - } - - /// - /// Asynchronously counts how many documents match the filter condition. - /// - /// The type representing a Document. - /// A LINQ expression filter. - /// An optional partitionKey - public async Task CountAsync(Expression> filter, string partitionKey = null) where TDocument : IDocument - { - return await MongoDbReader.CountAsync(filter, partitionKey); - } - - /// - /// Counts how many documents match the filter condition. - /// - /// The type representing a Document. - /// A LINQ expression filter. - /// An optional partitionKey - public long Count(Expression> filter, string partitionKey = null) where TDocument : IDocument - { - return MongoDbReader.Count(filter, partitionKey); - } - - /// - /// Gets the document with the maximum value of a specified property in a MongoDB collections that is satisfying the filter. - /// - /// The document type. - /// A LINQ expression filter. - /// A property selector to order by descending. - /// An optional partitionKey. - public async Task GetByMaxAsync(Expression> filter, Expression> maxValueSelector, string partitionKey = null) + /// + public async Task AnyAsync(Expression> filter) where TDocument : IDocument { - return await MongoDbReader.GetByMaxAsync(filter, maxValueSelector, partitionKey); + return await AnyAsync(filter, null, CancellationToken.None); } - /// - /// Gets the document with the maximum value of a specified property in a MongoDB collections that is satisfying the filter. - /// - /// The document type. - /// A LINQ expression filter. - /// A property selector to order by descending. - /// An optional partitionKey. - /// - public TDocument GetByMax(Expression> filter, Expression> maxValueSelector, string partitionKey = null) + /// + public async Task AnyAsync(Expression> filter, CancellationToken cancellationToken) + where TDocument : IDocument + { + return await AnyAsync(filter, null, cancellationToken); + } + + /// + public async Task AnyAsync(Expression> filter, string partitionKey) + where TDocument : IDocument + { + return await AnyAsync(filter, partitionKey, CancellationToken.None); + } + + /// + public async Task AnyAsync(Expression> filter, string partitionKey, CancellationToken cancellationToken) + where TDocument : IDocument + { + return await MongoDbReader.AnyAsync(filter, partitionKey, cancellationToken); + } + + /// + public bool Any(Expression> filter) + where TDocument : IDocument + { + return Any(filter, null, CancellationToken.None); + } + + /// + public bool Any(Expression> filter, CancellationToken cancellationToken) + where TDocument : IDocument + { + return Any(filter, null, cancellationToken); + } + + /// + public bool Any(Expression> filter, string partitionKey) + where TDocument : IDocument + { + return Any(filter, partitionKey, CancellationToken.None); + } + + /// + public bool Any(Expression> filter, string partitionKey, CancellationToken cancellationToken) + where TDocument : IDocument + { + return MongoDbReader.Any(filter, partitionKey, cancellationToken); + } + + /// + public async Task> GetAllAsync(Expression> filter) + where TDocument : IDocument + { + return await GetAllAsync(filter, null, CancellationToken.None); + } + + /// + public async Task> GetAllAsync(Expression> filter, CancellationToken cancellationToken) + where TDocument : IDocument + { + return await GetAllAsync(filter, null, cancellationToken); + } + + /// + public async Task> GetAllAsync(Expression> filter, string partitionKey) + where TDocument : IDocument + { + return await GetAllAsync(filter, partitionKey, CancellationToken.None); + } + + /// + public async Task> GetAllAsync( + Expression> filter, + string partitionKey, + CancellationToken cancellationToken) + where TDocument : IDocument + { + return await MongoDbReader.GetAllAsync(filter, partitionKey, cancellationToken); + } + + /// + public List GetAll(Expression> filter) + where TDocument : IDocument + { + return GetAll(filter, null, CancellationToken.None); + } + + /// + public List GetAll(Expression> filter, CancellationToken cancellationToken) + where TDocument : IDocument + { + return GetAll(filter, null, cancellationToken); + } + + /// + public List GetAll(Expression> filter, string partitionKey) + where TDocument : IDocument + { + return GetAll(filter, partitionKey, CancellationToken.None); + } + + /// + public List GetAll(Expression> filter, string partitionKey, CancellationToken cancellationToken) + where TDocument : IDocument + { + return MongoDbReader.GetAll(filter, partitionKey, cancellationToken); + } + + /// + public async Task CountAsync(Expression> filter) + where TDocument : IDocument + { + return await CountAsync(filter, null, CancellationToken.None); + } + + /// + public async Task CountAsync(Expression> filter, CancellationToken cancellationToken) + where TDocument : IDocument + { + return await CountAsync(filter, null, cancellationToken); + } + + /// + public async Task CountAsync(Expression> filter, string partitionKey) + where TDocument : IDocument + { + return await CountAsync(filter, partitionKey, CancellationToken.None); + } + + /// + public async Task CountAsync(Expression> filter, string partitionKey, CancellationToken cancellationToken) + where TDocument : IDocument + { + return await MongoDbReader.CountAsync(filter, partitionKey, cancellationToken); + } + + /// + public long Count(Expression> filter) + where TDocument : IDocument + { + return Count(filter, null, CancellationToken.None); + } + + /// + public long Count(Expression> filter, CancellationToken cancellationToken) + where TDocument : IDocument + { + return Count(filter, null, cancellationToken); + } + + /// + public long Count(Expression> filter, string partitionKey) + where TDocument : IDocument + { + return Count(filter, partitionKey, CancellationToken.None); + } + + /// + public long Count(Expression> filter, string partitionKey, CancellationToken cancellationToken) + where TDocument : IDocument + { + return MongoDbReader.Count(filter, partitionKey, cancellationToken); + } + + + /// + public async Task GetByMaxAsync(Expression> filter, Expression> maxValueSelector) + where TDocument : IDocument + { + return await GetByMaxAsync(filter, maxValueSelector, null, CancellationToken.None); + } + + /// + public async Task GetByMaxAsync( + Expression> filter, + Expression> maxValueSelector, + CancellationToken cancellationToken) + where TDocument : IDocument + { + return await GetByMaxAsync(filter, maxValueSelector, null, cancellationToken); + } + + /// + public async Task GetByMaxAsync( + Expression> filter, + Expression> maxValueSelector, + string partitionKey) + where TDocument : IDocument + { + return await GetByMaxAsync(filter, maxValueSelector, partitionKey, CancellationToken.None); + } + + /// + public async Task GetByMaxAsync( + Expression> filter, + Expression> maxValueSelector, + string partitionKey, + CancellationToken cancellationToken) + where TDocument : IDocument + { + return await MongoDbReader.GetByMaxAsync(filter, maxValueSelector, partitionKey, cancellationToken); + } + + /// + public TDocument GetByMax(Expression> filter, Expression> maxValueSelector) + where TDocument : IDocument + { + return GetByMax(filter, maxValueSelector, null, CancellationToken.None); + } + + /// + public TDocument GetByMax( + Expression> filter, + Expression> maxValueSelector, + CancellationToken cancellationToken) + where TDocument : IDocument + { + return GetByMax(filter, maxValueSelector, null, cancellationToken); + } + + /// + public TDocument GetByMax( + Expression> filter, + Expression> maxValueSelector, + string partitionKey) + where TDocument : IDocument + { + return GetByMax(filter, maxValueSelector, partitionKey, CancellationToken.None); + } + + /// + public TDocument GetByMax( + Expression> filter, + Expression> maxValueSelector, + string partitionKey, + CancellationToken cancellationToken) where TDocument : IDocument { return MongoDbReader.GetByMax(filter, maxValueSelector, partitionKey); } - /// - /// Gets the document with the maximum value of a specified property in a MongoDB collections that is satisfying the filter. - /// - /// The document type. - /// A LINQ expression filter. - /// A property selector to order by ascending. - /// An optional partitionKey. - public async Task GetByMinAsync(Expression> filter, Expression> minValueSelector, string partitionKey = null) + /// + public async Task GetByMinAsync(Expression> filter, Expression> minValueSelector) where TDocument : IDocument { - return await MongoDbReader.GetByMinAsync(filter, minValueSelector, partitionKey); + return await GetByMinAsync(filter, minValueSelector, null, CancellationToken.None); } - /// - /// Gets the document with the maximum value of a specified property in a MongoDB collections that is satisfying the filter. - /// - /// The document type. - /// A LINQ expression filter. - /// A property selector to order by ascending. - /// An optional partitionKey. - public TDocument GetByMin(Expression> filter, Expression> minValueSelector, string partitionKey = null) + /// + public async Task GetByMinAsync( + Expression> filter, + Expression> minValueSelector, + CancellationToken cancellationToken) where TDocument : IDocument { - return MongoDbReader.GetByMin(filter, minValueSelector, partitionKey); + return await GetByMinAsync(filter, minValueSelector, null, cancellationToken); } - /// - /// Gets the maximum value of a property in a mongodb collections that is satisfying the filter. - /// - /// The document type. - /// The type of the value used to order the query. - /// A LINQ expression filter. - /// A property selector to order by ascending. - /// An optional partitionKey. - public async Task GetMaxValueAsync(Expression> filter, Expression> maxValueSelector, string partitionKey = null) + /// + public async Task GetByMinAsync( + Expression> filter, + Expression> minValueSelector, + string partitionKey) where TDocument : IDocument { - return await MongoDbReader.GetMaxValueAsync(filter, maxValueSelector, partitionKey); + return await GetByMinAsync(filter, minValueSelector, partitionKey, CancellationToken.None); } - /// - /// Gets the maximum value of a property in a mongodb collections that is satisfying the filter. - /// - /// The document type. - /// The type of the value used to order the query. - /// A LINQ expression filter. - /// A property selector to order by ascending. - /// An optional partitionKey. - public TValue GetMaxValue(Expression> filter, Expression> maxValueSelector, string partitionKey = null) + /// + public async Task GetByMinAsync( + Expression> filter, + Expression> minValueSelector, + string partitionKey, + CancellationToken cancellationToken) where TDocument : IDocument { - return MongoDbReader.GetMaxValue(filter, maxValueSelector, partitionKey); + return await MongoDbReader.GetByMinAsync(filter, minValueSelector, partitionKey, cancellationToken); } - /// - /// Gets the minimum value of a property in a mongodb collections that is satisfying the filter. - /// - /// The document type. - /// The type of the value used to order the query. - /// A LINQ expression filter. - /// A property selector to order by ascending. - /// An optional partition key. - public virtual async Task GetMinValueAsync(Expression> filter, Expression> minValueSelector, string partitionKey = null) + /// + public TDocument GetByMin(Expression> filter, Expression> minValueSelector) where TDocument : IDocument { - return await MongoDbReader.GetMinValueAsync(filter, minValueSelector, partitionKey); + return GetByMin(filter, minValueSelector, null, CancellationToken.None); } - /// - /// Gets the minimum value of a property in a mongodb collections that is satisfying the filter. - /// - /// The document type. - /// The type of the value used to order the query. - /// A LINQ expression filter. - /// A property selector to order by ascending. - /// An optional partition key. - public virtual TValue GetMinValue(Expression> filter, Expression> minValueSelector, string partitionKey = null) + /// + public TDocument GetByMin( + Expression> filter, + Expression> minValueSelector, + CancellationToken cancellationToken) where TDocument : IDocument { - return MongoDbReader.GetMinValue(filter, minValueSelector, partitionKey); + return GetByMin(filter, minValueSelector, null, cancellationToken); + } + + /// + public TDocument GetByMin( + Expression> filter, + Expression> minValueSelector, + string partitionKey) + where TDocument : IDocument + { + return GetByMin(filter, minValueSelector, partitionKey, CancellationToken.None); + } + + /// + public TDocument GetByMin( + Expression> filter, + Expression> minValueSelector, + string partitionKey, + CancellationToken cancellationToken) + where TDocument : IDocument + { + return MongoDbReader.GetByMin(filter, minValueSelector, partitionKey, cancellationToken); + } + + /// + public async Task GetMaxValueAsync( + Expression> filter, + Expression> maxValueSelector) + where TDocument : IDocument + { + return await GetMaxValueAsync(filter, maxValueSelector, null, CancellationToken.None); + } + + /// + public async Task GetMaxValueAsync( + Expression> filter, + Expression> maxValueSelector, + CancellationToken cancellationToken) + where TDocument : IDocument + { + return await GetMaxValueAsync(filter, maxValueSelector, null, cancellationToken); + } + + /// + public async Task GetMaxValueAsync( + Expression> filter, + Expression> maxValueSelector, + string partitionKey) + where TDocument : IDocument + { + return await GetMaxValueAsync(filter, maxValueSelector, partitionKey, CancellationToken.None); + } + + /// + public async Task GetMaxValueAsync( + Expression> filter, + Expression> maxValueSelector, + string partitionKey, + CancellationToken cancellationToken) + where TDocument : IDocument + { + return await MongoDbReader.GetMaxValueAsync(filter, maxValueSelector, partitionKey, cancellationToken); + } + + /// + public TValue GetMaxValue(Expression> filter, Expression> maxValueSelector) + where TDocument : IDocument + { + return GetMaxValue(filter, maxValueSelector, null, CancellationToken.None); + } + + /// + public TValue GetMaxValue( + Expression> filter, + Expression> maxValueSelector, + CancellationToken cancellationToken) + where TDocument : IDocument + { + return GetMaxValue(filter, maxValueSelector, null, cancellationToken); + } + + /// + public TValue GetMaxValue( + Expression> filter, + Expression> maxValueSelector, + string partitionKey) + where TDocument : IDocument + { + return GetMaxValue(filter, maxValueSelector, partitionKey, CancellationToken.None); + } + + /// + public TValue GetMaxValue( + Expression> filter, + Expression> maxValueSelector, + string partitionKey, + CancellationToken cancellationToken) + where TDocument : IDocument + { + return MongoDbReader.GetMaxValue(filter, maxValueSelector, partitionKey, cancellationToken); + } + + /// + public virtual async Task GetMinValueAsync( + Expression> filter, + Expression> minValueSelector) + where TDocument : IDocument + { + return await GetMinValueAsync(filter, minValueSelector, null, CancellationToken.None); + } + + /// + public virtual async Task GetMinValueAsync( + Expression> filter, + Expression> minValueSelector, + CancellationToken cancellationToken) + where TDocument : IDocument + { + return await GetMinValueAsync(filter, minValueSelector, null, cancellationToken); + } + + /// + public virtual async Task GetMinValueAsync( + Expression> filter, + Expression> minValueSelector, + string partitionKey) + where TDocument : IDocument + { + return await GetMinValueAsync(filter, minValueSelector, partitionKey, CancellationToken.None); + } + + /// + public virtual async Task GetMinValueAsync( + Expression> filter, + Expression> minValueSelector, + string partitionKey, + CancellationToken cancellationToken) + where TDocument : IDocument + { + return await MongoDbReader.GetMinValueAsync(filter, minValueSelector, partitionKey, cancellationToken); + } + + /// + public virtual TValue GetMinValue(Expression> filter, Expression> minValueSelector) + where TDocument : IDocument + { + return GetMinValue(filter, minValueSelector, null, CancellationToken.None); + } + + /// + public virtual TValue GetMinValue( + Expression> filter, + Expression> minValueSelector, + CancellationToken cancellationToken) + where TDocument : IDocument + { + return GetMinValue(filter, minValueSelector, null, cancellationToken); + } + + /// + public virtual TValue GetMinValue( + Expression> filter, + Expression> minValueSelector, + string partitionKey) + where TDocument : IDocument + { + return GetMinValue(filter, minValueSelector, partitionKey, CancellationToken.None); + } + + /// + public virtual TValue GetMinValue( + Expression> filter, + Expression> minValueSelector, + string partitionKey, + CancellationToken cancellationToken) + where TDocument : IDocument + { + return MongoDbReader.GetMinValue(filter, minValueSelector, partitionKey, cancellationToken); } #endregion #region Maths - /// - /// Sums the values of a selected field for a given filtered collection of documents. - /// - /// The type representing a Document. - /// A LINQ expression filter. - /// The field you want to sum. - /// The partition key of your document, if any. - public virtual async Task SumByAsync(Expression> filter, - Expression> selector, - string partitionKey = null) + /// + public virtual async Task SumByAsync(Expression> filter, Expression> selector) where TDocument : IDocument { - return await MongoDbReader.SumByAsync(filter, selector, partitionKey); + return await SumByAsync(filter, selector, null, CancellationToken.None); } - /// - /// Sums the values of a selected field for a given filtered collection of documents. - /// - /// The type representing a Document. - /// A LINQ expression filter. - /// The field you want to sum. - /// The partition key of your document, if any. - public virtual async Task SumByAsync(Expression> filter, - Expression> selector, - string partitionKey = null) + /// + public virtual async Task SumByAsync( + Expression> filter, + Expression> selector, + CancellationToken cancellationToken) where TDocument : IDocument { - return await MongoDbReader.SumByAsync(filter, selector, partitionKey); + return await SumByAsync(filter, selector, null, cancellationToken); } - /// - /// Sums the values of a selected field for a given filtered collection of documents. - /// - /// The type representing a Document. - /// A LINQ expression filter. - /// The field you want to sum. - /// The partition key of your document, if any. - public virtual int SumBy(Expression> filter, - Expression> selector, - string partitionKey = null) + /// + public virtual async Task SumByAsync( + Expression> filter, + Expression> selector, + string partitionKey) + where TDocument : IDocument + { + return await SumByAsync(filter, selector, partitionKey, CancellationToken.None); + } + + /// + public virtual async Task SumByAsync( + Expression> filter, + Expression> selector, + string partitionKey, + CancellationToken cancellationToken) + where TDocument : IDocument + { + return await MongoDbReader.SumByAsync(filter, selector, partitionKey, cancellationToken); + } + + /// + public virtual async Task SumByAsync(Expression> filter, Expression> selector) + where TDocument : IDocument + { + return await SumByAsync(filter, selector, null, CancellationToken.None); + } + + /// + public virtual async Task SumByAsync( + Expression> filter, + Expression> selector, + CancellationToken cancellationToken) + where TDocument : IDocument + { + return await SumByAsync(filter, selector, null, cancellationToken); + } + + /// + public virtual async Task SumByAsync( + Expression> filter, + Expression> selector, + string partitionKey) + where TDocument : IDocument + { + return await SumByAsync(filter, selector, partitionKey, CancellationToken.None); + } + + /// + public virtual async Task SumByAsync( + Expression> filter, + Expression> selector, + string partitionKey, + CancellationToken cancellationToken) + where TDocument : IDocument + { + return await MongoDbReader.SumByAsync(filter, selector, partitionKey, cancellationToken); + } + + /// + public virtual int SumBy(Expression> filter, Expression> selector, string partitionKey = null) where TDocument : IDocument { return MongoDbReader.SumBy(filter, selector, partitionKey); } - /// - /// Sums the values of a selected field for a given filtered collection of documents. - /// - /// The type representing a Document. - /// A LINQ expression filter. - /// The field you want to sum. - /// The partition key of your document, if any. - public virtual decimal SumBy(Expression> filter, - Expression> selector, - string partitionKey = null) + /// + public virtual decimal SumBy( + Expression> filter, + Expression> selector, + string partitionKey = null) where TDocument : IDocument { return MongoDbReader.SumBy(filter, selector, partitionKey); @@ -390,144 +930,183 @@ namespace MongoDbGenericRepository #region Project - /// - public virtual async Task ProjectOneAsync(Expression> filter, Expression> projection, string partitionKey = null) + /// + public virtual async Task ProjectOneAsync( + Expression> filter, + Expression> projection) where TDocument : IDocument where TProjection : class { - return await MongoDbReader.ProjectOneAsync(filter, projection, partitionKey); + return await ProjectOneAsync(filter, projection, null, CancellationToken.None); } - /// - /// Returns a projected document matching the filter condition. - /// - /// The type representing a Document. - /// The type representing the model you want to project to. - /// A LINQ expression filter. - /// The projection expression. - /// An optional partition key. - public virtual TProjection ProjectOne(Expression> filter, Expression> projection, string partitionKey = null) + /// + public virtual async Task ProjectOneAsync( + Expression> filter, + Expression> projection, + CancellationToken cancellationToken) where TDocument : IDocument where TProjection : class { - return MongoDbReader.ProjectOne(filter, projection, partitionKey); + return await ProjectOneAsync(filter, projection, null, cancellationToken); } - /// - /// Asynchronously returns a list of projected documents matching the filter condition. - /// - /// The type representing a Document. - /// The type representing the model you want to project to. - /// A LINQ expression filter. - /// The projection expression. - /// An optional partition key. - public virtual async Task> ProjectManyAsync(Expression> filter, Expression> projection, string partitionKey = null) + /// + public virtual async Task ProjectOneAsync( + Expression> filter, + Expression> projection, + string partitionKey) where TDocument : IDocument where TProjection : class { - return await MongoDbReader.ProjectManyAsync(filter, projection, partitionKey); + return await ProjectOneAsync(filter, projection, partitionKey, CancellationToken.None); } - /// - /// Asynchronously returns a list of projected documents matching the filter condition. - /// - /// The type representing a Document. - /// The type representing the model you want to project to. - /// A LINQ expression filter. - /// The projection expression. - /// An optional partition key. - public virtual List ProjectMany(Expression> filter, Expression> projection, string partitionKey = null) + /// + public virtual async Task ProjectOneAsync( + Expression> filter, + Expression> projection, + string partitionKey, + CancellationToken cancellationToken) where TDocument : IDocument where TProjection : class { - return MongoDbReader.ProjectMany(filter, projection, partitionKey); + return await MongoDbReader.ProjectOneAsync(filter, projection, partitionKey, cancellationToken); } + /// + public virtual TProjection ProjectOne( + Expression> filter, + Expression> projection) + where TDocument : IDocument + where TProjection : class + { + return ProjectOne(filter, projection, null, CancellationToken.None); + } + + /// + public virtual TProjection ProjectOne( + Expression> filter, + Expression> projection, + CancellationToken cancellationToken) + where TDocument : IDocument + where TProjection : class + { + return ProjectOne(filter, projection, null, cancellationToken); + } + + + /// + public virtual TProjection ProjectOne( + Expression> filter, + Expression> projection, + string partitionKey) + where TDocument : IDocument + where TProjection : class + { + return ProjectOne(filter, projection, partitionKey, CancellationToken.None); + } + + /// + public virtual TProjection ProjectOne( + Expression> filter, + Expression> projection, + string partitionKey, + CancellationToken cancellationToken) + where TDocument : IDocument + where TProjection : class + { + return MongoDbReader.ProjectOne(filter, projection, partitionKey, cancellationToken); + } + + /// + public virtual async Task> ProjectManyAsync( + Expression> filter, + Expression> projection) + where TDocument : IDocument + where TProjection : class + { + return await ProjectManyAsync(filter, projection, null, CancellationToken.None); + } + + /// + public virtual async Task> ProjectManyAsync( + Expression> filter, + Expression> projection, + CancellationToken cancellationToken) + where TDocument : IDocument + where TProjection : class + { + return await ProjectManyAsync(filter, projection, null, cancellationToken); + } + + /// + public virtual async Task> ProjectManyAsync( + Expression> filter, + Expression> projection, + string partitionKey) + where TDocument : IDocument + where TProjection : class + { + return await ProjectManyAsync(filter, projection, partitionKey, CancellationToken.None); + } + + /// + public virtual async Task> ProjectManyAsync( + Expression> filter, + Expression> projection, + string partitionKey, + CancellationToken cancellationToken) + where TDocument : IDocument + where TProjection : class + { + return await MongoDbReader.ProjectManyAsync(filter, projection, partitionKey, cancellationToken); + } + + /// + public virtual List ProjectMany( + Expression> filter, + Expression> projection) + where TDocument : IDocument + where TProjection : class + { + return ProjectMany(filter, projection, null, CancellationToken.None); + } + + /// + public virtual List ProjectMany( + Expression> filter, + Expression> projection, + CancellationToken cancellationToken) + where TDocument : IDocument + where TProjection : class + { + return ProjectMany(filter, projection, null, cancellationToken); + } + + /// + public virtual List ProjectMany( + Expression> filter, + Expression> projection, + string partitionKey) + where TDocument : IDocument + where TProjection : class + { + return ProjectMany(filter, projection, partitionKey, CancellationToken.None); + } + + /// + public virtual List ProjectMany( + Expression> filter, + Expression> projection, + string partitionKey, + CancellationToken cancellationToken) + where TDocument : IDocument + where TProjection : class + { + return MongoDbReader.ProjectMany(filter, projection, partitionKey, cancellationToken); + } #endregion Project - - /// - /// Groups a collection of documents given a grouping criteria, - /// and returns a dictionary of listed document groups with keys having the different values of the grouping criteria. - /// - /// The type representing a Document. - /// The type of the grouping criteria. - /// The type of the projected group. - /// The grouping criteria. - /// The projected group result. - /// The partition key of your document, if any. - public virtual List GroupBy( - Expression> groupingCriteria, - Expression, TProjection>> groupProjection, - string partitionKey = null) - where TDocument : IDocument - where TProjection : class, new() - { - return MongoDbReader.GroupBy(groupingCriteria, groupProjection, partitionKey); - } - - /// - /// Groups filtered a collection of documents given a grouping criteria, - /// and returns a dictionary of listed document groups with keys having the different values of the grouping criteria. - /// - /// The type representing a Document. - /// The type of the grouping criteria. - /// The type of the projected group. - /// A LINQ expression filter. - /// The grouping criteria. - /// The projected group result. - /// The partition key of your document, if any. - public virtual List GroupBy( - Expression> filter, - Expression> groupingCriteria, - Expression, TProjection>> groupProjection, - string partitionKey = null) - where TDocument : IDocument - where TProjection : class, new() - { - return MongoDbReader.GroupBy(filter, groupingCriteria, groupProjection, partitionKey); - } - - /// - /// Asynchronously returns a paginated list of the documents matching the filter condition. - /// - /// The type representing a Document. - /// A LINQ expression filter. - /// The property selector. - /// Order of the sorting. - /// The number of documents you want to skip. Default value is 0. - /// The number of documents you want to take. Default value is 50. - /// An optional partition key. - public virtual async Task> GetSortedPaginatedAsync( - Expression> filter, - Expression> sortSelector, - bool ascending = true, - int skipNumber = 0, - int takeNumber = 50, - string partitionKey = null) - where TDocument : IDocument - { - return await MongoDbReader.GetSortedPaginatedAsync(filter, sortSelector, ascending, skipNumber, takeNumber, partitionKey); - } - - /// - /// Asynchronously returns a paginated list of the documents matching the filter condition. - /// - /// The type representing a Document. - /// A LINQ expression filter. - /// The sort definition. - /// The number of documents you want to skip. Default value is 0. - /// The number of documents you want to take. Default value is 50. - /// An optional partition key. - public virtual async Task> GetSortedPaginatedAsync( - Expression> filter, - SortDefinition sortDefinition, - int skipNumber = 0, - int takeNumber = 50, - string partitionKey = null) - where TDocument : IDocument - { - return await MongoDbReader.GetSortedPaginatedAsync(filter, sortDefinition, skipNumber, takeNumber, partitionKey); - } } } \ No newline at end of file