Compare commits

...

14 Commits

Author SHA1 Message Date
alexandre-spieser 3a42a1c574 Upgraded mongodb driver + new package version released. 2018-01-27 15:58:16 +00:00
alexandre-spieser 67e7318021 updating mongodb driver to version 2.5.0 for MongoDB 3.6 support. 2018-01-27 14:49:13 +00:00
alexandre-spieser 29012d1e52 nuget package update 2018-01-27 14:41:39 +00:00
alexandre-spieser e15c1e4ad2 Refactoring to have a greater separation of concern. 2017-12-06 23:20:53 +00:00
alexandre-spieser 3d104764ae added dependencies 2017-11-19 19:05:22 +00:00
alexandre-spieser 3af68c06db Merge branch 'master' of https://github.com/alexandre-spieser/mongodb-generic-repository 2017-11-17 18:39:38 +00:00
alexandre-spieser a3ae98d077 added comments and updated nuspec 2017-11-17 18:39:34 +00:00
Alexandre SPIESER aff276f9e3 Update README.md 2017-11-16 17:14:40 +00:00
Alexandre SPIESER e91c89f054 Update README.md 2017-11-01 08:27:59 +00:00
alexandre-spieser 657beeac99 The MongoDbRepository now has a constructor that takes an IMongoDatabase. 2017-11-01 08:18:29 +00:00
alexandre-spieser fbb07475a1 Added tests for IdentityUsers 2017-10-29 19:29:43 +00:00
Alexandre SPIESER 30ea910b9c Update README.md 2017-10-22 01:06:26 +01:00
Alexandre SPIESER aae71cddc3 Update README.md 2017-10-02 00:20:50 +01:00
Alexandre SPIESER ad2cd66a7d Update README.md 2017-10-01 22:47:37 +01:00
45 changed files with 5962 additions and 4636 deletions
@@ -5,18 +5,17 @@
</PropertyGroup> </PropertyGroup>
<ItemGroup> <ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="15.5.0-preview-20170810-02" /> <PackageReference Include="Microsoft.AspNetCore.Identity" Version="2.0.1" />
<PackageReference Include="MongoDB.Driver" Version="2.4.4" /> <PackageReference Include="Microsoft.Extensions.Identity.Stores" Version="2.0.1" />
<PackageReference Include="xunit" Version="2.3.0-beta5-build3769" /> <PackageReference Include="Microsoft.NET.Test.Sdk" Version="15.5.0" />
<PackageReference Include="xunit.runner.console" Version="2.3.0-beta5-build3769" /> <PackageReference Include="MongoDB.Driver" Version="2.5.0" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.3.0-beta5-build3769" /> <PackageReference Include="MongoDbGenericRepository" Version="1.3.4" />
<PackageReference Include="xunit" Version="2.3.1" />
<PackageReference Include="xunit.runner.console" Version="2.3.1" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.3.1" />
<DotNetCliToolReference Include="dotnet-xunit" Version="2.3.0-beta4-build3742" /> <DotNetCliToolReference Include="dotnet-xunit" Version="2.3.0-beta4-build3742" />
</ItemGroup> </ItemGroup>
<ItemGroup>
<ProjectReference Include="..\MongoDbGenericRepository\MongoDbGenericRepository.csproj" />
</ItemGroup>
<ItemGroup> <ItemGroup>
<None Update="App.config"> <None Update="App.config">
<CopyToOutputDirectory>Always</CopyToOutputDirectory> <CopyToOutputDirectory>Always</CopyToOutputDirectory>
@@ -1,10 +1,10 @@
using IntegrationTests.Infrastructure; using CoreIntegrationTests.Infrastructure;
using MongoDbGenericRepository.Models; using MongoDbGenericRepository.Models;
using Xunit; using Xunit;
using System.Collections.Generic; using System.Collections.Generic;
using System.Threading.Tasks; using System.Threading.Tasks;
namespace IntegrationTests namespace CoreIntegrationTests
{ {
public class CreateTestsPartitionedDocument : PartitionedDocument public class CreateTestsPartitionedDocument : PartitionedDocument
{ {
+2 -2
View File
@@ -1,10 +1,10 @@
using IntegrationTests.Infrastructure; using CoreIntegrationTests.Infrastructure;
using MongoDbGenericRepository.Models; using MongoDbGenericRepository.Models;
using Xunit; using Xunit;
using System.Collections.Generic; using System.Collections.Generic;
using System.Threading.Tasks; using System.Threading.Tasks;
namespace IntegrationTests namespace CoreIntegrationTests
{ {
public class CreateTestsDocument : Document public class CreateTestsDocument : Document
{ {
@@ -1,9 +1,9 @@
using IntegrationTests.Infrastructure; using CoreIntegrationTests.Infrastructure;
using MongoDbGenericRepository.Models; using MongoDbGenericRepository.Models;
using Xunit; using Xunit;
using System.Threading.Tasks; using System.Threading.Tasks;
namespace IntegrationTests namespace CoreIntegrationTests
{ {
public class DeleteTestsPartitionedDocument : PartitionedDocument public class DeleteTestsPartitionedDocument : PartitionedDocument
{ {
+2 -2
View File
@@ -1,9 +1,9 @@
using IntegrationTests.Infrastructure; using CoreIntegrationTests.Infrastructure;
using MongoDbGenericRepository.Models; using MongoDbGenericRepository.Models;
using Xunit; using Xunit;
using System.Threading.Tasks; using System.Threading.Tasks;
namespace IntegrationTests namespace CoreIntegrationTests
{ {
public class DeleteTestsDocument : Document public class DeleteTestsDocument : Document
{ {
+77
View File
@@ -0,0 +1,77 @@
using CoreIntegrationTests.Infrastructure;
using MongoDbGenericRepository.Models;
using System;
using System.Collections.Generic;
using Xunit;
using Microsoft.AspNetCore.Identity;
using System.Threading.Tasks;
namespace CoreCoreIntegrationTests
{
public class MongoIdentityUser<TKey> : IdentityUser<TKey>, IDocument<TKey>
where TKey : IEquatable<TKey>
{
public int Version { get; set; }
}
public class IdentityUserTest : MongoIdentityUser<Guid>, IDocument<Guid>
{
public IdentityUserTest()
{
Id = Guid.NewGuid();
Version = 2;
}
public string SomeContent { get; set; }
}
public class IdentityUserTests : BaseMongoDbRepositoryTests<IdentityUserTest>
{
[Fact]
public void AddOne()
{
// Arrange
var document = new IdentityUserTest();
// Act
SUT.AddOne<IdentityUserTest, Guid>(document);
// Assert
long count = SUT.Count<IdentityUserTest, Guid>(e => e.Id == document.Id);
Assert.Equal(1, count);
}
[Fact]
public async Task AddOneAsync()
{
// Arrange
var document = new IdentityUserTest();
// Act
await SUT.AddOneAsync<IdentityUserTest, Guid>(document);
// Assert
long count = SUT.Count<IdentityUserTest, Guid>(e => e.Id == document.Id);
Assert.Equal(1, count);
}
[Fact]
public void AddMany()
{
// Arrange
var documents = new List<IdentityUserTest> { new IdentityUserTest(), new IdentityUserTest() };
// Act
SUT.AddMany<IdentityUserTest, Guid>(documents);
// Assert
long count = SUT.Count<IdentityUserTest, Guid>(e => e.Id == documents[0].Id || e.Id == documents[1].Id);
Assert.Equal(2, count);
}
[Fact]
public async Task AddManyAsync()
{
// Arrange
var documents = new List<IdentityUserTest> { new IdentityUserTest(), new IdentityUserTest() };
// Act
await SUT.AddManyAsync<IdentityUserTest, Guid>(documents);
// Assert
long count = SUT.Count<IdentityUserTest, Guid>(e => e.Id == documents[0].Id || e.Id == documents[1].Id);
Assert.Equal(2, count);
}
}
}
@@ -2,10 +2,10 @@
using System.Collections.Generic; using System.Collections.Generic;
using System; using System;
namespace IntegrationTests.Infrastructure namespace CoreIntegrationTests.Infrastructure
{ {
public class BaseMongoDbRepositoryTests<T> : IDisposable where T : Document, new() public class BaseMongoDbRepositoryTests<T> : IDisposable where T : new()
{ {
public T CreateTestDocument() public T CreateTestDocument()
{ {
@@ -44,6 +44,7 @@ namespace IntegrationTests.Infrastructure
public void Init() public void Init()
{ {
MongoDbConfig.EnsureConfigured();
SUT = TestRepository.Instance; SUT = TestRepository.Instance;
} }
@@ -1,6 +1,6 @@
using MongoDbGenericRepository; using MongoDbGenericRepository;
namespace IntegrationTests namespace CoreIntegrationTests
{ {
public interface ITestRepository : IBaseMongoRepository public interface ITestRepository : IBaseMongoRepository
{ {
@@ -0,0 +1,43 @@
using CoreCoreIntegrationTests;
using MongoDB.Bson.Serialization;
using MongoDB.Bson.Serialization.Conventions;
using System.Threading;
namespace CoreIntegrationTests.Infrastructure
{
internal static class MongoDbConfig
{
private static bool _initialized = false;
private static object _initializationLock = new object();
private static object _initializationTarget;
public static void EnsureConfigured()
{
EnsureConfiguredImpl();
}
private static void EnsureConfiguredImpl()
{
LazyInitializer.EnsureInitialized(ref _initializationTarget, ref _initialized, ref _initializationLock, () =>
{
Configure();
return null;
});
}
private static void Configure()
{
RegisterConventions();
}
private static void RegisterConventions()
{
var pack = new ConventionPack
{
new IgnoreIfNullConvention(false),
new CamelCaseElementNameConvention(),
};
}
}
}
@@ -1,6 +1,6 @@
using MongoDbGenericRepository; using MongoDbGenericRepository;
namespace IntegrationTests.Infrastructure namespace CoreIntegrationTests.Infrastructure
{ {
/// <summary> /// <summary>
/// A singleton implementation of the TestRepository /// A singleton implementation of the TestRepository
@@ -1,11 +1,11 @@
using IntegrationTests.Infrastructure; using CoreIntegrationTests.Infrastructure;
using MongoDbGenericRepository.Models; using MongoDbGenericRepository.Models;
using Xunit; using Xunit;
using System; using System;
using System.Linq; using System.Linq;
using System.Threading.Tasks; using System.Threading.Tasks;
namespace IntegrationTests namespace CoreIntegrationTests
{ {
public class ProjectTestsPartitionedDocument : PartitionedDocument public class ProjectTestsPartitionedDocument : PartitionedDocument
{ {
+2 -2
View File
@@ -1,11 +1,11 @@
using IntegrationTests.Infrastructure; using CoreIntegrationTests.Infrastructure;
using MongoDbGenericRepository.Models; using MongoDbGenericRepository.Models;
using Xunit; using Xunit;
using System; using System;
using System.Linq; using System.Linq;
using System.Threading.Tasks; using System.Threading.Tasks;
namespace IntegrationTests namespace CoreIntegrationTests
{ {
public class Nested public class Nested
{ {
+2 -2
View File
@@ -1,10 +1,10 @@
using IntegrationTests.Infrastructure; using CoreIntegrationTests.Infrastructure;
using MongoDbGenericRepository.Models; using MongoDbGenericRepository.Models;
using Xunit; using Xunit;
using System; using System;
using System.Threading.Tasks; using System.Threading.Tasks;
namespace IntegrationTests namespace CoreIntegrationTests
{ {
public class ReadTestsPartitionedDocument : PartitionedDocument public class ReadTestsPartitionedDocument : PartitionedDocument
{ {
+2 -2
View File
@@ -1,10 +1,10 @@
using IntegrationTests.Infrastructure; using CoreIntegrationTests.Infrastructure;
using MongoDbGenericRepository.Models; using MongoDbGenericRepository.Models;
using Xunit; using Xunit;
using System; using System;
using System.Threading.Tasks; using System.Threading.Tasks;
namespace IntegrationTests namespace CoreIntegrationTests
{ {
public class ReadTestsDocument : Document public class ReadTestsDocument : Document
{ {
@@ -1,9 +1,9 @@
using IntegrationTests.Infrastructure; using CoreIntegrationTests.Infrastructure;
using MongoDbGenericRepository.Models; using MongoDbGenericRepository.Models;
using Xunit; using Xunit;
using System.Threading.Tasks; using System.Threading.Tasks;
namespace IntegrationTests namespace CoreIntegrationTests
{ {
public class UpdateTestsPartitionedDocument : PartitionedDocument public class UpdateTestsPartitionedDocument : PartitionedDocument
{ {
+2 -2
View File
@@ -1,9 +1,9 @@
using IntegrationTests.Infrastructure; using CoreIntegrationTests.Infrastructure;
using MongoDbGenericRepository.Models; using MongoDbGenericRepository.Models;
using Xunit; using Xunit;
using System.Threading.Tasks; using System.Threading.Tasks;
namespace IntegrationTests namespace CoreIntegrationTests
{ {
public class UpdateTestsDocument : Document public class UpdateTestsDocument : Document
{ {
+5 -1
View File
@@ -11,7 +11,11 @@
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1"> <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly> <dependentAssembly>
<assemblyIdentity name="System.Runtime.InteropServices.RuntimeInformation" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" /> <assemblyIdentity name="System.Runtime.InteropServices.RuntimeInformation" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-4.0.1.0" newVersion="4.0.1.0" /> <bindingRedirect oldVersion="0.0.0.0-4.0.0.0" newVersion="4.0.0.0" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="System.Buffers" publicKeyToken="cc7b13ffcd2ddd51" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-4.0.2.0" newVersion="4.0.2.0" />
</dependentAssembly> </dependentAssembly>
</assemblyBinding> </assemblyBinding>
</runtime> </runtime>
+19 -16
View File
@@ -30,24 +30,33 @@
<WarningLevel>4</WarningLevel> <WarningLevel>4</WarningLevel>
</PropertyGroup> </PropertyGroup>
<ItemGroup> <ItemGroup>
<Reference Include="MongoDB.Bson, Version=2.4.4.0, Culture=neutral, processorArchitecture=MSIL"> <Reference Include="DnsClient, Version=1.0.7.0, Culture=neutral, PublicKeyToken=4574bb5573c51424, processorArchitecture=MSIL">
<HintPath>..\packages\MongoDB.Bson.2.4.4\lib\net45\MongoDB.Bson.dll</HintPath> <HintPath>..\packages\MongoDbGenericRepository.1.3.4\lib\net45\DnsClient.dll</HintPath>
</Reference> </Reference>
<Reference Include="MongoDB.Driver, Version=2.4.4.0, Culture=neutral, processorArchitecture=MSIL"> <Reference Include="MongoDB.Bson, Version=2.5.0.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\packages\MongoDB.Driver.2.4.4\lib\net45\MongoDB.Driver.dll</HintPath> <HintPath>..\packages\MongoDbGenericRepository.1.3.4\lib\net45\MongoDB.Bson.dll</HintPath>
</Reference> </Reference>
<Reference Include="MongoDB.Driver.Core, Version=2.4.4.0, Culture=neutral, processorArchitecture=MSIL"> <Reference Include="MongoDB.Driver, Version=2.5.0.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\packages\MongoDB.Driver.Core.2.4.4\lib\net45\MongoDB.Driver.Core.dll</HintPath> <HintPath>..\packages\MongoDbGenericRepository.1.3.4\lib\net45\MongoDB.Driver.dll</HintPath>
</Reference> </Reference>
<Reference Include="nunit.framework, Version=3.7.1.0, Culture=neutral, PublicKeyToken=2638cd05610744eb, processorArchitecture=MSIL"> <Reference Include="MongoDB.Driver.Core, Version=2.5.0.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\packages\NUnit.3.7.1\lib\net45\nunit.framework.dll</HintPath> <HintPath>..\packages\MongoDbGenericRepository.1.3.4\lib\net45\MongoDB.Driver.Core.dll</HintPath>
</Reference>
<Reference Include="MongoDbGenericRepository, Version=1.0.0.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\packages\MongoDbGenericRepository.1.3.4\lib\net45\MongoDbGenericRepository.dll</HintPath>
</Reference>
<Reference Include="nunit.framework, Version=3.9.0.0, Culture=neutral, PublicKeyToken=2638cd05610744eb, processorArchitecture=MSIL">
<HintPath>..\packages\NUnit.3.9.0\lib\net45\nunit.framework.dll</HintPath>
</Reference> </Reference>
<Reference Include="System" /> <Reference Include="System" />
<Reference Include="System.Buffers, Version=4.0.1.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51, processorArchitecture=MSIL">
<HintPath>..\packages\MongoDbGenericRepository.1.3.4\lib\net45\System.Buffers.dll</HintPath>
</Reference>
<Reference Include="System.Configuration" /> <Reference Include="System.Configuration" />
<Reference Include="System.Core" /> <Reference Include="System.Core" />
<Reference Include="Microsoft.CSharp" /> <Reference Include="Microsoft.CSharp" />
<Reference Include="System.Runtime.InteropServices.RuntimeInformation, Version=4.0.1.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL"> <Reference Include="System.Runtime.InteropServices.RuntimeInformation, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
<HintPath>..\packages\System.Runtime.InteropServices.RuntimeInformation.4.3.0\lib\net45\System.Runtime.InteropServices.RuntimeInformation.dll</HintPath> <HintPath>..\packages\MongoDbGenericRepository.1.3.4\lib\net45\System.Runtime.InteropServices.RuntimeInformation.dll</HintPath>
<Private>True</Private> <Private>True</Private>
</Reference> </Reference>
</ItemGroup> </ItemGroup>
@@ -88,11 +97,5 @@
<ItemGroup> <ItemGroup>
<Service Include="{82A7F48D-3B50-4B1E-B82E-3ADA8210C358}" /> <Service Include="{82A7F48D-3B50-4B1E-B82E-3ADA8210C358}" />
</ItemGroup> </ItemGroup>
<ItemGroup>
<ProjectReference Include="..\MongoDbGenericRepository\MongoDbGenericRepository.csproj">
<Project>{efc776c4-2af3-440c-be80-3fbe335817a5}</Project>
<Name>MongoDbGenericRepository</Name>
</ProjectReference>
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" /> <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
</Project> </Project>
+8 -6
View File
@@ -1,10 +1,12 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<packages> <packages>
<package id="MongoDB.Bson" version="2.4.4" targetFramework="net461" /> <package id="DnsClient" version="1.0.7" targetFramework="net461" />
<package id="MongoDB.Driver" version="2.4.4" targetFramework="net461" /> <package id="MongoDB.Bson" version="2.5.0" targetFramework="net461" />
<package id="MongoDB.Driver.Core" version="2.4.4" targetFramework="net461" /> <package id="MongoDB.Driver" version="2.5.0" targetFramework="net461" />
<package id="NUnit" version="3.7.1" targetFramework="net461" /> <package id="MongoDB.Driver.Core" version="2.5.0" targetFramework="net461" />
<package id="MongoDbGenericRepository" version="1.3.4" targetFramework="net461" />
<package id="NUnit" version="3.9.0" targetFramework="net461" />
<package id="NUnit.ConsoleRunner" version="3.7.0" targetFramework="net461" /> <package id="NUnit.ConsoleRunner" version="3.7.0" targetFramework="net461" />
<package id="System.Runtime.InteropServices" version="4.3.0" targetFramework="net461" /> <package id="System.Buffers" version="4.3.0" targetFramework="net461" />
<package id="System.Runtime.InteropServices.RuntimeInformation" version="4.3.0" targetFramework="net461" /> <package id="System.Runtime.InteropServices.RuntimeInformation" version="4.0.0" targetFramework="net461" />
</packages> </packages>
File diff suppressed because it is too large Load Diff
@@ -0,0 +1,646 @@
using MongoDB.Driver;
using System;
using System.Collections.Generic;
using System.Threading.Tasks;
using System.Linq.Expressions;
using MongoDbGenericRepository.Models;
using System.Linq;
namespace MongoDbGenericRepository
{
/// <summary>
/// The IBaseMongoRepository exposes the CRUD functionality of the BaseMongoRepository.
/// </summary>
public interface IBaseMongoRepository : IReadOnlyMongoRepository
{
#region Create
/// <summary>
/// Asynchronously adds a document to the collection.
/// </summary>
/// <typeparam name="TDocument">The type representing a Document.</typeparam>
/// <param name="document">The document you want to add.</param>
Task AddOneAsync<TDocument>(TDocument document) where TDocument : IDocument;
/// <summary>
/// Adds a document to the collection.
/// Populates the Id and AddedAtUtc fields if necessary.
/// </summary>
/// <typeparam name="TDocument">The type representing a Document.</typeparam>
/// <param name="document">The document you want to add.</param>
void AddOne<TDocument>(TDocument document) where TDocument : IDocument;
/// <summary>
/// Asynchronously adds a list of documents to the collection.
/// Populates the Id and AddedAtUtc fields if necessary.
/// </summary>
/// <typeparam name="TDocument">The type representing a Document.</typeparam>
/// <param name="documents">The document you want to add.</param>
Task AddManyAsync<TDocument>(IEnumerable<TDocument> documents) where TDocument : IDocument;
/// <summary>
/// Adds a list of documents to the collection.
/// Populates the Id and AddedAtUtc fields if necessary.
/// </summary>
/// <typeparam name="TDocument">The type representing a Document.</typeparam>
/// <param name="documents">The document you want to add.</param>
void AddMany<TDocument>(IEnumerable<TDocument> documents) where TDocument : IDocument;
#endregion
#region Create TKey
/// <summary>
/// Asynchronously adds a document to the collection.
/// Populates the Id and AddedAtUtc fields if necessary.
/// </summary>
/// <typeparam name="TDocument">The type representing a Document.</typeparam>
/// <typeparam name="TKey">The type of the primary key for a Document.</typeparam>
/// <param name="document">The document you want to add.</param>
Task AddOneAsync<TDocument, TKey>(TDocument document)
where TDocument : IDocument<TKey>
where TKey : IEquatable<TKey>;
/// <summary>
/// Adds a document to the collection.
/// Populates the Id and AddedAtUtc fields if necessary.
/// </summary>
/// <typeparam name="TDocument">The type representing a Document.</typeparam>
/// <typeparam name="TKey">The type of the primary key for a Document.</typeparam>
/// <param name="document">The document you want to add.</param>
void AddOne<TDocument, TKey>(TDocument document)
where TDocument : IDocument<TKey>
where TKey : IEquatable<TKey>;
/// <summary>
/// Asynchronously adds a list of documents to the collection.
/// Populates the Id and AddedAtUtc fields if necessary.
/// </summary>
/// <typeparam name="TDocument">The type representing a Document.</typeparam>
/// <typeparam name="TKey">The type of the primary key for a Document.</typeparam>
/// <param name="documents">The documents you want to add.</param>
Task AddManyAsync<TDocument, TKey>(IEnumerable<TDocument> documents)
where TDocument : IDocument<TKey>
where TKey : IEquatable<TKey>;
/// <summary>
/// Adds a list of documents to the collection.
/// Populates the Id and AddedAtUtc fields if necessary.
/// </summary>
/// <typeparam name="TDocument">The type representing a Document.</typeparam>
/// <typeparam name="TKey">The type of the primary key for a Document.</typeparam>
/// <param name="documents">The documents you want to add.</param>
void AddMany<TDocument, TKey>(IEnumerable<TDocument> documents)
where TDocument : IDocument<TKey>
where TKey : IEquatable<TKey>;
#endregion
#region Update
/// <summary>
/// Asynchronously Updates a document.
/// </summary>
/// <typeparam name="TDocument">The type representing a Document.</typeparam>
/// <param name="modifiedDocument">The document with the modifications you want to persist.</param>
Task<bool> UpdateOneAsync<TDocument>(TDocument modifiedDocument) where TDocument : IDocument;
/// <summary>
/// Updates a document.
/// </summary>
/// <typeparam name="TDocument">The type representing a Document.</typeparam>
/// <param name="modifiedDocument">The document with the modifications you want to persist.</param>
bool UpdateOne<TDocument>(TDocument modifiedDocument) where TDocument : IDocument;
/// <summary>
/// Updates the property field with the given value update a property field in entities.
/// </summary>
/// <typeparam name="TDocument">The type representing a Document.</typeparam>
/// <typeparam name="TField">The type of the field.</typeparam>
/// <param name="filter">The document filter.</param>
/// <param name="field">The field selector.</param>
/// <param name="value">The new value of the property field.</param>
/// <param name="partitionKey">The value of the partition key.</param>
bool UpdateOne<TDocument, TField>(FilterDefinition<TDocument> filter, Expression<Func<TDocument, TField>> field, TField value, string partitionKey = null)
where TDocument : IDocument;
/// <summary>
/// Updates the property field with the given value update a property field in entities.
/// </summary>
/// <typeparam name="TDocument">The type representing a Document.</typeparam>
/// <typeparam name="TField">The type of the field.</typeparam>
/// <param name="filter">The document filter.</param>
/// <param name="field">The field selector.</param>
/// <param name="value">The new value of the property field.</param>
/// <param name="partitionKey">The value of the partition key.</param>
Task<bool> UpdateOneAsync<TDocument, TField>(FilterDefinition<TDocument> filter, Expression<Func<TDocument, TField>> field, TField value, string partitionKey = null)
where TDocument : IDocument;
/// <summary>
/// Updates the property field with the given value update a property field in entities.
/// </summary>
/// <typeparam name="TDocument">The type representing a Document.</typeparam>
/// <typeparam name="TField">The type of the field.</typeparam>
/// <param name="documentToModify">The document you want to modify.</param>
/// <param name="field">The field selector.</param>
/// <param name="value">The new value of the property field.</param>
bool UpdateOne<TDocument, TField>(TDocument documentToModify, Expression<Func<TDocument, TField>> field, TField value)
where TDocument : IDocument;
/// <summary>
/// Updates the property field with the given value update a property field in entities.
/// </summary>
/// <typeparam name="TDocument">The type representing a Document.</typeparam>
/// <typeparam name="TField">The type of the field.</typeparam>
/// <param name="documentToModify">The document you want to modify.</param>
/// <param name="field">The field selector.</param>
/// <param name="value">The new value of the property field.</param>
Task<bool> UpdateOneAsync<TDocument, TField>(TDocument documentToModify, Expression<Func<TDocument, TField>> field, TField value)
where TDocument : IDocument;
/// <summary>
/// Takes a document you want to modify and applies the update you have defined in MongoDb.
/// </summary>
/// <typeparam name="TDocument">The type representing a Document.</typeparam>
/// <param name="documentToModify">The document you want to modify.</param>
/// <param name="update">The update definition for the document.</param>
Task<bool> UpdateOneAsync<TDocument>(TDocument documentToModify, UpdateDefinition<TDocument> update)
where TDocument : IDocument;
/// <summary>
/// Takes a document you want to modify and applies the update you have defined in MongoDb.
/// </summary>
/// <typeparam name="TDocument">The type representing a Document.</typeparam>
/// <param name="documentToModify">The document you want to modify.</param>
/// <param name="update">The update definition for the document.</param>
bool UpdateOne<TDocument>(TDocument documentToModify, UpdateDefinition<TDocument> update)
where TDocument : IDocument;
#endregion
#region Update TKey
/// <summary>
/// Asynchronously Updates a document.
/// </summary>
/// <typeparam name="TDocument">The type representing a Document.</typeparam>
/// <typeparam name="TKey">The type of the primary key for a Document.</typeparam>
/// <param name="modifiedDocument">The document with the modifications you want to persist.</param>
Task<bool> UpdateOneAsync<TDocument, TKey>(TDocument modifiedDocument)
where TDocument : IDocument<TKey>
where TKey : IEquatable<TKey>;
/// <summary>
/// Updates a document.
/// </summary>
/// <typeparam name="TDocument">The type representing a Document.</typeparam>
/// <typeparam name="TKey">The type of the primary key for a Document.</typeparam>
/// <param name="modifiedDocument">The document with the modifications you want to persist.</param>
bool UpdateOne<TDocument, TKey>(TDocument modifiedDocument)
where TDocument : IDocument<TKey>
where TKey : IEquatable<TKey>;
/// <summary>
/// Takes a document you want to modify and applies the update you have defined in MongoDb.
/// </summary>
/// <typeparam name="TDocument">The type representing a Document.</typeparam>
/// <typeparam name="TKey">The type of the primary key for a Document.</typeparam>
/// <param name="documentToModify">The document you want to modify.</param>
/// <param name="update">The update definition for the document.</param>
Task<bool> UpdateOneAsync<TDocument, TKey>(TDocument documentToModify, UpdateDefinition<TDocument> update)
where TDocument : IDocument<TKey>
where TKey : IEquatable<TKey>;
/// <summary>
/// Takes a document you want to modify and applies the update you have defined in MongoDb.
/// </summary>
/// <typeparam name="TDocument">The type representing a Document.</typeparam>
/// <typeparam name="TKey">The type of the primary key for a Document.</typeparam>
/// <param name="documentToModify">The document you want to modify.</param>
/// <param name="update">The update definition for the document.</param>
bool UpdateOne<TDocument, TKey>(TDocument documentToModify, UpdateDefinition<TDocument> update)
where TDocument : IDocument<TKey>
where TKey : IEquatable<TKey>;
/// <summary>
/// Updates the property field with the given value update a property field in entities.
/// </summary>
/// <typeparam name="TDocument">The type representing a Document.</typeparam>
/// <typeparam name="TKey">The type of the primary key for a Document.</typeparam>
/// <typeparam name="TField">The type of the field.</typeparam>
/// <param name="documentToModify">The document you want to modify.</param>
/// <param name="field">The field selector.</param>
/// <param name="value">The new value of the property field.</param>
Task<bool> UpdateOneAsync<TDocument, TKey, TField>(TDocument documentToModify, Expression<Func<TDocument, TField>> field, TField value)
where TDocument : IDocument<TKey>
where TKey : IEquatable<TKey>;
/// <summary>
/// Updates the property field with the given value update a property field in entities.
/// </summary>
/// <typeparam name="TDocument">The type representing a Document.</typeparam>
/// <typeparam name="TKey">The type of the primary key for a Document.</typeparam>
/// <typeparam name="TField">The type of the field.</typeparam>
/// <param name="documentToModify">The document you want to modify.</param>
/// <param name="field">The field selector.</param>
/// <param name="value">The new value of the property field.</param>
bool UpdateOne<TDocument, TKey, TField>(TDocument documentToModify, Expression<Func<TDocument, TField>> field, TField value)
where TDocument : IDocument<TKey>
where TKey : IEquatable<TKey>;
/// <summary>
/// Updates the property field with the given value update a property field in entities.
/// </summary>
/// <typeparam name="TDocument">The type representing a Document.</typeparam>
/// <typeparam name="TKey">The type of the primary key for a Document.</typeparam>
/// <typeparam name="TField">The type of the field.</typeparam>
/// <param name="filter">The document filter.</param>
/// <param name="field">The field selector.</param>
/// <param name="value">The new value of the property field.</param>
/// <param name="partitionKey">The value of the partition key.</param>
Task<bool> UpdateOneAsync<TDocument, TKey, TField>(FilterDefinition<TDocument> filter, Expression<Func<TDocument, TField>> field, TField value, string partitionKey = null)
where TDocument : IDocument<TKey>
where TKey : IEquatable<TKey>;
/// <summary>
/// Updates the property field with the given value update a property field in entities.
/// </summary>
/// <typeparam name="TDocument">The type representing a Document.</typeparam>
/// <typeparam name="TKey">The type of the primary key for a Document.</typeparam>
/// <typeparam name="TField">The type of the field.</typeparam>
/// <param name="filter">The document filter.</param>
/// <param name="field">The field selector.</param>
/// <param name="value">The new value of the property field.</param>
/// <param name="partitionKey">The value of the partition key.</param>
bool UpdateOne<TDocument, TKey, TField>(FilterDefinition<TDocument> filter, Expression<Func<TDocument, TField>> field, TField value, string partitionKey = null)
where TDocument : IDocument<TKey>
where TKey : IEquatable<TKey>;
#endregion
#region Delete
/// <summary>
/// Asynchronously deletes a document.
/// </summary>
/// <typeparam name="TDocument">The type representing a Document.</typeparam>
/// <param name="document">The document you want to delete.</param>
/// <returns>The number of documents deleted.</returns>
Task<long> DeleteOneAsync<TDocument>(TDocument document) where TDocument : IDocument;
/// <summary>
/// Asynchronously deletes a document matching the condition of the LINQ expression filter.
/// </summary>
/// <typeparam name="TDocument">The type representing a Document.</typeparam>
/// <param name="filter">A LINQ expression filter.</param>
/// <param name="partitionKey">An optional partition key.</param>
/// <returns>The number of documents deleted.</returns>
Task<long> DeleteOneAsync<TDocument>(Expression<Func<TDocument, bool>> filter, string partitionKey = null) where TDocument : IDocument;
/// <summary>
/// Deletes a document.
/// </summary>
/// <typeparam name="TDocument">The type representing a Document.</typeparam>
/// <param name="document">The document you want to delete.</param>
/// <returns>The number of documents deleted.</returns>
long DeleteOne<TDocument>(TDocument document) where TDocument : IDocument;
/// <summary>
/// Deletes a document matching the condition of the LINQ expression filter.
/// </summary>
/// <typeparam name="TDocument">The type representing a Document.</typeparam>
/// <param name="filter">A LINQ expression filter.</param>
/// <param name="partitionKey">An optional partition key.</param>
/// <returns>The number of documents deleted.</returns>
long DeleteOne<TDocument>(Expression<Func<TDocument, bool>> filter, string partitionKey = null) where TDocument : IDocument;
/// <summary>
/// Asynchronously deletes the documents matching the condition of the LINQ expression filter.
/// </summary>
/// <typeparam name="TDocument">The type representing a Document.</typeparam>
/// <param name="filter">A LINQ expression filter.</param>
/// <param name="partitionKey">An optional partition key.</param>
/// <returns>The number of documents deleted.</returns>
Task<long> DeleteManyAsync<TDocument>(Expression<Func<TDocument, bool>> filter, string partitionKey = null) where TDocument : IDocument;
/// <summary>
/// Asynchronously deletes a list of documents.
/// </summary>
/// <typeparam name="TDocument">The type representing a Document.</typeparam>
/// <param name="documents">The list of documents to delete.</param>
/// <returns>The number of documents deleted.</returns>
Task<long> DeleteManyAsync<TDocument>(IEnumerable<TDocument> documents) where TDocument : IDocument;
/// <summary>
/// Deletes a list of documents.
/// </summary>
/// <typeparam name="TDocument">The type representing a Document.</typeparam>
/// <param name="documents">The list of documents to delete.</param>
/// <returns>The number of documents deleted.</returns>
long DeleteMany<TDocument>(IEnumerable<TDocument> documents) where TDocument : IDocument;
/// <summary>
/// Deletes the documents matching the condition of the LINQ expression filter.
/// </summary>
/// <typeparam name="TDocument">The type representing a Document.</typeparam>
/// <param name="filter">A LINQ expression filter.</param>
/// <param name="partitionKey">An optional partition key.</param>
/// <returns>The number of documents deleted.</returns>
long DeleteMany<TDocument>(Expression<Func<TDocument, bool>> filter, string partitionKey = null) where TDocument : IDocument;
#endregion
#region Delete TKey
/// <summary>
/// Deletes a document.
/// </summary>
/// <typeparam name="TDocument">The type representing a Document.</typeparam>
/// <typeparam name="TKey">The type of the primary key for a Document.</typeparam>
/// <param name="document">The document you want to delete.</param>
/// <returns>The number of documents deleted.</returns>
long DeleteOne<TDocument, TKey>(TDocument document)
where TDocument : IDocument<TKey>
where TKey : IEquatable<TKey>;
/// <summary>
/// Asynchronously deletes a document matching the condition of the LINQ expression filter.
/// </summary>
/// <typeparam name="TDocument">The type representing a Document.</typeparam>
/// <typeparam name="TKey">The type of the primary key for a Document.</typeparam>
/// <param name="document">The document you want to delete.</param>
/// <returns>The number of documents deleted.</returns>
Task<long> DeleteOneAsync<TDocument, TKey>(TDocument document)
where TDocument : IDocument<TKey>
where TKey : IEquatable<TKey>;
/// <summary>
/// Deletes a document matching the condition of the LINQ expression filter.
/// </summary>
/// <typeparam name="TDocument">The type representing a Document.</typeparam>
/// <typeparam name="TKey">The type of the primary key for a Document.</typeparam>
/// <param name="filter">A LINQ expression filter.</param>
/// <param name="partitionKey">An optional partition key.</param>
/// <returns>The number of documents deleted.</returns>
long DeleteOne<TDocument, TKey>(Expression<Func<TDocument, bool>> filter, string partitionKey = null)
where TDocument : IDocument<TKey>
where TKey : IEquatable<TKey>;
/// <summary>
/// Asynchronously deletes a document matching the condition of the LINQ expression filter.
/// </summary>
/// <typeparam name="TDocument">The type representing a Document.</typeparam>
/// <typeparam name="TKey">The type of the primary key for a Document.</typeparam>
/// <param name="filter">A LINQ expression filter.</param>
/// <param name="partitionKey">An optional partition key.</param>
/// <returns>The number of documents deleted.</returns>
Task<long> DeleteOneAsync<TDocument, TKey>(Expression<Func<TDocument, bool>> filter, string partitionKey = null)
where TDocument : IDocument<TKey>
where TKey : IEquatable<TKey>;
/// <summary>
/// Asynchronously deletes the documents matching the condition of the LINQ expression filter.
/// </summary>
/// <typeparam name="TDocument">The type representing a Document.</typeparam>
/// <typeparam name="TKey">The type of the primary key for a Document.</typeparam>
/// <param name="filter">A LINQ expression filter.</param>
/// <param name="partitionKey">An optional partition key.</param>
/// <returns>The number of documents deleted.</returns>
Task<long> DeleteManyAsync<TDocument, TKey>(Expression<Func<TDocument, bool>> filter, string partitionKey = null)
where TDocument : IDocument<TKey>
where TKey : IEquatable<TKey>;
/// <summary>
/// Asynchronously deletes a list of documents.
/// </summary>
/// <typeparam name="TDocument">The type representing a Document.</typeparam>
/// <typeparam name="TKey">The type of the primary key for a Document.</typeparam>
/// <param name="documents">The list of documents to delete.</param>
/// <returns>The number of documents deleted.</returns>
Task<long> DeleteManyAsync<TDocument, TKey>(IEnumerable<TDocument> documents)
where TDocument : IDocument<TKey>
where TKey : IEquatable<TKey>;
/// <summary>
/// Deletes a list of documents.
/// </summary>
/// <typeparam name="TDocument">The type representing a Document.</typeparam>
/// <typeparam name="TKey">The type of the primary key for a Document.</typeparam>
/// <param name="documents">The list of documents to delete.</param>
/// <returns>The number of documents deleted.</returns>
long DeleteMany<TDocument, TKey>(IEnumerable<TDocument> documents)
where TDocument : IDocument<TKey>
where TKey : IEquatable<TKey>;
/// <summary>
/// Deletes the documents matching the condition of the LINQ expression filter.
/// </summary>
/// <typeparam name="TDocument">The type representing a Document.</typeparam>
/// <typeparam name="TKey">The type of the primary key for a Document.</typeparam>
/// <param name="filter">A LINQ expression filter.</param>
/// <param name="partitionKey">An optional partition key.</param>
/// <returns>The number of documents deleted.</returns>
long DeleteMany<TDocument, TKey>(Expression<Func<TDocument, bool>> filter, string partitionKey = null)
where TDocument : IDocument<TKey>
where TKey : IEquatable<TKey>;
#endregion
#region Project
/// <summary>
/// Asynchronously returns a projected document matching the filter condition.
/// </summary>
/// <typeparam name="TDocument">The type representing a Document.</typeparam>
/// <typeparam name="TProjection">The type representing the model you want to project to.</typeparam>
/// <param name="filter"></param>
/// <param name="projection">The projection expression.</param>
/// <param name="partitionKey">An optional partition key.</param>
Task<TProjection> ProjectOneAsync<TDocument, TProjection>(Expression<Func<TDocument, bool>> filter, Expression<Func<TDocument, TProjection>> projection, string partitionKey = null)
where TDocument : IDocument
where TProjection : class;
/// <summary>
/// Asynchronously returns a projected document matching the filter condition.
/// </summary>
/// <typeparam name="TDocument">The type representing a Document.</typeparam>
/// <typeparam name="TKey">The type of the primary key for a Document.</typeparam>
/// <typeparam name="TProjection">The type representing the model you want to project to.</typeparam>
/// <param name="filter"></param>
/// <param name="projection">The projection expression.</param>
/// <param name="partitionKey">An optional partition key.</param>
Task<TProjection> ProjectOneAsync<TDocument, TProjection, TKey>(Expression<Func<TDocument, bool>> filter, Expression<Func<TDocument, TProjection>> projection, string partitionKey = null)
where TDocument : IDocument<TKey>
where TKey : IEquatable<TKey>
where TProjection : class;
/// <summary>
/// Returns a projected document matching the filter condition.
/// </summary>
/// <typeparam name="TDocument">The type representing a Document.</typeparam>
/// <typeparam name="TProjection">The type representing the model you want to project to.</typeparam>
/// <param name="filter"></param>
/// <param name="projection">The projection expression.</param>
/// <param name="partitionKey">An optional partition key.</param>
TProjection ProjectOne<TDocument, TProjection>(Expression<Func<TDocument, bool>> filter, Expression<Func<TDocument, TProjection>> projection, string partitionKey = null)
where TDocument : IDocument
where TProjection : class;
/// <summary>
/// Returns a projected document matching the filter condition.
/// </summary>
/// <typeparam name="TDocument">The type representing a Document.</typeparam>
/// <typeparam name="TKey">The type of the primary key for a Document.</typeparam>
/// <typeparam name="TProjection">The type representing the model you want to project to.</typeparam>
/// <param name="filter"></param>
/// <param name="projection">The projection expression.</param>
/// <param name="partitionKey">An optional partition key.</param>
TProjection ProjectOne<TDocument, TProjection, TKey>(Expression<Func<TDocument, bool>> filter, Expression<Func<TDocument, TProjection>> projection, string partitionKey = null)
where TDocument : IDocument<TKey>
where TKey : IEquatable<TKey>
where TProjection : class;
/// <summary>
/// Asynchronously returns a list of projected documents matching the filter condition.
/// </summary>
/// <typeparam name="TDocument">The type representing a Document.</typeparam>
/// <typeparam name="TProjection">The type representing the model you want to project to.</typeparam>
/// <param name="filter"></param>
/// <param name="projection">The projection expression.</param>
/// <param name="partitionKey">An optional partition key.</param>
Task<List<TProjection>> ProjectManyAsync<TDocument, TProjection>(Expression<Func<TDocument, bool>> filter, Expression<Func<TDocument, TProjection>> projection, string partitionKey = null)
where TDocument : IDocument
where TProjection : class;
/// <summary>
/// Asynchronously returns a list of projected documents matching the filter condition.
/// </summary>
/// <typeparam name="TDocument">The type representing a Document.</typeparam>
/// <typeparam name="TKey">The type of the primary key for a Document.</typeparam>
/// <typeparam name="TProjection">The type representing the model you want to project to.</typeparam>
/// <param name="filter"></param>
/// <param name="projection">The projection expression.</param>
/// <param name="partitionKey">An optional partition key.</param>
Task<List<TProjection>> ProjectManyAsync<TDocument, TProjection, TKey>(Expression<Func<TDocument, bool>> filter, Expression<Func<TDocument, TProjection>> projection, string partitionKey = null)
where TDocument : IDocument<TKey>
where TKey : IEquatable<TKey>
where TProjection : class;
/// <summary>
/// Asynchronously returns a list of projected documents matching the filter condition.
/// </summary>
/// <typeparam name="TDocument">The type representing a Document.</typeparam>
/// <typeparam name="TProjection">The type representing the model you want to project to.</typeparam>
/// <param name="filter"></param>
/// <param name="projection">The projection expression.</param>
/// <param name="partitionKey">An optional partition key.</param>
List<TProjection> ProjectMany<TDocument, TProjection>(Expression<Func<TDocument, bool>> filter, Expression<Func<TDocument, TProjection>> projection, string partitionKey = null)
where TDocument : IDocument
where TProjection : class;
/// <summary>
/// Asynchronously returns a list of projected documents matching the filter condition.
/// </summary>
/// <typeparam name="TDocument">The type representing a Document.</typeparam>
/// <typeparam name="TKey">The type of the primary key for a Document.</typeparam>
/// <typeparam name="TProjection">The type representing the model you want to project to.</typeparam>
/// <param name="filter"></param>
/// <param name="projection">The projection expression.</param>
/// <param name="partitionKey">An optional partition key.</param>
List<TProjection> ProjectMany<TDocument, TProjection, TKey>(Expression<Func<TDocument, bool>> filter, Expression<Func<TDocument, TProjection>> projection, string partitionKey = null)
where TDocument : IDocument<TKey>
where TKey : IEquatable<TKey>
where TProjection : class;
#endregion
/// <summary>
/// Asynchronously returns a paginated list of the documents matching the filter condition.
/// </summary>
/// <typeparam name="TDocument">The type representing a Document.</typeparam>
/// <param name="filter"></param>
/// <param name="skipNumber">The number of documents you want to skip. Default value is 0.</param>
/// <param name="takeNumber">The number of documents you want to take. Default value is 50.</param>
/// <param name="partitionKey">An optional partition key.</param>
Task<List<TDocument>> GetPaginatedAsync<TDocument>(Expression<Func<TDocument, bool>> filter, int skipNumber = 0, int takeNumber = 50, string partitionKey = null)
where TDocument : IDocument;
/// <summary>
/// Asynchronously returns a paginated list of the documents matching the filter condition.
/// </summary>
/// <typeparam name="TDocument">The type representing a Document.</typeparam>
/// <typeparam name="TKey">The type of the primary key for a Document.</typeparam>
/// <param name="filter"></param>
/// <param name="skipNumber">The number of documents you want to skip. Default value is 0.</param>
/// <param name="takeNumber">The number of documents you want to take. Default value is 50.</param>
/// <param name="partitionKey">An optional partition key.</param>
Task<List<TDocument>> GetPaginatedAsync<TDocument, TKey>(Expression<Func<TDocument, bool>> filter, int skipNumber = 0, int takeNumber = 50, string partitionKey = null)
where TDocument : IDocument<TKey>
where TKey : IEquatable<TKey>;
/// <summary>
/// GetAndUpdateOne with filter
/// </summary>
/// <typeparam name="TDocument">The type representing a Document.</typeparam>
/// <param name="filter"></param>
/// <param name="update"></param>
/// <param name="options"></param>
/// <returns></returns>
Task<TDocument> GetAndUpdateOne<TDocument>(FilterDefinition<TDocument> filter, UpdateDefinition<TDocument> update, FindOneAndUpdateOptions<TDocument, TDocument> options)
where TDocument : IDocument;
/// <summary>
/// GetAndUpdateOne with filter
/// </summary>
/// <typeparam name="TDocument">The type representing a Document.</typeparam>
/// <typeparam name="TKey">The type of the primary key for a Document.</typeparam>
/// <param name="filter"></param>
/// <param name="update"></param>
/// <param name="options"></param>
/// <returns></returns>
Task<TDocument> GetAndUpdateOne<TDocument, TKey>(FilterDefinition<TDocument> filter, UpdateDefinition<TDocument> update, FindOneAndUpdateOptions<TDocument, TDocument> options)
where TDocument : IDocument<TKey>
where TKey : IEquatable<TKey>;
#region Grouping
/// <summary>
/// Groups a collection of documents given a grouping criteria,
/// and returns a list of projected documents.
/// </summary>
/// <typeparam name="TDocument">The type representing a Document.</typeparam>
/// <typeparam name="TGroupKey">The type of the grouping criteria.</typeparam>
/// <typeparam name="TProjection">The type of the projected group.</typeparam>
/// <param name="groupingCriteria">The grouping criteria.</param>
/// <param name="groupProjection">The projected group result.</param>
/// <param name="partitionKey">The partition key of your document, if any.</param>
List<TProjection> GroupBy<TDocument, TGroupKey, TProjection>(
Expression<Func<TDocument, TGroupKey>> groupingCriteria,
Expression<Func<IGrouping<TGroupKey, TDocument>, TProjection>> groupProjection,
string partitionKey = null)
where TDocument : IDocument
where TProjection : class, new();
/// <summary>
/// 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.
/// </summary>
/// <typeparam name="TDocument">The type representing a Document.</typeparam>
/// <typeparam name="TGroupKey">The type of the grouping criteria.</typeparam>
/// <typeparam name="TProjection">The type of the projected group.</typeparam>
/// <param name="filter"></param>
/// <param name="selector">The grouping criteria.</param>
/// <param name="projection">The projected group result.</param>
/// <param name="partitionKey">The partition key of your document, if any.</param>
List<TProjection> GroupBy<TDocument, TGroupKey, TProjection>(Expression<Func<TDocument, bool>> filter,
Expression<Func<TDocument, TGroupKey>> selector,
Expression<Func<IGrouping<TGroupKey, TDocument>, TProjection>> projection,
string partitionKey = null)
where TDocument : IDocument
where TProjection : class, new();
#endregion
}
}
@@ -53,5 +53,11 @@ namespace MongoDbGenericRepository
/// </summary> /// </summary>
/// <typeparam name="TDocument"></typeparam> /// <typeparam name="TDocument"></typeparam>
void DropCollection<TDocument>(string partitionKey); void DropCollection<TDocument>(string partitionKey);
/// <summary>
/// Sets the Guid representation of the MongoDb Driver.
/// </summary>
/// <param name="guidRepresentation">The new value of the GuidRepresentation</param>
void SetGuidRepresentation(MongoDB.Bson.GuidRepresentation guidRepresentation);
} }
} }
@@ -0,0 +1,244 @@
using MongoDB.Driver;
using System;
using System.Collections.Generic;
using System.Threading.Tasks;
using System.Linq.Expressions;
using MongoDbGenericRepository.Models;
namespace MongoDbGenericRepository
{
/// <summary>
/// The IReadOnlyMongoRepository exposes the readonly functionality of the BaseMongoRepository.
/// </summary>
public interface IReadOnlyMongoRepository
{
/// <summary>
/// The connection string.
/// </summary>
string ConnectionString { get; set; }
/// <summary>
/// The database name.
/// </summary>
string DatabaseName { get; set; }
#region Read
/// <summary>
/// Asynchronously returns one document given its id.
/// </summary>
/// <typeparam name="TDocument">The type representing a Document.</typeparam>
/// <param name="id">The Id of the document you want to get.</param>
/// <param name="partitionKey">An optional partition key.</param>
Task<TDocument> GetByIdAsync<TDocument>(Guid id, string partitionKey = null) where TDocument : IDocument;
/// <summary>
/// Returns one document given its id.
/// </summary>
/// <typeparam name="TDocument">The type representing a Document.</typeparam>
/// <param name="id">The Id of the document you want to get.</param>
/// <param name="partitionKey">An optional partition key.</param>
TDocument GetById<TDocument>(Guid id, string partitionKey = null) where TDocument : IDocument;
/// <summary>
/// Asynchronously returns one document given an expression filter.
/// </summary>
/// <typeparam name="TDocument">The type representing a Document.</typeparam>
/// <param name="filter">A LINQ expression filter.</param>
/// <param name="partitionKey">An optional partition key.</param>
Task<TDocument> GetOneAsync<TDocument>(Expression<Func<TDocument, bool>> filter, string partitionKey = null) where TDocument : IDocument;
/// <summary>
/// Returns one document given an expression filter.
/// </summary>
/// <typeparam name="TDocument">The type representing a Document.</typeparam>
/// <param name="filter">A LINQ expression filter.</param>
/// <param name="partitionKey">An optional partition key.</param>
TDocument GetOne<TDocument>(Expression<Func<TDocument, bool>> filter, string partitionKey = null) where TDocument : IDocument;
/// <summary>
/// Returns a collection cursor.
/// </summary>
/// <typeparam name="TDocument">The type representing a Document.</typeparam>
/// <param name="filter">A LINQ expression filter.</param>
/// <param name="partitionKey">An optional partition key.</param>
IFindFluent<TDocument, TDocument> GetCursor<TDocument>(Expression<Func<TDocument, bool>> filter, string partitionKey = null) where TDocument : IDocument;
/// <summary>
/// Asynchronously returns true if any of the document of the collection matches the filter condition.
/// </summary>
/// <typeparam name="TDocument">The type representing a Document.</typeparam>
/// <param name="filter">A LINQ expression filter.</param>
/// <param name="partitionKey">An optional partition key.</param>
Task<bool> AnyAsync<TDocument>(Expression<Func<TDocument, bool>> filter, string partitionKey = null) where TDocument : IDocument;
/// <summary>
/// Returns true if any of the document of the collection matches the filter condition.
/// </summary>
/// <typeparam name="TDocument">The type representing a Document.</typeparam>
/// <param name="filter">A LINQ expression filter.</param>
/// <param name="partitionKey">An optional partition key.</param>
bool Any<TDocument>(Expression<Func<TDocument, bool>> filter, string partitionKey = null) where TDocument : IDocument;
/// <summary>
/// Asynchronously returns a list of the documents matching the filter condition.
/// </summary>
/// <typeparam name="TDocument">The type representing a Document.</typeparam>
/// <param name="filter">A LINQ expression filter.</param>
/// <param name="partitionKey">An optional partition key.</param>
Task<List<TDocument>> GetAllAsync<TDocument>(Expression<Func<TDocument, bool>> filter, string partitionKey = null) where TDocument : IDocument;
/// <summary>
/// Returns a list of the documents matching the filter condition.
/// </summary>
/// <typeparam name="TDocument">The type representing a Document.</typeparam>
/// <param name="filter">A LINQ expression filter.</param>
/// <param name="partitionKey">An optional partition key.</param>
List<TDocument> GetAll<TDocument>(Expression<Func<TDocument, bool>> filter, string partitionKey = null) where TDocument : IDocument;
/// <summary>
/// Asynchronously counts how many documents match the filter condition.
/// </summary>
/// <typeparam name="TDocument">The type representing a Document.</typeparam>
/// <param name="filter">A LINQ expression filter.</param>
/// <param name="partitionKey">An optional partition key.</param>
Task<long> CountAsync<TDocument>(Expression<Func<TDocument, bool>> filter, string partitionKey = null) where TDocument : IDocument;
/// <summary>
/// Counts how many documents match the filter condition.
/// </summary>
/// <typeparam name="TDocument">The type representing a Document.</typeparam>
/// <param name="filter">A LINQ expression filter.</param>
/// <param name="partitionKey">An optional partition key.</param>
long Count<TDocument>(Expression<Func<TDocument, bool>> filter, string partitionKey = null) where TDocument : IDocument;
#endregion
#region Read TKey
/// <summary>
/// Asynchronously returns one document given its id.
/// </summary>
/// <typeparam name="TDocument">The type representing a Document.</typeparam>
/// <typeparam name="TKey">The type of the primary key for a Document.</typeparam>
/// <param name="id">The Id of the document you want to get.</param>
/// <param name="partitionKey">An optional partition key.</param>
Task<TDocument> GetByIdAsync<TDocument, TKey>(TKey id, string partitionKey = null)
where TDocument : IDocument<TKey>
where TKey : IEquatable<TKey>;
/// <summary>
/// Returns one document given its id.
/// </summary>
/// <typeparam name="TDocument">The type representing a Document.</typeparam>
/// <typeparam name="TKey">The type of the primary key for a Document.</typeparam>
/// <param name="id">The Id of the document you want to get.</param>
/// <param name="partitionKey">An optional partition key.</param>
TDocument GetById<TDocument, TKey>(TKey id, string partitionKey = null)
where TDocument : IDocument<TKey>
where TKey : IEquatable<TKey>;
/// <summary>
/// Asynchronously returns one document given an expression filter.
/// </summary>
/// <typeparam name="TDocument">The type representing a Document.</typeparam>
/// <typeparam name="TKey">The type of the primary key for a Document.</typeparam>
/// <param name="filter">A LINQ expression filter.</param>
/// <param name="partitionKey">An optional partition key.</param>
Task<TDocument> GetOneAsync<TDocument, TKey>(Expression<Func<TDocument, bool>> filter, string partitionKey = null)
where TDocument : IDocument<TKey>
where TKey : IEquatable<TKey>;
/// <summary>
/// Returns one document given an expression filter.
/// </summary>
/// <typeparam name="TDocument">The type representing a Document.</typeparam>
/// <typeparam name="TKey">The type of the primary key for a Document.</typeparam>
/// <param name="filter">A LINQ expression filter.</param>
/// <param name="partitionKey">An optional partition key.</param>
TDocument GetOne<TDocument, TKey>(Expression<Func<TDocument, bool>> filter, string partitionKey = null)
where TDocument : IDocument<TKey>
where TKey : IEquatable<TKey>;
/// <summary>
/// Returns a collection cursor.
/// </summary>
/// <typeparam name="TDocument">The type representing a Document.</typeparam>
/// <typeparam name="TKey">The type of the primary key for a Document.</typeparam>
/// <param name="filter">A LINQ expression filter.</param>
/// <param name="partitionKey">An optional partition key.</param>
IFindFluent<TDocument, TDocument> GetCursor<TDocument, TKey>(Expression<Func<TDocument, bool>> filter, string partitionKey = null)
where TDocument : IDocument<TKey>
where TKey : IEquatable<TKey>;
/// <summary>
/// Returns true if any of the document of the collection matches the filter condition.
/// </summary>
/// <typeparam name="TDocument">The type representing a Document.</typeparam>
/// <typeparam name="TKey">The type of the primary key for a Document.</typeparam>
/// <param name="filter">A LINQ expression filter.</param>
/// <param name="partitionKey">An optional partition key.</param>
Task<bool> AnyAsync<TDocument, TKey>(Expression<Func<TDocument, bool>> filter, string partitionKey = null)
where TDocument : IDocument<TKey>
where TKey : IEquatable<TKey>;
/// <summary>
/// Returns true if any of the document of the collection matches the filter condition.
/// </summary>
/// <typeparam name="TDocument">The type representing a Document.</typeparam>
/// <typeparam name="TKey">The type of the primary key for a Document.</typeparam>
/// <param name="filter">A LINQ expression filter.</param>
/// <param name="partitionKey">An optional partition key.</param>
bool Any<TDocument, TKey>(Expression<Func<TDocument, bool>> filter, string partitionKey = null)
where TDocument : IDocument<TKey>
where TKey : IEquatable<TKey>;
/// <summary>
/// Asynchronously returns a list of the documents matching the filter condition.
/// </summary>
/// <typeparam name="TDocument">The type representing a Document.</typeparam>
/// <typeparam name="TKey">The type of the primary key for a Document.</typeparam>
/// <param name="filter">A LINQ expression filter.</param>
/// <param name="partitionKey">An optional partition key.</param>
Task<List<TDocument>> GetAllAsync<TDocument, TKey>(Expression<Func<TDocument, bool>> filter, string partitionKey = null)
where TDocument : IDocument<TKey>
where TKey : IEquatable<TKey>;
/// <summary>
/// Returns a list of the documents matching the filter condition.
/// </summary>
/// <typeparam name="TDocument">The type representing a Document.</typeparam>
/// <typeparam name="TKey">The type of the primary key for a Document.</typeparam>
/// <param name="filter">A LINQ expression filter.</param>
/// <param name="partitionKey">An optional partition key.</param>
List<TDocument> GetAll<TDocument, TKey>(Expression<Func<TDocument, bool>> filter, string partitionKey = null)
where TDocument : IDocument<TKey>
where TKey : IEquatable<TKey>;
/// <summary>
/// Asynchronously counts how many documents match the filter condition.
/// </summary>
/// <typeparam name="TDocument">The type representing a Document.</typeparam>
/// <typeparam name="TKey">The type of the primary key for a Document.</typeparam>
/// <param name="filter">A LINQ expression filter.</param>
/// <param name="partitionKey">An optional partitionKey</param>
Task<long> CountAsync<TDocument, TKey>(Expression<Func<TDocument, bool>> filter, string partitionKey = null)
where TDocument : IDocument<TKey>
where TKey : IEquatable<TKey>;
/// <summary>
/// Counts how many documents match the filter condition.
/// </summary>
/// <typeparam name="TDocument">The type representing a Document.</typeparam>
/// <typeparam name="TKey">The type of the primary key for a Document.</typeparam>
/// <param name="filter">A LINQ expression filter.</param>
/// <param name="partitionKey">An optional partitionKey</param>
long Count<TDocument, TKey>(Expression<Func<TDocument, bool>> filter, string partitionKey = null)
where TDocument : IDocument<TKey>
where TKey : IEquatable<TKey>;
#endregion
}
}
+1 -2
View File
@@ -13,7 +13,6 @@ namespace MongoDbGenericRepository.Models
/// The Primary Key, which must be decorated with the [BsonId] attribute /// The Primary Key, which must be decorated with the [BsonId] attribute
/// if you want the MongoDb C# driver to consider it to be the document ID. /// if you want the MongoDb C# driver to consider it to be the document ID.
/// </summary> /// </summary>
[BsonId]
TKey Id { get; set; } TKey Id { get; set; }
/// <summary> /// <summary>
/// A version number, to indicate the version of the schema. /// A version number, to indicate the version of the schema.
@@ -25,7 +24,7 @@ namespace MongoDbGenericRepository.Models
/// This class represents a basic document that can be stored in MongoDb. /// This class represents a basic document that can be stored in MongoDb.
/// Your document must implement this class in order for the MongoDbRepository to handle them. /// Your document must implement this class in order for the MongoDbRepository to handle them.
/// </summary> /// </summary>
public interface IDocument: IDocument<Guid> public interface IDocument : IDocument<Guid>
{ {
} }
} }
@@ -1,5 +1,6 @@
using MongoDB.Driver; using MongoDB.Driver;
using MongoDbGenericRepository.Models; using MongoDbGenericRepository.Models;
using MongoDbGenericRepository.Utils;
using System; using System;
namespace MongoDbGenericRepository namespace MongoDbGenericRepository
@@ -25,6 +26,15 @@ namespace MongoDbGenericRepository
MongoDefaults.GuidRepresentation = MongoDB.Bson.GuidRepresentation.Standard; MongoDefaults.GuidRepresentation = MongoDB.Bson.GuidRepresentation.Standard;
} }
/// <summary>
/// Sets the Guid representation of the MongoDb Driver.
/// </summary>
/// <param name="guidRepresentation">The new value of the GuidRepresentation</param>
public void SetGuidRepresentation(MongoDB.Bson.GuidRepresentation guidRepresentation)
{
MongoDefaults.GuidRepresentation = guidRepresentation;
}
/// <summary> /// <summary>
/// The constructor of the MongoDbContext, it needs a an object implementing <see cref="IMongoDatabase"/>. /// The constructor of the MongoDbContext, it needs a an object implementing <see cref="IMongoDatabase"/>.
/// </summary> /// </summary>
@@ -17,7 +17,7 @@
</PropertyGroup> </PropertyGroup>
<ItemGroup> <ItemGroup>
<PackageReference Include="MongoDB.Driver" Version="2.4.4" /> <PackageReference Include="MongoDB.Driver" Version="2.5.0" />
</ItemGroup> </ItemGroup>
</Project> </Project>
@@ -2,7 +2,7 @@
<package > <package >
<metadata> <metadata>
<id>MongoDbGenericRepository</id> <id>MongoDbGenericRepository</id>
<version>1.3</version> <version>1.3.4</version>
<title>MongoDb Generic Repository</title> <title>MongoDb Generic Repository</title>
<authors>Alexandre Spieser</authors> <authors>Alexandre Spieser</authors>
<owners>Alexandre Spieser</owners> <owners>Alexandre Spieser</owners>
@@ -10,9 +10,12 @@
<projectUrl>https://github.com/alexandre-spieser/mongodb-generic-repository</projectUrl> <projectUrl>https://github.com/alexandre-spieser/mongodb-generic-repository</projectUrl>
<requireLicenseAcceptance>false</requireLicenseAcceptance> <requireLicenseAcceptance>false</requireLicenseAcceptance>
<description>A generic repository implementation using the MongoDB C# Sharp 2.0 driver.</description> <description>A generic repository implementation using the MongoDB C# Sharp 2.0 driver.</description>
<releaseNotes>Added support for Documents that have an Id of type TKey, and implement the IDocument{TKey} interface.</releaseNotes> <releaseNotes>Updating MongoDB driver to version 2.5.0 for MongoDB 3.6 support.</releaseNotes>
<copyright>Copyright 2017 (c) Alexandre Spieser. All rights reserved.</copyright> <copyright>Copyright 2017 (c) Alexandre Spieser. All rights reserved.</copyright>
<tags>MongoDb Repository Generic NoSql</tags> <tags>MongoDb Repository Generic NoSql</tags>
<dependencies>
<dependency id="MongoDB.Driver" version="2.5.0" />
</dependencies>
</metadata> </metadata>
<files> <files>
<file src="lib\**" target="lib" /> <file src="lib\**" target="lib" />
@@ -0,0 +1,469 @@
using MongoDB.Driver;
using System;
using System.Collections.Generic;
using System.Threading.Tasks;
using System.Linq.Expressions;
using MongoDbGenericRepository.Models;
using System.Linq;
namespace MongoDbGenericRepository
{
/// <summary>
/// The ReadOnlyMongoRepository implements the readonly functionality of the IReadOnlyMongoRepository.
/// </summary>
public class ReadOnlyMongoRepository : IReadOnlyMongoRepository
{
/// <summary>
/// The connection string.
/// </summary>
public string ConnectionString { get; set; }
/// <summary>
/// The database name.
/// </summary>
public string DatabaseName { get; set; }
/// <summary>
/// The MongoDbContext
/// </summary>
protected IMongoDbContext MongoDbContext = null;
/// <summary>
/// The constructor taking a connection string and a database name.
/// </summary>
/// <param name="connectionString">The connection string of the MongoDb server.</param>
/// <param name="databaseName">The name of the database against which you want to perform operations.</param>
protected ReadOnlyMongoRepository(string connectionString, string databaseName)
{
MongoDbContext = new MongoDbContext(connectionString, databaseName);
}
/// <summary>
/// The contructor taking a <see cref="IMongoDbContext"/>.
/// </summary>
/// <param name="mongoDbContext">A mongodb context implementing <see cref="IMongoDbContext"/></param>
protected ReadOnlyMongoRepository(IMongoDbContext mongoDbContext)
{
MongoDbContext = mongoDbContext;
}
/// <summary>
/// The contructor taking a <see cref="IMongoDatabase"/>.
/// </summary>
/// <param name="mongoDatabase">A mongodb context implementing <see cref="IMongoDatabase"/></param>
protected ReadOnlyMongoRepository(IMongoDatabase mongoDatabase)
{
MongoDbContext = new MongoDbContext(mongoDatabase);
}
#region Read
/// <summary>
/// Asynchronously returns one document given its id.
/// </summary>
/// <typeparam name="TDocument">The type representing a Document.</typeparam>
/// <param name="id">The Id of the document you want to get.</param>
/// <param name="partitionKey">An optional partition key.</param>
public async Task<TDocument> GetByIdAsync<TDocument>(Guid id, string partitionKey = null) where TDocument : IDocument
{
var filter = Builders<TDocument>.Filter.Eq("Id", id);
return await HandlePartitioned<TDocument>(partitionKey).Find(filter).FirstOrDefaultAsync();
}
/// <summary>
/// Returns one document given its id.
/// </summary>
/// <typeparam name="TDocument">The type representing a Document.</typeparam>
/// <param name="id">The Id of the document you want to get.</param>
/// <param name="partitionKey">An optional partition key.</param>
public TDocument GetById<TDocument>(Guid id, string partitionKey = null) where TDocument : IDocument
{
var filter = Builders<TDocument>.Filter.Eq("Id", id);
return HandlePartitioned<TDocument>(partitionKey).Find(filter).FirstOrDefault();
}
/// <summary>
/// Asynchronously returns one document given an expression filter.
/// </summary>
/// <typeparam name="TDocument">The type representing a Document.</typeparam>
/// <param name="filter">A LINQ expression filter.</param>
/// <param name="partitionKey">An optional partition key.</param>
public async Task<TDocument> GetOneAsync<TDocument>(Expression<Func<TDocument, bool>> filter, string partitionKey = null) where TDocument : IDocument
{
return await HandlePartitioned<TDocument>(partitionKey).Find(filter).FirstOrDefaultAsync();
}
/// <summary>
/// Returns one document given an expression filter.
/// </summary>
/// <typeparam name="TDocument">The type representing a Document.</typeparam>
/// <param name="filter">A LINQ expression filter.</param>
/// <param name="partitionKey">An optional partition key.</param>
public TDocument GetOne<TDocument>(Expression<Func<TDocument, bool>> filter, string partitionKey = null) where TDocument : IDocument
{
return HandlePartitioned<TDocument>(partitionKey).Find(filter).FirstOrDefault();
}
/// <summary>
/// Returns a collection cursor.
/// </summary>
/// <typeparam name="TDocument">The type representing a Document.</typeparam>
/// <param name="filter">A LINQ expression filter.</param>
/// <param name="partitionKey">An optional partition key.</param>
public IFindFluent<TDocument, TDocument> GetCursor<TDocument>(Expression<Func<TDocument, bool>> filter, string partitionKey = null) where TDocument : IDocument
{
return HandlePartitioned<TDocument>(partitionKey).Find(filter);
}
/// <summary>
/// Returns true if any of the document of the collection matches the filter condition.
/// </summary>
/// <typeparam name="TDocument">The type representing a Document.</typeparam>
/// <param name="filter">A LINQ expression filter.</param>
/// <param name="partitionKey">An optional partition key.</param>
public async Task<bool> AnyAsync<TDocument>(Expression<Func<TDocument, bool>> filter, string partitionKey = null) where TDocument : IDocument
{
var count = await HandlePartitioned<TDocument>(partitionKey).CountAsync(filter);
return (count > 0);
}
/// <summary>
/// Returns true if any of the document of the collection matches the filter condition.
/// </summary>
/// <typeparam name="TDocument">The type representing a Document.</typeparam>
/// <param name="filter">A LINQ expression filter.</param>
/// <param name="partitionKey">An optional partition key.</param>
public bool Any<TDocument>(Expression<Func<TDocument, bool>> filter, string partitionKey = null) where TDocument : IDocument
{
var count = HandlePartitioned<TDocument>(partitionKey).Count(filter);
return (count > 0);
}
/// <summary>
/// Asynchronously returns a list of the documents matching the filter condition.
/// </summary>
/// <typeparam name="TDocument">The type representing a Document.</typeparam>
/// <param name="filter">A LINQ expression filter.</param>
/// <param name="partitionKey">An optional partition key.</param>
public async Task<List<TDocument>> GetAllAsync<TDocument>(Expression<Func<TDocument, bool>> filter, string partitionKey = null) where TDocument : IDocument
{
return await HandlePartitioned<TDocument>(partitionKey).Find(filter).ToListAsync();
}
/// <summary>
/// Returns a list of the documents matching the filter condition.
/// </summary>
/// <typeparam name="TDocument">The type representing a Document.</typeparam>
/// <param name="filter">A LINQ expression filter.</param>
/// <param name="partitionKey">An optional partition key.</param>
public List<TDocument> GetAll<TDocument>(Expression<Func<TDocument, bool>> filter, string partitionKey = null) where TDocument : IDocument
{
return HandlePartitioned<TDocument>(partitionKey).Find(filter).ToList();
}
/// <summary>
/// Asynchronously counts how many documents match the filter condition.
/// </summary>
/// <typeparam name="TDocument">The type representing a Document.</typeparam>
/// <param name="filter">A LINQ expression filter.</param>
/// <param name="partitionKey">An optional partitionKey</param>
public async Task<long> CountAsync<TDocument>(Expression<Func<TDocument, bool>> filter, string partitionKey = null) where TDocument : IDocument
{
return await HandlePartitioned<TDocument>(partitionKey).CountAsync(filter);
}
/// <summary>
/// Counts how many documents match the filter condition.
/// </summary>
/// <typeparam name="TDocument">The type representing a Document.</typeparam>
/// <param name="filter">A LINQ expression filter.</param>
/// <param name="partitionKey">An optional partitionKey</param>
public long Count<TDocument>(Expression<Func<TDocument, bool>> filter, string partitionKey = null) where TDocument : IDocument
{
return HandlePartitioned<TDocument>(partitionKey).Find(filter).Count();
}
#endregion
#region Read TKey
/// <summary>
/// Asynchronously returns one document given its id.
/// </summary>
/// <typeparam name="TDocument">The type representing a Document.</typeparam>
/// <typeparam name="TKey">The type of the primary key for a Document.</typeparam>
/// <param name="id">The Id of the document you want to get.</param>
/// <param name="partitionKey">An optional partition key.</param>
public async Task<TDocument> GetByIdAsync<TDocument, TKey>(TKey id, string partitionKey = null)
where TDocument : IDocument<TKey>
where TKey : IEquatable<TKey>
{
var filter = Builders<TDocument>.Filter.Eq("Id", id);
return await HandlePartitioned<TDocument, TKey>(partitionKey).Find(filter).FirstOrDefaultAsync();
}
/// <summary>
/// Returns one document given its id.
/// </summary>
/// <typeparam name="TDocument">The type representing a Document.</typeparam>
/// <typeparam name="TKey">The type of the primary key for a Document.</typeparam>
/// <param name="id">The Id of the document you want to get.</param>
/// <param name="partitionKey">An optional partition key.</param>
public TDocument GetById<TDocument, TKey>(TKey id, string partitionKey = null)
where TDocument : IDocument<TKey>
where TKey : IEquatable<TKey>
{
var filter = Builders<TDocument>.Filter.Eq("Id", id);
return HandlePartitioned<TDocument, TKey>(partitionKey).Find(filter).FirstOrDefault();
}
/// <summary>
/// Asynchronously returns one document given an expression filter.
/// </summary>
/// <typeparam name="TDocument">The type representing a Document.</typeparam>
/// <typeparam name="TKey">The type of the primary key for a Document.</typeparam>
/// <param name="filter">A LINQ expression filter.</param>
/// <param name="partitionKey">An optional partition key.</param>
public async Task<TDocument> GetOneAsync<TDocument, TKey>(Expression<Func<TDocument, bool>> filter, string partitionKey = null)
where TDocument : IDocument<TKey>
where TKey : IEquatable<TKey>
{
return await HandlePartitioned<TDocument, TKey>(partitionKey).Find(filter).FirstOrDefaultAsync();
}
/// <summary>
/// Returns one document given an expression filter.
/// </summary>
/// <typeparam name="TDocument">The type representing a Document.</typeparam>
/// <typeparam name="TKey">The type of the primary key for a Document.</typeparam>
/// <param name="filter">A LINQ expression filter.</param>
/// <param name="partitionKey">An optional partition key.</param>
public TDocument GetOne<TDocument, TKey>(Expression<Func<TDocument, bool>> filter, string partitionKey = null)
where TDocument : IDocument<TKey>
where TKey : IEquatable<TKey>
{
return HandlePartitioned<TDocument, TKey>(partitionKey).Find(filter).FirstOrDefault();
}
/// <summary>
/// Returns a collection cursor.
/// </summary>
/// <typeparam name="TDocument">The type representing a Document.</typeparam>
/// <typeparam name="TKey">The type of the primary key for a Document.</typeparam>
/// <param name="filter">A LINQ expression filter.</param>
/// <param name="partitionKey">An optional partition key.</param>
public IFindFluent<TDocument, TDocument> GetCursor<TDocument, TKey>(Expression<Func<TDocument, bool>> filter, string partitionKey = null)
where TDocument : IDocument<TKey>
where TKey : IEquatable<TKey>
{
return HandlePartitioned<TDocument, TKey>(partitionKey).Find(filter);
}
/// <summary>
/// Returns true if any of the document of the collection matches the filter condition.
/// </summary>
/// <typeparam name="TDocument">The type representing a Document.</typeparam>
/// <typeparam name="TKey">The type of the primary key for a Document.</typeparam>
/// <param name="filter">A LINQ expression filter.</param>
/// <param name="partitionKey">An optional partition key.</param>
public async Task<bool> AnyAsync<TDocument, TKey>(Expression<Func<TDocument, bool>> filter, string partitionKey = null)
where TDocument : IDocument<TKey>
where TKey : IEquatable<TKey>
{
var count = await HandlePartitioned<TDocument, TKey>(partitionKey).CountAsync(filter);
return (count > 0);
}
/// <summary>
/// Returns true if any of the document of the collection matches the filter condition.
/// </summary>
/// <typeparam name="TDocument">The type representing a Document.</typeparam>
/// <typeparam name="TKey">The type of the primary key for a Document.</typeparam>
/// <param name="filter">A LINQ expression filter.</param>
/// <param name="partitionKey">An optional partition key.</param>
public bool Any<TDocument, TKey>(Expression<Func<TDocument, bool>> filter, string partitionKey = null)
where TDocument : IDocument<TKey>
where TKey : IEquatable<TKey>
{
var count = HandlePartitioned<TDocument, TKey>(partitionKey).Count(filter);
return (count > 0);
}
/// <summary>
/// Asynchronously returns a list of the documents matching the filter condition.
/// </summary>
/// <typeparam name="TDocument">The type representing a Document.</typeparam>
/// <typeparam name="TKey">The type of the primary key for a Document.</typeparam>
/// <param name="filter">A LINQ expression filter.</param>
/// <param name="partitionKey">An optional partition key.</param>
public async Task<List<TDocument>> GetAllAsync<TDocument, TKey>(Expression<Func<TDocument, bool>> filter, string partitionKey = null)
where TDocument : IDocument<TKey>
where TKey : IEquatable<TKey>
{
return await HandlePartitioned<TDocument, TKey>(partitionKey).Find(filter).ToListAsync();
}
/// <summary>
/// Returns a list of the documents matching the filter condition.
/// </summary>
/// <typeparam name="TDocument">The type representing a Document.</typeparam>
/// <typeparam name="TKey">The type of the primary key for a Document.</typeparam>
/// <param name="filter">A LINQ expression filter.</param>
/// <param name="partitionKey">An optional partition key.</param>
public List<TDocument> GetAll<TDocument, TKey>(Expression<Func<TDocument, bool>> filter, string partitionKey = null)
where TDocument : IDocument<TKey>
where TKey : IEquatable<TKey>
{
return HandlePartitioned<TDocument, TKey>(partitionKey).Find(filter).ToList();
}
/// <summary>
/// Asynchronously counts how many documents match the filter condition.
/// </summary>
/// <typeparam name="TDocument">The type representing a Document.</typeparam>
/// <typeparam name="TKey">The type of the primary key for a Document.</typeparam>
/// <param name="filter">A LINQ expression filter.</param>
/// <param name="partitionKey">An optional partitionKey</param>
public async Task<long> CountAsync<TDocument, TKey>(Expression<Func<TDocument, bool>> filter, string partitionKey = null)
where TDocument : IDocument<TKey>
where TKey : IEquatable<TKey>
{
return await HandlePartitioned<TDocument, TKey>(partitionKey).CountAsync(filter);
}
/// <summary>
/// Counts how many documents match the filter condition.
/// </summary>
/// <typeparam name="TDocument">The type representing a Document.</typeparam>
/// <typeparam name="TKey">The type of the primary key for a Document.</typeparam>
/// <param name="filter">A LINQ expression filter.</param>
/// <param name="partitionKey">An optional partitionKey</param>
public long Count<TDocument, TKey>(Expression<Func<TDocument, bool>> filter, string partitionKey = null)
where TDocument : IDocument<TKey>
where TKey : IEquatable<TKey>
{
return HandlePartitioned<TDocument, TKey>(partitionKey).Find(filter).Count();
}
#endregion
#region Utility Methods
/// <summary>
/// Gets a collections for the type TDocument with the matching partition key.
/// </summary>
/// <typeparam name="TDocument">The document type.</typeparam>
/// <param name="partitionKey">The partion key.</param>
/// <returns>An <see cref="IMongoCollection{TDocument}"/></returns>
protected IMongoCollection<TDocument> GetCollection<TDocument>(string partitionKey) where TDocument : IDocument
{
return MongoDbContext.GetCollection<TDocument>(partitionKey);
}
/// <summary>
/// Gets a collections for the type TDocument
/// </summary>
/// <typeparam name="TDocument">The document type.</typeparam>
/// <returns></returns>
protected IMongoCollection<TDocument> GetCollection<TDocument>() where TDocument : IDocument
{
return MongoDbContext.GetCollection<TDocument>();
}
/// <summary>
/// Gets a collections for the type TDocument
/// </summary>
/// <typeparam name="TDocument">The document type.</typeparam>
/// <param name="document">The document.</param>
/// <returns></returns>
protected IMongoCollection<TDocument> HandlePartitioned<TDocument>(TDocument document) where TDocument : IDocument
{
if (document is IPartitionedDocument)
{
return GetCollection<TDocument>(((IPartitionedDocument)document).PartitionKey);
}
return GetCollection<TDocument>();
}
/// <summary>
/// Gets a collections for a potentially partitioned document type.
/// </summary>
/// <typeparam name="TDocument">The document type.</typeparam>
/// <typeparam name="TKey">The type of the primary key.</typeparam>
/// <param name="document">The document.</param>
/// <returns></returns>
protected IMongoCollection<TDocument> HandlePartitioned<TDocument, TKey>(TDocument document)
where TDocument : IDocument<TKey>
where TKey : IEquatable<TKey>
{
if (document is IPartitionedDocument)
{
return GetCollection<TDocument, TKey>(((IPartitionedDocument)document).PartitionKey);
}
return GetCollection<TDocument, TKey>();
}
/// <summary>
/// Gets a collections for a potentially partitioned document type.
/// </summary>
/// <typeparam name="TDocument">The document type.</typeparam>
/// <param name="partitionKey">The collection partition key.</param>
/// <returns></returns>
protected IMongoCollection<TDocument> HandlePartitioned<TDocument>(string partitionKey) where TDocument : IDocument
{
if (!string.IsNullOrEmpty(partitionKey))
{
return GetCollection<TDocument>(partitionKey);
}
return GetCollection<TDocument>();
}
/// <summary>
/// Gets a collections for the type TDocument with a partition key.
/// </summary>
/// <typeparam name="TDocument">The document type.</typeparam>
/// <typeparam name="TKey">The type of the primary key.</typeparam>
/// <param name="partitionKey">The collection partition key.</param>
/// <returns></returns>
protected IMongoCollection<TDocument> GetCollection<TDocument, TKey>(string partitionKey)
where TDocument : IDocument<TKey>
where TKey : IEquatable<TKey>
{
return MongoDbContext.GetCollection<TDocument, TKey>(partitionKey);
}
/// <summary>
/// Gets a collections for the type TDocument
/// </summary>
/// <typeparam name="TDocument">The document type.</typeparam>
/// <typeparam name="TKey">The type of the primary key.</typeparam>
/// <returns></returns>
protected IMongoCollection<TDocument> GetCollection<TDocument, TKey>()
where TDocument : IDocument<TKey>
where TKey : IEquatable<TKey>
{
return MongoDbContext.GetCollection<TDocument>();
}
/// <summary>
/// Gets a collections for a potentially partitioned document type.
/// </summary>
/// <typeparam name="TDocument">The document type.</typeparam>
/// <typeparam name="TKey">The type of the primary key.</typeparam>
/// <param name="partitionKey">The collection partition key.</param>
/// <returns></returns>
protected IMongoCollection<TDocument> HandlePartitioned<TDocument, TKey>(string partitionKey)
where TDocument : IDocument<TKey>
where TKey : IEquatable<TKey>
{
if (!string.IsNullOrEmpty(partitionKey))
{
return GetCollection<TDocument, TKey>(partitionKey);
}
return GetCollection<TDocument, TKey>();
}
#endregion
}
}
@@ -64,7 +64,7 @@ using System.Collections.Generic;
using System.Text.RegularExpressions; using System.Text.RegularExpressions;
using System.Threading; using System.Threading;
namespace MongoDbGenericRepository namespace MongoDbGenericRepository.Utils
{ {
/// <summary> /// <summary>
/// Container for registered Vocabularies. At present, only a single vocabulary is supported: Default. /// Container for registered Vocabularies. At present, only a single vocabulary is supported: Default.
@@ -0,0 +1,60 @@
using System;
namespace MongoDbGenericRepository.Utils
{
// Thanks BlueRaja - Danny Pflughoeft https://stackoverflow.com/a/13095144/5103354
/// <summary>
/// Extensions for the random number generator <see cref="Random"/>
/// </summary>
public static class RandomExtensions
{
/// <summary>
/// Returns a random long from min (inclusive) to max (exclusive)
/// </summary>
/// <param name="random">The given random instance</param>
/// <param name="min">The inclusive minimum bound</param>
/// <param name="max">The exclusive maximum bound. Must be greater than min</param>
public static long NextLong(this Random random, long min, long max)
{
if (max <= min)
throw new ArgumentOutOfRangeException("max", "max must be > min!");
//Working with ulong so that modulo works correctly with values > long.MaxValue
ulong uRange = (ulong)(max - min);
//Prevent a modulo bias; see https://stackoverflow.com/a/10984975/238419
//for more information.
//In the worst case, the expected number of calls is 2 (though usually it's
//much closer to 1) so this loop doesn't really hurt performance at all.
ulong ulongRand;
do
{
byte[] buf = new byte[8];
random.NextBytes(buf);
ulongRand = (ulong)BitConverter.ToInt64(buf, 0);
} while (ulongRand > ulong.MaxValue - ((ulong.MaxValue % uRange) + 1) % uRange);
return (long)(ulongRand % uRange) + min;
}
/// <summary>
/// Returns a random long from 0 (inclusive) to max (exclusive)
/// </summary>
/// <param name="random">The given random instance</param>
/// <param name="max">The exclusive maximum bound. Must be greater than 0</param>
public static long NextLong(this Random random, long max)
{
return random.NextLong(0, max);
}
/// <summary>
/// Returns a random long over all possible values of long (except long.MaxValue, similar to
/// random.Next())
/// </summary>
/// <param name="random">The given random instance</param>
public static long NextLong(this Random random)
{
return random.NextLong(long.MinValue, long.MaxValue);
}
}
}
+5
View File
@@ -0,0 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<Relationships xmlns="http://schemas.openxmlformats.org/package/2006/relationships">
<Relationship Type="http://schemas.microsoft.com/packaging/2010/07/manifest" Target="/MongoDbGenericRepository.nuspec" Id="Rd7ba7aa97a7d4fb2" />
<Relationship Type="http://schemas.openxmlformats.org/package/2006/relationships/metadata/core-properties" Target="/package/services/metadata/core-properties/e5080d3094a649a39d247315f4dcd1ba.psmdcp" Id="Rcfffb2818c774b93" />
</Relationships>
Binary file not shown.
Binary file not shown.
File diff suppressed because it is too large Load Diff
@@ -1,7 +1,7 @@
{ {
"runtimeTarget": { "runtimeTarget": {
"name": ".NETStandard,Version=v1.5/", "name": ".NETStandard,Version=v1.5/",
"signature": "a194bb722afb9e376ea09b07a4832ba79352dd6a" "signature": "795a70ab1bbc13177859af16f1887befe3221c54"
}, },
"compilationOptions": {}, "compilationOptions": {},
"targets": { "targets": {
@@ -9,13 +9,36 @@
".NETStandard,Version=v1.5/": { ".NETStandard,Version=v1.5/": {
"MongoDbGenericRepository/1.0.0": { "MongoDbGenericRepository/1.0.0": {
"dependencies": { "dependencies": {
"MongoDB.Driver": "2.4.4", "MongoDB.Driver": "2.5.0",
"NETStandard.Library": "1.6.1" "NETStandard.Library": "1.6.1"
}, },
"runtime": { "runtime": {
"MongoDbGenericRepository.dll": {} "MongoDbGenericRepository.dll": {}
} }
}, },
"DnsClient/1.0.7": {
"dependencies": {
"Microsoft.Win32.Primitives": "4.3.0",
"NETStandard.Library": "1.6.1",
"System.Buffers": "4.3.0",
"System.Collections": "4.3.0",
"System.Collections.Concurrent": "4.3.0",
"System.Globalization.Extensions": "4.3.0",
"System.IO.FileSystem": "4.3.0",
"System.Linq": "4.3.0",
"System.Net.NameResolution": "4.3.0",
"System.Net.NetworkInformation": "4.3.0",
"System.Net.Sockets": "4.3.0",
"System.Runtime.Extensions": "4.3.0",
"System.Runtime.InteropServices": "4.3.0",
"System.Runtime.InteropServices.RuntimeInformation": "4.3.0",
"System.Text.Encoding": "4.3.0",
"System.Threading": "4.3.0"
},
"runtime": {
"lib/netstandard1.3/DnsClient.dll": {}
}
},
"Microsoft.NETCore.Platforms/1.1.0": {}, "Microsoft.NETCore.Platforms/1.1.0": {},
"Microsoft.NETCore.Targets/1.1.0": {}, "Microsoft.NETCore.Targets/1.1.0": {},
"Microsoft.Win32.Primitives/4.3.0": { "Microsoft.Win32.Primitives/4.3.0": {
@@ -37,7 +60,7 @@
"System.Runtime.InteropServices": "4.3.0" "System.Runtime.InteropServices": "4.3.0"
} }
}, },
"MongoDB.Bson/2.4.4": { "MongoDB.Bson/2.5.0": {
"dependencies": { "dependencies": {
"NETStandard.Library": "1.6.1", "NETStandard.Library": "1.6.1",
"System.Collections.NonGeneric": "4.0.1", "System.Collections.NonGeneric": "4.0.1",
@@ -49,24 +72,26 @@
"lib/netstandard1.5/MongoDB.Bson.dll": {} "lib/netstandard1.5/MongoDB.Bson.dll": {}
} }
}, },
"MongoDB.Driver/2.4.4": { "MongoDB.Driver/2.5.0": {
"dependencies": { "dependencies": {
"MongoDB.Bson": "2.4.4", "MongoDB.Bson": "2.5.0",
"MongoDB.Driver.Core": "2.4.4", "MongoDB.Driver.Core": "2.5.0",
"NETStandard.Library": "1.6.1", "NETStandard.Library": "1.6.1",
"System.ComponentModel.TypeConverter": "4.1.0",
"System.Linq.Queryable": "4.0.1" "System.Linq.Queryable": "4.0.1"
}, },
"runtime": { "runtime": {
"lib/netstandard1.5/MongoDB.Driver.dll": {} "lib/netstandard1.5/MongoDB.Driver.dll": {}
} }
}, },
"MongoDB.Driver.Core/2.4.4": { "MongoDB.Driver.Core/2.5.0": {
"dependencies": { "dependencies": {
"MongoDB.Bson": "2.4.4", "DnsClient": "1.0.7",
"MongoDB.Bson": "2.5.0",
"NETStandard.Library": "1.6.1", "NETStandard.Library": "1.6.1",
"System.Collections.Specialized": "4.0.1", "System.Collections.Specialized": "4.0.1",
"System.Diagnostics.TraceSource": "4.0.0", "System.Diagnostics.TraceSource": "4.0.0",
"System.Net.NameResolution": "4.0.0", "System.Net.NameResolution": "4.3.0",
"System.Net.Security": "4.0.0", "System.Net.Security": "4.0.0",
"System.Security.SecureString": "4.0.0" "System.Security.SecureString": "4.0.0"
}, },
@@ -216,7 +241,7 @@
"dependencies": { "dependencies": {
"System.Collections.NonGeneric": "4.0.1", "System.Collections.NonGeneric": "4.0.1",
"System.Globalization": "4.3.0", "System.Globalization": "4.3.0",
"System.Globalization.Extensions": "4.0.1", "System.Globalization.Extensions": "4.3.0",
"System.Resources.ResourceManager": "4.3.0", "System.Resources.ResourceManager": "4.3.0",
"System.Runtime": "4.3.0", "System.Runtime": "4.3.0",
"System.Runtime.Extensions": "4.3.0", "System.Runtime.Extensions": "4.3.0",
@@ -226,6 +251,46 @@
"lib/netstandard1.3/System.Collections.Specialized.dll": {} "lib/netstandard1.3/System.Collections.Specialized.dll": {}
} }
}, },
"System.ComponentModel/4.0.1": {
"dependencies": {
"System.Runtime": "4.3.0"
},
"runtime": {
"lib/netstandard1.3/System.ComponentModel.dll": {}
}
},
"System.ComponentModel.Primitives/4.1.0": {
"dependencies": {
"System.ComponentModel": "4.0.1",
"System.Resources.ResourceManager": "4.3.0",
"System.Runtime": "4.3.0"
},
"runtime": {
"lib/netstandard1.0/System.ComponentModel.Primitives.dll": {}
}
},
"System.ComponentModel.TypeConverter/4.1.0": {
"dependencies": {
"System.Collections": "4.3.0",
"System.Collections.NonGeneric": "4.0.1",
"System.Collections.Specialized": "4.0.1",
"System.ComponentModel": "4.0.1",
"System.ComponentModel.Primitives": "4.1.0",
"System.Globalization": "4.3.0",
"System.Linq": "4.3.0",
"System.Reflection": "4.3.0",
"System.Reflection.Extensions": "4.3.0",
"System.Reflection.Primitives": "4.3.0",
"System.Reflection.TypeExtensions": "4.1.0",
"System.Resources.ResourceManager": "4.3.0",
"System.Runtime": "4.3.0",
"System.Runtime.Extensions": "4.3.0",
"System.Threading": "4.3.0"
},
"runtime": {
"lib/netstandard1.5/System.ComponentModel.TypeConverter.dll": {}
}
},
"System.Console/4.3.0": { "System.Console/4.3.0": {
"dependencies": { "dependencies": {
"Microsoft.NETCore.Platforms": "1.1.0", "Microsoft.NETCore.Platforms": "1.1.0",
@@ -274,8 +339,8 @@
"System.Text.Encoding.Extensions": "4.3.0", "System.Text.Encoding.Extensions": "4.3.0",
"System.Threading": "4.3.0", "System.Threading": "4.3.0",
"System.Threading.Tasks": "4.3.0", "System.Threading.Tasks": "4.3.0",
"System.Threading.Thread": "4.0.0", "System.Threading.Thread": "4.3.0",
"System.Threading.ThreadPool": "4.0.10", "System.Threading.ThreadPool": "4.3.0",
"runtime.native.System": "4.3.0" "runtime.native.System": "4.3.0"
} }
}, },
@@ -343,7 +408,7 @@
"System.Runtime": "4.3.0" "System.Runtime": "4.3.0"
} }
}, },
"System.Globalization.Extensions/4.0.1": { "System.Globalization.Extensions/4.3.0": {
"dependencies": { "dependencies": {
"Microsoft.NETCore.Platforms": "1.1.0", "Microsoft.NETCore.Platforms": "1.1.0",
"System.Globalization": "4.3.0", "System.Globalization": "4.3.0",
@@ -467,7 +532,7 @@
"System.Threading.Tasks": "4.3.0" "System.Threading.Tasks": "4.3.0"
} }
}, },
"System.Net.NameResolution/4.0.0": { "System.Net.NameResolution/4.3.0": {
"dependencies": { "dependencies": {
"Microsoft.NETCore.Platforms": "1.1.0", "Microsoft.NETCore.Platforms": "1.1.0",
"System.Collections": "4.3.0", "System.Collections": "4.3.0",
@@ -479,12 +544,39 @@
"System.Runtime.Extensions": "4.3.0", "System.Runtime.Extensions": "4.3.0",
"System.Runtime.Handles": "4.3.0", "System.Runtime.Handles": "4.3.0",
"System.Runtime.InteropServices": "4.3.0", "System.Runtime.InteropServices": "4.3.0",
"System.Security.Principal.Windows": "4.0.0", "System.Security.Principal.Windows": "4.3.0",
"System.Threading": "4.3.0", "System.Threading": "4.3.0",
"System.Threading.Tasks": "4.3.0", "System.Threading.Tasks": "4.3.0",
"runtime.native.System": "4.3.0" "runtime.native.System": "4.3.0"
} }
}, },
"System.Net.NetworkInformation/4.3.0": {
"dependencies": {
"Microsoft.NETCore.Platforms": "1.1.0",
"Microsoft.Win32.Primitives": "4.3.0",
"System.Collections": "4.3.0",
"System.Diagnostics.Tracing": "4.3.0",
"System.Globalization": "4.3.0",
"System.IO": "4.3.0",
"System.IO.FileSystem": "4.3.0",
"System.IO.FileSystem.Primitives": "4.3.0",
"System.Linq": "4.3.0",
"System.Net.Primitives": "4.3.0",
"System.Net.Sockets": "4.3.0",
"System.Resources.ResourceManager": "4.3.0",
"System.Runtime": "4.3.0",
"System.Runtime.Extensions": "4.3.0",
"System.Runtime.Handles": "4.3.0",
"System.Runtime.InteropServices": "4.3.0",
"System.Security.Principal.Windows": "4.3.0",
"System.Threading": "4.3.0",
"System.Threading.Overlapped": "4.3.0",
"System.Threading.Tasks": "4.3.0",
"System.Threading.Thread": "4.3.0",
"System.Threading.ThreadPool": "4.3.0",
"runtime.native.System": "4.3.0"
}
},
"System.Net.Primitives/4.3.0": { "System.Net.Primitives/4.3.0": {
"dependencies": { "dependencies": {
"Microsoft.NETCore.Platforms": "1.1.0", "Microsoft.NETCore.Platforms": "1.1.0",
@@ -508,14 +600,14 @@
"System.Runtime.Extensions": "4.3.0", "System.Runtime.Extensions": "4.3.0",
"System.Runtime.Handles": "4.3.0", "System.Runtime.Handles": "4.3.0",
"System.Runtime.InteropServices": "4.3.0", "System.Runtime.InteropServices": "4.3.0",
"System.Security.Claims": "4.0.1", "System.Security.Claims": "4.3.0",
"System.Security.Cryptography.Primitives": "4.3.0", "System.Security.Cryptography.Primitives": "4.3.0",
"System.Security.Cryptography.X509Certificates": "4.3.0", "System.Security.Cryptography.X509Certificates": "4.3.0",
"System.Security.Principal": "4.0.1", "System.Security.Principal": "4.3.0",
"System.Security.Principal.Windows": "4.0.0", "System.Security.Principal.Windows": "4.3.0",
"System.Threading": "4.3.0", "System.Threading": "4.3.0",
"System.Threading.Tasks": "4.3.0", "System.Threading.Tasks": "4.3.0",
"System.Threading.ThreadPool": "4.0.10" "System.Threading.ThreadPool": "4.3.0"
} }
}, },
"System.Net.Sockets/4.3.0": { "System.Net.Sockets/4.3.0": {
@@ -670,7 +762,7 @@
"lib/netstandard1.3/System.Runtime.Numerics.dll": {} "lib/netstandard1.3/System.Runtime.Numerics.dll": {}
} }
}, },
"System.Security.Claims/4.0.1": { "System.Security.Claims/4.3.0": {
"dependencies": { "dependencies": {
"System.Collections": "4.3.0", "System.Collections": "4.3.0",
"System.Globalization": "4.3.0", "System.Globalization": "4.3.0",
@@ -678,7 +770,7 @@
"System.Resources.ResourceManager": "4.3.0", "System.Resources.ResourceManager": "4.3.0",
"System.Runtime": "4.3.0", "System.Runtime": "4.3.0",
"System.Runtime.Extensions": "4.3.0", "System.Runtime.Extensions": "4.3.0",
"System.Security.Principal": "4.0.1" "System.Security.Principal": "4.3.0"
}, },
"runtime": { "runtime": {
"lib/netstandard1.3/System.Security.Claims.dll": {} "lib/netstandard1.3/System.Security.Claims.dll": {}
@@ -729,7 +821,7 @@
"System.Security.Cryptography.Encoding": "4.3.0" "System.Security.Cryptography.Encoding": "4.3.0"
} }
}, },
"System.Security.Principal/4.0.1": { "System.Security.Principal/4.3.0": {
"dependencies": { "dependencies": {
"System.Runtime": "4.3.0" "System.Runtime": "4.3.0"
}, },
@@ -737,7 +829,7 @@
"lib/netstandard1.0/System.Security.Principal.dll": {} "lib/netstandard1.0/System.Security.Principal.dll": {}
} }
}, },
"System.Security.Principal.Windows/4.0.0": { "System.Security.Principal.Windows/4.3.0": {
"dependencies": { "dependencies": {
"Microsoft.NETCore.Platforms": "1.1.0", "Microsoft.NETCore.Platforms": "1.1.0",
"Microsoft.Win32.Primitives": "4.3.0", "Microsoft.Win32.Primitives": "4.3.0",
@@ -749,8 +841,8 @@
"System.Runtime.Extensions": "4.3.0", "System.Runtime.Extensions": "4.3.0",
"System.Runtime.Handles": "4.3.0", "System.Runtime.Handles": "4.3.0",
"System.Runtime.InteropServices": "4.3.0", "System.Runtime.InteropServices": "4.3.0",
"System.Security.Claims": "4.0.1", "System.Security.Claims": "4.3.0",
"System.Security.Principal": "4.0.1", "System.Security.Principal": "4.3.0",
"System.Text.Encoding": "4.3.0", "System.Text.Encoding": "4.3.0",
"System.Threading": "4.3.0" "System.Threading": "4.3.0"
} }
@@ -796,6 +888,14 @@
"lib/netstandard1.3/System.Threading.dll": {} "lib/netstandard1.3/System.Threading.dll": {}
} }
}, },
"System.Threading.Overlapped/4.3.0": {
"dependencies": {
"Microsoft.NETCore.Platforms": "1.1.0",
"System.Resources.ResourceManager": "4.3.0",
"System.Runtime": "4.3.0",
"System.Runtime.Handles": "4.3.0"
}
},
"System.Threading.Tasks/4.3.0": { "System.Threading.Tasks/4.3.0": {
"dependencies": { "dependencies": {
"Microsoft.NETCore.Platforms": "1.1.0", "Microsoft.NETCore.Platforms": "1.1.0",
@@ -813,7 +913,7 @@
"lib/netstandard1.0/System.Threading.Tasks.Extensions.dll": {} "lib/netstandard1.0/System.Threading.Tasks.Extensions.dll": {}
} }
}, },
"System.Threading.Thread/4.0.0": { "System.Threading.Thread/4.3.0": {
"dependencies": { "dependencies": {
"System.Runtime": "4.3.0" "System.Runtime": "4.3.0"
}, },
@@ -821,7 +921,7 @@
"lib/netstandard1.3/System.Threading.Thread.dll": {} "lib/netstandard1.3/System.Threading.Thread.dll": {}
} }
}, },
"System.Threading.ThreadPool/4.0.10": { "System.Threading.ThreadPool/4.3.0": {
"dependencies": { "dependencies": {
"System.Runtime": "4.3.0", "System.Runtime": "4.3.0",
"System.Runtime.Handles": "4.3.0" "System.Runtime.Handles": "4.3.0"
@@ -886,6 +986,13 @@
"serviceable": false, "serviceable": false,
"sha512": "" "sha512": ""
}, },
"DnsClient/1.0.7": {
"type": "package",
"serviceable": true,
"sha512": "sha512-f3k5ufhUSL658fy/ac1mReqRIr0jGMyOJFvBqJ+7cASq01NIysYbrrRDjboYKAGrd0Y2mc1A749uQvT8vAA91A==",
"path": "dnsclient/1.0.7",
"hashPath": "dnsclient.1.0.7.nupkg.sha512"
},
"Microsoft.NETCore.Platforms/1.1.0": { "Microsoft.NETCore.Platforms/1.1.0": {
"type": "package", "type": "package",
"serviceable": true, "serviceable": true,
@@ -914,26 +1021,26 @@
"path": "microsoft.win32.registry/4.0.0", "path": "microsoft.win32.registry/4.0.0",
"hashPath": "microsoft.win32.registry.4.0.0.nupkg.sha512" "hashPath": "microsoft.win32.registry.4.0.0.nupkg.sha512"
}, },
"MongoDB.Bson/2.4.4": { "MongoDB.Bson/2.5.0": {
"type": "package", "type": "package",
"serviceable": true, "serviceable": true,
"sha512": "sha512-BavFx+rmR5k+dx14tC23KTyjCPkASvTQ1WxzLYHt2w3Mkqel5lJV6+gWzWV3DX9hnTewCC09OKqNqckiJl4sIw==", "sha512": "sha512-b7zQAUdSdfJ4kmGzAA+hv89N2Q6jm1td9WfTimgp8xWAsN4qbtIjA/JkAY1HA0Z8xfXQE3EmdUcDEwT8bkXfXg==",
"path": "mongodb.bson/2.4.4", "path": "mongodb.bson/2.5.0",
"hashPath": "mongodb.bson.2.4.4.nupkg.sha512" "hashPath": "mongodb.bson.2.5.0.nupkg.sha512"
}, },
"MongoDB.Driver/2.4.4": { "MongoDB.Driver/2.5.0": {
"type": "package", "type": "package",
"serviceable": true, "serviceable": true,
"sha512": "sha512-sG+4H7732fG3XGCXWsxwuUQBvnbVO/bzzxBVZHtHa5R2UDsRXR7BfQxAS/d9Qk8FlNDHOjTjz+GzWTgzjgopQw==", "sha512": "sha512-VbHVV8Xdl3PcPU3XxdOUE/yc4BnPokg7k1XHU/3fEM/UdfCy0Ie0eXVE+U2HJXVcM3TQuuyVn+B1La2YY7X8dA==",
"path": "mongodb.driver/2.4.4", "path": "mongodb.driver/2.5.0",
"hashPath": "mongodb.driver.2.4.4.nupkg.sha512" "hashPath": "mongodb.driver.2.5.0.nupkg.sha512"
}, },
"MongoDB.Driver.Core/2.4.4": { "MongoDB.Driver.Core/2.5.0": {
"type": "package", "type": "package",
"serviceable": true, "serviceable": true,
"sha512": "sha512-fVjXuQE5Qe2P38xz9wz5V0QhT54+ZT78/JUKMMbIXOKYVFgkzEOE7UU6ZsbC/AbR4lwGIpRQZoiv7wW3rJb3xQ==", "sha512": "sha512-/JYwBTEoWZDHiSePk0AF775c0YkSGSsHTA2+hWt9/UOCkYV/QOFujAWDdpFzBMCDpmQewbLRR1knYj76YOxffA==",
"path": "mongodb.driver.core/2.4.4", "path": "mongodb.driver.core/2.5.0",
"hashPath": "mongodb.driver.core.2.4.4.nupkg.sha512" "hashPath": "mongodb.driver.core.2.5.0.nupkg.sha512"
}, },
"NETStandard.Library/1.6.1": { "NETStandard.Library/1.6.1": {
"type": "package", "type": "package",
@@ -1075,6 +1182,27 @@
"path": "system.collections.specialized/4.0.1", "path": "system.collections.specialized/4.0.1",
"hashPath": "system.collections.specialized.4.0.1.nupkg.sha512" "hashPath": "system.collections.specialized.4.0.1.nupkg.sha512"
}, },
"System.ComponentModel/4.0.1": {
"type": "package",
"serviceable": true,
"sha512": "sha512-oBZFnm7seFiVfugsIyOvQCWobNZs7FzqDV/B7tx20Ep/l3UUFCPDkdTnCNaJZTU27zjeODmy2C/cP60u3D4c9w==",
"path": "system.componentmodel/4.0.1",
"hashPath": "system.componentmodel.4.0.1.nupkg.sha512"
},
"System.ComponentModel.Primitives/4.1.0": {
"type": "package",
"serviceable": true,
"sha512": "sha512-sc/7eVCdxPrp3ljpgTKVaQGUXiW05phNWvtv/m2kocXqrUQvTVWKou1Edas2aDjTThLPZOxPYIGNb/HN0QjURg==",
"path": "system.componentmodel.primitives/4.1.0",
"hashPath": "system.componentmodel.primitives.4.1.0.nupkg.sha512"
},
"System.ComponentModel.TypeConverter/4.1.0": {
"type": "package",
"serviceable": true,
"sha512": "sha512-MnDAlaeJZy9pdB5ZdOlwdxfpI+LJQ6e0hmH7d2+y2LkiD8DRJynyDYl4Xxf3fWFm7SbEwBZh4elcfzONQLOoQw==",
"path": "system.componentmodel.typeconverter/4.1.0",
"hashPath": "system.componentmodel.typeconverter.4.1.0.nupkg.sha512"
},
"System.Console/4.3.0": { "System.Console/4.3.0": {
"type": "package", "type": "package",
"serviceable": true, "serviceable": true,
@@ -1145,12 +1273,12 @@
"path": "system.globalization.calendars/4.3.0", "path": "system.globalization.calendars/4.3.0",
"hashPath": "system.globalization.calendars.4.3.0.nupkg.sha512" "hashPath": "system.globalization.calendars.4.3.0.nupkg.sha512"
}, },
"System.Globalization.Extensions/4.0.1": { "System.Globalization.Extensions/4.3.0": {
"type": "package", "type": "package",
"serviceable": true, "serviceable": true,
"sha512": "sha512-KKo23iKeOaIg61SSXwjANN7QYDr/3op3OWGGzDzz7mypx0Za0fZSeG0l6cco8Ntp8YMYkIQcAqlk8yhm5/Uhcg==", "sha512": "sha512-FhKmdR6MPG+pxow6wGtNAWdZh7noIOpdD5TwQ3CprzgIE1bBBoim0vbR1+AWsWjQmU7zXHgQo4TWSP6lCeiWcQ==",
"path": "system.globalization.extensions/4.0.1", "path": "system.globalization.extensions/4.3.0",
"hashPath": "system.globalization.extensions.4.0.1.nupkg.sha512" "hashPath": "system.globalization.extensions.4.3.0.nupkg.sha512"
}, },
"System.IO/4.3.0": { "System.IO/4.3.0": {
"type": "package", "type": "package",
@@ -1215,12 +1343,19 @@
"path": "system.net.http/4.3.0", "path": "system.net.http/4.3.0",
"hashPath": "system.net.http.4.3.0.nupkg.sha512" "hashPath": "system.net.http.4.3.0.nupkg.sha512"
}, },
"System.Net.NameResolution/4.0.0": { "System.Net.NameResolution/4.3.0": {
"type": "package", "type": "package",
"serviceable": true, "serviceable": true,
"sha512": "sha512-JdqRdM1Qym3YehqdKIi5LHrpypP4JMfxKQSNCJ2z4WawkG0il+N3XfNeJOxll2XrTnG7WgYYPoeiu/KOwg0DQw==", "sha512": "sha512-AFYl08R7MrsrEjqpQWTZWBadqXyTzNDaWpMqyxhb0d6sGhV6xMDKueuBXlLL30gz+DIRY6MpdgnHWlCh5wmq9w==",
"path": "system.net.nameresolution/4.0.0", "path": "system.net.nameresolution/4.3.0",
"hashPath": "system.net.nameresolution.4.0.0.nupkg.sha512" "hashPath": "system.net.nameresolution.4.3.0.nupkg.sha512"
},
"System.Net.NetworkInformation/4.3.0": {
"type": "package",
"serviceable": true,
"sha512": "sha512-zNVmWVry0pAu7lcrRBhwwU96WUdbsrGL3azyzsbXmVNptae1+Za+UgOe9Z6s8iaWhPn7/l4wQqhC56HZWq7tkg==",
"path": "system.net.networkinformation/4.3.0",
"hashPath": "system.net.networkinformation.4.3.0.nupkg.sha512"
}, },
"System.Net.Primitives/4.3.0": { "System.Net.Primitives/4.3.0": {
"type": "package", "type": "package",
@@ -1348,12 +1483,12 @@
"path": "system.runtime.numerics/4.3.0", "path": "system.runtime.numerics/4.3.0",
"hashPath": "system.runtime.numerics.4.3.0.nupkg.sha512" "hashPath": "system.runtime.numerics.4.3.0.nupkg.sha512"
}, },
"System.Security.Claims/4.0.1": { "System.Security.Claims/4.3.0": {
"type": "package", "type": "package",
"serviceable": true, "serviceable": true,
"sha512": "sha512-4Jlp0OgJLS/Voj1kyFP6MJlIYp3crgfH8kNQk2p7+4JYfc1aAmh9PZyAMMbDhuoolGNtux9HqSOazsioRiDvCw==", "sha512": "sha512-P/+BR/2lnc4PNDHt/TPBAWHVMLMRHsyYZbU1NphW4HIWzCggz8mJbTQQ3MKljFE7LS3WagmVFuBgoLcFzYXlkA==",
"path": "system.security.claims/4.0.1", "path": "system.security.claims/4.3.0",
"hashPath": "system.security.claims.4.0.1.nupkg.sha512" "hashPath": "system.security.claims.4.3.0.nupkg.sha512"
}, },
"System.Security.Cryptography.Algorithms/4.3.0": { "System.Security.Cryptography.Algorithms/4.3.0": {
"type": "package", "type": "package",
@@ -1383,19 +1518,19 @@
"path": "system.security.cryptography.x509certificates/4.3.0", "path": "system.security.cryptography.x509certificates/4.3.0",
"hashPath": "system.security.cryptography.x509certificates.4.3.0.nupkg.sha512" "hashPath": "system.security.cryptography.x509certificates.4.3.0.nupkg.sha512"
}, },
"System.Security.Principal/4.0.1": { "System.Security.Principal/4.3.0": {
"type": "package", "type": "package",
"serviceable": true, "serviceable": true,
"sha512": "sha512-On+SKhXY5rzxh/S8wlH1Rm0ogBlu7zyHNxeNBiXauNrhHRXAe9EuX8Yl5IOzLPGU5Z4kLWHMvORDOCG8iu9hww==", "sha512": "sha512-I1tkfQlAoMM2URscUtpcRo/hX0jinXx6a/KUtEQoz3owaYwl3qwsO8cbzYVVnjxrzxjHo3nJC+62uolgeGIS9A==",
"path": "system.security.principal/4.0.1", "path": "system.security.principal/4.3.0",
"hashPath": "system.security.principal.4.0.1.nupkg.sha512" "hashPath": "system.security.principal.4.3.0.nupkg.sha512"
}, },
"System.Security.Principal.Windows/4.0.0": { "System.Security.Principal.Windows/4.3.0": {
"type": "package", "type": "package",
"serviceable": true, "serviceable": true,
"sha512": "sha512-iFx15AF3RMEPZn3COh8+Bb2Thv2zsmLd93RchS1b8Mj5SNYeGqbYNCSn5AES1+gq56p4ujGZPrl0xN7ngkXOHg==", "sha512": "sha512-HVL1rvqYtnRCxFsYag/2le/ZfKLK4yMw79+s6FmKXbSCNN0JeAhrYxnRAHFoWRa0dEojsDcbBSpH3l22QxAVyw==",
"path": "system.security.principal.windows/4.0.0", "path": "system.security.principal.windows/4.3.0",
"hashPath": "system.security.principal.windows.4.0.0.nupkg.sha512" "hashPath": "system.security.principal.windows.4.3.0.nupkg.sha512"
}, },
"System.Security.SecureString/4.0.0": { "System.Security.SecureString/4.0.0": {
"type": "package", "type": "package",
@@ -1432,6 +1567,13 @@
"path": "system.threading/4.3.0", "path": "system.threading/4.3.0",
"hashPath": "system.threading.4.3.0.nupkg.sha512" "hashPath": "system.threading.4.3.0.nupkg.sha512"
}, },
"System.Threading.Overlapped/4.3.0": {
"type": "package",
"serviceable": true,
"sha512": "sha512-m3HQ2dPiX/DSTpf+yJt8B0c+SRvzfqAJKx+QDWi+VLhz8svLT23MVjEOHPF/KiSLeArKU/iHescrbLd3yVgyNg==",
"path": "system.threading.overlapped/4.3.0",
"hashPath": "system.threading.overlapped.4.3.0.nupkg.sha512"
},
"System.Threading.Tasks/4.3.0": { "System.Threading.Tasks/4.3.0": {
"type": "package", "type": "package",
"serviceable": true, "serviceable": true,
@@ -1446,19 +1588,19 @@
"path": "system.threading.tasks.extensions/4.3.0", "path": "system.threading.tasks.extensions/4.3.0",
"hashPath": "system.threading.tasks.extensions.4.3.0.nupkg.sha512" "hashPath": "system.threading.tasks.extensions.4.3.0.nupkg.sha512"
}, },
"System.Threading.Thread/4.0.0": { "System.Threading.Thread/4.3.0": {
"type": "package", "type": "package",
"serviceable": true, "serviceable": true,
"sha512": "sha512-gIdJqDXlOr5W9zeqFErLw3dsOsiShSCYtF9SEHitACycmvNvY8odf9kiKvp6V7aibc8C4HzzNBkWXjyfn7plbQ==", "sha512": "sha512-OHmbT+Zz065NKII/ZHcH9XO1dEuLGI1L2k7uYss+9C1jLxTC9kTZZuzUOyXHayRk+dft9CiDf3I/QZ0t8JKyBQ==",
"path": "system.threading.thread/4.0.0", "path": "system.threading.thread/4.3.0",
"hashPath": "system.threading.thread.4.0.0.nupkg.sha512" "hashPath": "system.threading.thread.4.3.0.nupkg.sha512"
}, },
"System.Threading.ThreadPool/4.0.10": { "System.Threading.ThreadPool/4.3.0": {
"type": "package", "type": "package",
"serviceable": true, "serviceable": true,
"sha512": "sha512-IMXgB5Vf/5Qw1kpoVgJMOvUO1l32aC+qC3OaIZjWJOjvcxuxNWOK2ZTWWYXfij22NHxT2j1yWX5vlAeQWld9vA==", "sha512": "sha512-k/+g4b7vjdd4aix83sTgC9VG6oXYKAktSfNIJUNGxPEj7ryEOfzHHhfnmsZvjxawwcD9HyWXKCXmPjX8U4zeSw==",
"path": "system.threading.threadpool/4.0.10", "path": "system.threading.threadpool/4.3.0",
"hashPath": "system.threading.threadpool.4.0.10.nupkg.sha512" "hashPath": "system.threading.threadpool.4.3.0.nupkg.sha512"
}, },
"System.Threading.Timer/4.3.0": { "System.Threading.Timer/4.3.0": {
"type": "package", "type": "package",
File diff suppressed because it is too large Load Diff
File diff suppressed because it is too large Load Diff
File diff suppressed because it is too large Load Diff
+32 -3
View File
@@ -4,6 +4,8 @@ An example of generic repository implementation using the MongoDB C# Sharp 2.0 d
Now available as a nuget package: Now available as a nuget package:
https://www.nuget.org/packages/MongoDbGenericRepository/ https://www.nuget.org/packages/MongoDbGenericRepository/
Covered by 200+ integration tests and counting.
# Usage examples # Usage examples
This repository is meant to be inherited from. This repository is meant to be inherited from.
@@ -44,8 +46,16 @@ The repository can be instantiated like so:
ITestRepository testRepository = new TestRepository(connectionString, "MongoDbTests"); ITestRepository testRepository = new TestRepository(connectionString, "MongoDbTests");
``` ```
If you prefer to reuse the same MongoDb database across your application, you can use the `MongoDatabase` from the MongoDb driver implementing the `IMongoDatabase` interface:
```csharp
var client = new MongoClient(connectionString);
var mongoDbDatabase = Client.GetDatabase(databaseName);
ITestRepository testRepository = new TestRepository(mongoDbDatabase);
```
## Adding documents ## Adding documents
To add a document, its class must inherit from the `Document` class or implement the `IDocument` interface: To add a document, its class must inherit from the `Document` class, implement the `IDocument` or `IDocument<TKey>` interface:
```csharp ```csharp
public class MyDocument : Document public class MyDocument : Document
@@ -58,7 +68,7 @@ To add a document, its class must inherit from the `Document` class or implement
} }
``` ```
The `IDocument` interface can be seen below: The `IDocument` and `IDocument<TKey>` interfaces can be seen below:
```csharp ```csharp
/// <summary> /// <summary>
@@ -70,7 +80,26 @@ The `IDocument` interface can be seen below:
Guid Id { get; set; } Guid Id { get; set; }
int Version { get; set; } int Version { get; set; }
} }
/// <summary>
/// This class represents a basic document that can be stored in MongoDb.
/// Your document must implement this class in order for the MongoDbRepository to handle them.
/// </summary>
public interface IDocument<TKey> where TKey : IEquatable<TKey>
{
/// <summary>
/// The Primary Key, which must be decorated with the [BsonId] attribute
/// if you want the MongoDb C# driver to consider it to be the document ID.
/// </summary>
[BsonId]
TKey Id { get; set; }
/// <summary>
/// A version number, to indicate the version of the schema.
/// </summary>
int Version { get; set; }
}
``` ```
## Partitioned collections ## Partitioned collections
This repository also allows you to partition your document across multiple collections, this can be useful if you are running a SaaS application and want to keep good performance. This repository also allows you to partition your document across multiple collections, this can be useful if you are running a SaaS application and want to keep good performance.
@@ -104,7 +133,7 @@ Please refer to the IntegrationTests (NET45) and CoreIntegrationTests (netstanda
## Donations ## Donations
Feeling like my work is worth a coffee? Feeling like my work is worth a coffee?
Donations are welcome and will go towards further development of this project as well as other MongoDb related projects. Use the wallet address below to donate. Donations are welcome and will go towards further development of this project as well as other MongoDb related projects. Use the wallet address below to donate.
BTC Donations: 1Qc5ZpNA7g66KEEMcz7MXxwNyyoRyKJJZ BTC Donations: 1FDMWqSK8SHXDGKKp7gyZc4rknynWJ7qbj
*Thank you for your support and generosity!* *Thank you for your support and generosity!*