Compare commits

...

21 Commits

Author SHA1 Message Date
Alexandre SPIESER 9cb35c5881 remove packaged dependencies 2020-02-05 21:37:44 +00:00
Alexandre SPIESER c5390214eb updated driver and test suite 2019-11-18 22:38:34 +00:00
Alexandre SPIESER ac1fd709a6 Merge pull request #26 from LeEmo86/upgrade-mongodbdriver
Updated the mongodb driver
2019-11-18 21:52:50 +00:00
Liam Flanagan f6b0aa274b Updated the mongodb driver 2019-11-18 19:20:57 +00:00
Alexandre SPIESER 7a82a281fb Merge pull request #23 from DanielGasson/master
Allow initialisation of MongoDbContext with connection string only
2019-06-18 21:50:50 +01:00
Daniel Gasson dca01b184c Allow initialisation of MongoDbContext with connection string only 2019-06-18 11:33:26 +01:00
Alexandre SPIESER b1cda2ac50 adding client session to mongodb updater methods 2019-05-18 19:49:44 +01:00
Alexandre SPIESER 8d6b796e7f Merge pull request #22 from alexandre-spieser/alex/refactorForKeyTypeRepo
1.4.0 release
2019-04-18 08:22:35 +01:00
Alexandre SPIESER 1a7763a312 1.4.0 release 2019-04-18 08:21:18 +01:00
Alexandre SPIESER 77cc85574c Update BaseMongoRepository.TKey.Update.cs 2019-04-17 19:08:13 +01:00
Alexandre SPIESER 846bb16730 Update BaseMongoRepository.TKey.Index.cs 2019-04-17 19:05:17 +01:00
Alexandre SPIESER 5e4cbfa1b3 Update BaseMongoRepository.TKey.Delete.cs 2019-04-17 19:04:38 +01:00
Alexandre SPIESER 804dc18c4f Update BaseMongoRepository.TKey.Create.cs 2019-04-17 19:03:59 +01:00
Alexandre SPIESER 182ee0a335 Update BaseMongoRepository.Update.cs 2019-04-17 19:02:57 +01:00
Alexandre SPIESER bd662d25d6 Update BaseMongoRepository.Index.cs 2019-04-17 19:00:33 +01:00
Alexandre SPIESER 6c8d4bdafb Update BaseMongoRepository.Delete.cs 2019-04-17 18:59:27 +01:00
Alexandre SPIESER 4d94a1b436 Update BaseMongoRepository.Create.cs 2019-04-17 18:58:47 +01:00
Alexandre SPIESER d91a644b4a Update README.md 2019-04-15 23:58:44 +01:00
Alexandre SPIESER 9d1950e9c7 Update README.md 2019-04-15 23:58:13 +01:00
Alexandre SPIESER 67d0a4c8a3 Update README.md 2019-04-15 00:48:19 +01:00
Alexandre SPIESER 1826668cea Update README.md 2019-04-15 00:47:06 +01:00
38 changed files with 9326 additions and 3347 deletions
@@ -1,4 +1,4 @@
<Project Sdk="Microsoft.NET.Sdk">
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>netcoreapp2.0</TargetFramework>
@@ -7,11 +7,13 @@
<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.Identity" Version="2.1.2" />
<PackageReference Include="Microsoft.Extensions.Identity.Stores" Version="2.1.2" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="15.8.0" />
<PackageReference Include="MongoDB.Driver" Version="2.7.0" />
<PackageReference Include="MongoDbGenericRepository" Version="1.3.9" />
<PackageReference Include="xunit" Version="2.4.0" />
<PackageReference Include="xunit.runner.console" Version="2.4.0" />
<PackageReference Include="MongoDB.Driver" Version="2.9.3" />
<PackageReference Include="MongoDbGenericRepository" Version="1.4.3" />
<PackageReference Include="xunit" Version="2.4.1" />
<PackageReference Include="xunit.runner.console" Version="2.4.1">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets>
</PackageReference>
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.0" />
<DotNetCliToolReference Include="dotnet-xunit" Version="2.3.0-beta4-build3742" />
</ItemGroup>
-4
View File
@@ -13,10 +13,6 @@
<assemblyIdentity name="System.Runtime.InteropServices.RuntimeInformation" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-4.0.2.0" newVersion="4.0.2.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>
</assemblyBinding>
</runtime>
</configuration>
+30 -14
View File
@@ -1,5 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="..\packages\NUnit3TestAdapter.3.15.1\build\net35\NUnit3TestAdapter.props" Condition="Exists('..\packages\NUnit3TestAdapter.3.15.1\build\net35\NUnit3TestAdapter.props')" />
<Import Project="..\packages\NUnit.3.12.0\build\NUnit.props" Condition="Exists('..\packages\NUnit.3.12.0\build\NUnit.props')" />
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
@@ -11,6 +13,8 @@
<AssemblyName>IntegrationTests</AssemblyName>
<TargetFrameworkVersion>v4.6.1</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<NuGetPackageImportStamp>
</NuGetPackageImportStamp>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
@@ -30,20 +34,32 @@
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<ItemGroup>
<Reference Include="Crc32C.NET, Version=1.0.5.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\packages\Crc32C.NET.1.0.5.0\lib\net20\Crc32C.NET.dll</HintPath>
</Reference>
<Reference Include="DnsClient, Version=1.2.0.0, Culture=neutral, PublicKeyToken=4574bb5573c51424, processorArchitecture=MSIL">
<HintPath>..\packages\DnsClient.1.2.0\lib\net45\DnsClient.dll</HintPath>
</Reference>
<Reference Include="MongoDB.Bson, Version=2.8.0.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\packages\MongoDB.Bson.2.8.0\lib\net452\MongoDB.Bson.dll</HintPath>
<Reference Include="MongoDB.Bson, Version=2.9.3.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\packages\MongoDB.Bson.2.9.3\lib\net452\MongoDB.Bson.dll</HintPath>
</Reference>
<Reference Include="MongoDB.Driver, Version=2.8.0.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\packages\MongoDB.Driver.2.8.0\lib\net452\MongoDB.Driver.dll</HintPath>
<Reference Include="MongoDB.Driver, Version=2.9.3.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\packages\MongoDB.Driver.2.9.3\lib\net452\MongoDB.Driver.dll</HintPath>
</Reference>
<Reference Include="MongoDB.Driver.Core, Version=2.8.0.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\packages\MongoDB.Driver.Core.2.8.0\lib\net452\MongoDB.Driver.Core.dll</HintPath>
<Reference Include="MongoDB.Driver.Core, Version=2.9.3.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\packages\MongoDB.Driver.Core.2.9.3\lib\net452\MongoDB.Driver.Core.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 Include="MongoDbGenericRepository, Version=1.0.0.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\packages\MongoDbGenericRepository.1.4.3\lib\net452\MongoDbGenericRepository.dll</HintPath>
</Reference>
<Reference Include="nunit.framework, Version=3.12.0.0, Culture=neutral, PublicKeyToken=2638cd05610744eb, processorArchitecture=MSIL">
<HintPath>..\packages\NUnit.3.12.0\lib\net45\nunit.framework.dll</HintPath>
</Reference>
<Reference Include="SharpCompress, Version=0.23.0.0, Culture=neutral, PublicKeyToken=afb0a02973931d96, processorArchitecture=MSIL">
<HintPath>..\packages\SharpCompress.0.23.0\lib\net45\SharpCompress.dll</HintPath>
</Reference>
<Reference Include="Snappy.NET, Version=1.1.1.8, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\packages\Snappy.NET.1.1.1.8\lib\net45\Snappy.NET.dll</HintPath>
</Reference>
<Reference Include="System" />
<Reference Include="System.Buffers, Version=4.0.2.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51, processorArchitecture=MSIL">
@@ -85,11 +101,11 @@
<ItemGroup>
<Service Include="{82A7F48D-3B50-4B1E-B82E-3ADA8210C358}" />
</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" />
<Target Name="EnsureNuGetPackageBuildImports" BeforeTargets="PrepareForBuild">
<PropertyGroup>
<ErrorText>This project references NuGet package(s) that are missing on this computer. Use NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}.</ErrorText>
</PropertyGroup>
<Error Condition="!Exists('..\packages\NUnit3TestAdapter.3.15.1\build\net35\NUnit3TestAdapter.props')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\NUnit3TestAdapter.3.15.1\build\net35\NUnit3TestAdapter.props'))" />
</Target>
</Project>
+10 -5
View File
@@ -1,11 +1,16 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="Crc32C.NET" version="1.0.5.0" targetFramework="net461" />
<package id="DnsClient" version="1.2.0" targetFramework="net461" />
<package id="MongoDB.Bson" version="2.8.0" targetFramework="net461" />
<package id="MongoDB.Driver" version="2.8.0" targetFramework="net461" />
<package id="MongoDB.Driver.Core" version="2.8.0" targetFramework="net461" />
<package id="NUnit" version="3.9.0" targetFramework="net461" />
<package id="NUnit.ConsoleRunner" version="3.7.0" targetFramework="net461" />
<package id="MongoDB.Bson" version="2.9.3" targetFramework="net461" />
<package id="MongoDB.Driver" version="2.9.3" targetFramework="net461" />
<package id="MongoDB.Driver.Core" version="2.9.3" targetFramework="net461" />
<package id="MongoDbGenericRepository" version="1.4.3" targetFramework="net461" />
<package id="NUnit" version="3.12.0" targetFramework="net461" />
<package id="NUnit.ConsoleRunner" version="3.10.0" targetFramework="net461" />
<package id="NUnit3TestAdapter" version="3.15.1" targetFramework="net461" />
<package id="SharpCompress" version="0.23.0" targetFramework="net461" />
<package id="Snappy.NET" version="1.1.1.8" targetFramework="net461" />
<package id="System.Buffers" version="4.4.0" targetFramework="net461" />
<package id="System.Runtime.InteropServices.RuntimeInformation" version="4.3.0" targetFramework="net461" />
</packages>
@@ -0,0 +1,135 @@
using MongoDB.Driver;
using MongoDbGenericRepository.Models;
using System;
using System.Linq.Expressions;
using System.Threading.Tasks;
namespace MongoDbGenericRepository
{
public interface IBaseMongoRepository_Update : IBaseMongoRepository_Update<Guid>
{
/// <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>
/// For the entity selected by the filter, updates the property field with the given value..
/// </summary>
/// <typeparam name="TDocument">The type representing a Document.</typeparam>
/// <typeparam name="TKey">The type of the primary key for a Document.</typeparam>
/// <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 partition key for the document.</param>
bool UpdateOne<TDocument, TKey, TField>(Expression<Func<TDocument, bool>> 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="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>
/// For the entity selected by the filter, updates the property field with the given value.
/// </summary>
/// <typeparam name="TDocument">The type representing a Document.</typeparam>
/// <typeparam name="TKey">The type of the primary key for a Document.</typeparam>
/// <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 partition key for the document.</param>
Task<bool> UpdateOneAsync<TDocument, TKey, TField>(Expression<Func<TDocument, bool>> 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="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>;
}
}
@@ -0,0 +1,166 @@
using System;
using System.Linq.Expressions;
using System.Threading;
using System.Threading.Tasks;
using MongoDB.Driver;
using MongoDbGenericRepository.Models;
namespace MongoDbGenericRepository.DataAccess.Update
{
public interface IBaseMongoRepository_Update_ClientSession
{
/// <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="session">The client session.</param>
/// <param name="modifiedDocument">The document with the modifications you want to persist.</param>
/// <param name="cancellationToken">The optional cancellation token.</param>
/// <returns></returns>
bool UpdateOne<TDocument, TKey, TField>(IClientSessionHandle session, Expression<Func<TDocument, bool>> filter, Expression<Func<TDocument, TField>> field, TField value, string partitionKey = null, CancellationToken cancellationToken = default(CancellationToken))
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="session">The client session.</param>
/// <param name="modifiedDocument">The document with the modifications you want to persist.</param>
/// <param name="cancellationToken">The optional cancellation token.</param>
/// <returns></returns>
bool UpdateOne<TDocument, TKey, TField>(IClientSessionHandle session, FilterDefinition<TDocument> filter, Expression<Func<TDocument, TField>> field, TField value, string partitionKey = null, CancellationToken cancellationToken = default(CancellationToken))
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="session">The client session.</param>
/// <param name="documentToModify">The document to modify.</param>
/// <param name="update">The update definition.</param>
/// <param name="cancellationToken">The optional cancellation token.</param>
/// <returns></returns>
bool UpdateOne<TDocument, TKey, TField>(IClientSessionHandle session, TDocument documentToModify, Expression<Func<TDocument, TField>> field, TField value, CancellationToken cancellationToken = default(CancellationToken))
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="session">The client session.</param>
/// <param name="documentToModify">The document to modify.</param>
/// <param name="update">The update definition.</param>
/// <param name="cancellationToken">The optional cancellation token.</param>
/// <returns></returns>
bool UpdateOne<TDocument, TKey>(IClientSessionHandle session, TDocument modifiedDocument, CancellationToken cancellationToken = default(CancellationToken))
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>
/// <typeparam name="TField">The type of the field to update.</typeparam>
/// <param name="session">The client session.</param>
/// <param name="documentToModify">The document to modify.</param>
/// <param name="field">The field to update.</param>
/// <param name="value">The value of the field.</param>
/// <param name="cancellationToken">The optional cancellation token.</param>
/// <returns></returns>
bool UpdateOne<TDocument, TKey>(IClientSessionHandle session, TDocument documentToModify, UpdateDefinition<TDocument> update, CancellationToken cancellationToken = default(CancellationToken))
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>
/// <typeparam name="TField">The type of the field to update.</typeparam>
/// <param name="session">The client session.</param>
/// <param name="documentToModify">The document to modify.</param>
/// <param name="field">The field to update.</param>
/// <param name="value">The value of the field.</param>
/// <param name="cancellationToken">The optional cancellation token.</param>
/// <returns></returns>
Task<bool> UpdateOneAsync<TDocument, TKey, TField>(IClientSessionHandle session, Expression<Func<TDocument, bool>> filter, Expression<Func<TDocument, TField>> field, TField value, string partitionKey = null, CancellationToken cancellationToken = default(CancellationToken))
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>
/// <typeparam name="TField">The type of the field to update.</typeparam>
/// <param name="session">The client session.</param>
/// <param name="filter">The filter for the update.</param>
/// <param name="field">The field to update.</param>
/// <param name="value">The value of the field.</param>
/// <param name="partitionKey">The optional partition key.</param>
/// <param name="cancellationToken">The optional cancellation token.</param>
/// <returns></returns>
Task<bool> UpdateOneAsync<TDocument, TKey, TField>(IClientSessionHandle session, FilterDefinition<TDocument> filter, Expression<Func<TDocument, TField>> field, TField value, string partitionKey = null, CancellationToken cancellationToken = default(CancellationToken))
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>
/// <typeparam name="TField">The type of the field to update.</typeparam>
/// <param name="session">The client session.</param>
/// <param name="filter">The filter for the update.</param>
/// <param name="field">The field to update.</param>
/// <param name="value">The value of the field.</param>
/// <param name="partitionKey">The optional partition key.</param>
/// <param name="cancellationToken">The optional cancellation token.</param>
/// <returns></returns>
Task<bool> UpdateOneAsync<TDocument, TKey, TField>(IClientSessionHandle session, TDocument documentToModify, Expression<Func<TDocument, TField>> field, TField value, CancellationToken cancellationToken = default(CancellationToken))
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>
/// <typeparam name="TField">The type of the field to update.</typeparam>
/// <param name="session">The client session.</param>
/// <param name="filter">The filter for the update.</param>
/// <param name="field">The field to update.</param>
/// <param name="value">The value of the field.</param>
/// <param name="partitionKey">The optional partition key.</param>
/// <param name="cancellationToken">The optional cancellation token.</param>
/// <returns></returns>
Task<bool> UpdateOneAsync<TDocument, TKey>(IClientSessionHandle session, TDocument modifiedDocument, CancellationToken cancellationToken = default(CancellationToken))
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>
/// <typeparam name="TField">The type of the field to update.</typeparam>
/// <param name="session">The client session.</param>
/// <param name="filter">The filter for the update.</param>
/// <param name="field">The field to update.</param>
/// <param name="value">The value of the field.</param>
/// <param name="partitionKey">The optional partition key.</param>
/// <param name="cancellationToken">The optional cancellation token.</param>
/// <returns></returns>
Task<bool> UpdateOneAsync<TDocument, TKey>(IClientSessionHandle session, TDocument documentToModify, UpdateDefinition<TDocument> update, CancellationToken cancellationToken = default(CancellationToken))
where TDocument : IDocument<TKey>
where TKey : IEquatable<TKey>;
}
}
@@ -335,5 +335,47 @@ namespace MongoDbGenericRepository
where TProjection : class, new();
#endregion Group By
#region Pagination
/// <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">A LINQ expression filter.</param>
/// <param name="sortSelector">The property selector.</param>
/// <param name="ascending">Order of the sorting.</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>> GetSortedPaginatedAsync<TDocument>(
Expression<Func<TDocument, bool>> filter,
Expression<Func<TDocument, object>> sortSelector,
bool ascending = true,
int skipNumber = 0,
int takeNumber = 50,
string partitionKey = null)
where TDocument : IDocument<TKey>;
/// <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">A LINQ expression filter.</param>
/// <param name="sortDefinition">The sort definition.</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>> GetSortedPaginatedAsync<TDocument>(
Expression<Func<TDocument, bool>> filter,
SortDefinition<TDocument> sortDefinition,
int skipNumber = 0,
int takeNumber = 50,
string partitionKey = null)
where TDocument : IDocument<TKey>;
#endregion Pagination
}
}
@@ -61,7 +61,7 @@ namespace MongoDbGenericRepository
{
private readonly object _initLock = new object();
private MongoDbCreator _mongoDbCreator;
protected MongoDbCreator MongoDbCreator
protected virtual MongoDbCreator MongoDbCreator
{
get
{
@@ -77,6 +77,7 @@ namespace MongoDbGenericRepository
return _mongoDbCreator;
}
set { _mongoDbCreator = value; }
}
/// <summary>
@@ -105,7 +105,7 @@ namespace MongoDbGenericRepository
public abstract partial class BaseMongoRepository : IBaseMongoRepository_Delete
{
private MongoDbEraser _mongoDbEraser;
protected MongoDbEraser MongoDbEraser
protected virtual MongoDbEraser MongoDbEraser
{
get
{
@@ -121,6 +121,7 @@ namespace MongoDbGenericRepository
return _mongoDbEraser;
}
set { _mongoDbEraser = value; }
}
#region Delete
@@ -113,7 +113,7 @@ namespace MongoDbGenericRepository
public abstract partial class BaseMongoRepository : IBaseMongoRepository_Index
{
private MongoDbIndexHandler _mongoDbIndexHandler;
protected MongoDbIndexHandler MongoDbIndexHandler
protected virtual MongoDbIndexHandler MongoDbIndexHandler
{
get
{
@@ -128,6 +128,7 @@ namespace MongoDbGenericRepository
}
return _mongoDbIndexHandler;
}
set { _mongoDbIndexHandler = value; }
}
/// <summary>
@@ -316,4 +317,4 @@ namespace MongoDbGenericRepository
await MongoDbIndexHandler.DropIndexAsync<TDocument, TKey>(indexName, partitionKey);
}
}
}
}
@@ -0,0 +1,197 @@
using MongoDB.Driver;
using MongoDbGenericRepository.DataAccess.Update;
using MongoDbGenericRepository.Models;
using System;
using System.Linq.Expressions;
using System.Threading;
using System.Threading.Tasks;
namespace MongoDbGenericRepository
{
public abstract partial class BaseMongoRepository : IBaseMongoRepository_Update_ClientSession
{
/// <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="session">The client session.</param>
/// <param name="modifiedDocument">The document with the modifications you want to persist.</param>
/// <param name="cancellationToken">The optional cancellation token.</param>
/// <returns></returns>
public virtual async Task<bool> UpdateOneAsync<TDocument, TKey>(IClientSessionHandle session, TDocument modifiedDocument, CancellationToken cancellationToken = default(CancellationToken))
where TDocument : IDocument<TKey>
where TKey : IEquatable<TKey>
{
return await MongoDbUpdater.UpdateOneAsync<TDocument, TKey>(session, modifiedDocument, cancellationToken);
}
/// <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="session">The client session.</param>
/// <param name="modifiedDocument">The document with the modifications you want to persist.</param>
/// <param name="cancellationToken">The optional cancellation token.</param>
/// <returns></returns>
public virtual bool UpdateOne<TDocument, TKey>(IClientSessionHandle session, TDocument modifiedDocument, CancellationToken cancellationToken = default(CancellationToken))
where TDocument : IDocument<TKey>
where TKey : IEquatable<TKey>
{
return MongoDbUpdater.UpdateOne<TDocument, TKey>(session, modifiedDocument, cancellationToken);
}
/// <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="session">The client session.</param>
/// <param name="documentToModify">The document to modify.</param>
/// <param name="update">The update definition.</param>
/// <param name="cancellationToken">The optional cancellation token.</param>
/// <returns></returns>
public virtual async Task<bool> UpdateOneAsync<TDocument, TKey>(IClientSessionHandle session, TDocument documentToModify, UpdateDefinition<TDocument> update, CancellationToken cancellationToken = default(CancellationToken))
where TDocument : IDocument<TKey>
where TKey : IEquatable<TKey>
{
return await MongoDbUpdater.UpdateOneAsync<TDocument, TKey>(session, documentToModify, update, cancellationToken);
}
/// <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="session">The client session.</param>
/// <param name="documentToModify">The document to modify.</param>
/// <param name="update">The update definition.</param>
/// <param name="cancellationToken">The optional cancellation token.</param>
/// <returns></returns>
public virtual bool UpdateOne<TDocument, TKey>(IClientSessionHandle session, TDocument documentToModify, UpdateDefinition<TDocument> update, CancellationToken cancellationToken = default(CancellationToken))
where TDocument : IDocument<TKey>
where TKey : IEquatable<TKey>
{
return MongoDbUpdater.UpdateOne<TDocument, TKey>(session, documentToModify, update, cancellationToken);
}
/// <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>
/// <typeparam name="TField">The type of the field to update.</typeparam>
/// <param name="session">The client session.</param>
/// <param name="documentToModify">The document to modify.</param>
/// <param name="field">The field to update.</param>
/// <param name="value">The value of the field.</param>
/// <param name="cancellationToken">The optional cancellation token.</param>
/// <returns></returns>
public virtual async Task<bool> UpdateOneAsync<TDocument, TKey, TField>(IClientSessionHandle session, TDocument documentToModify, Expression<Func<TDocument, TField>> field, TField value, CancellationToken cancellationToken = default(CancellationToken))
where TDocument : IDocument<TKey>
where TKey : IEquatable<TKey>
{
return await MongoDbUpdater.UpdateOneAsync<TDocument, TKey, TField>(session, documentToModify, field, value, cancellationToken);
}
/// <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>
/// <typeparam name="TField">The type of the field to update.</typeparam>
/// <param name="session">The client session.</param>
/// <param name="documentToModify">The document to modify.</param>
/// <param name="field">The field to update.</param>
/// <param name="value">The value of the field.</param>
/// <param name="cancellationToken">The optional cancellation token.</param>
/// <returns></returns>
public virtual bool UpdateOne<TDocument, TKey, TField>(IClientSessionHandle session, TDocument documentToModify, Expression<Func<TDocument, TField>> field, TField value, CancellationToken cancellationToken = default(CancellationToken))
where TDocument : IDocument<TKey>
where TKey : IEquatable<TKey>
{
return MongoDbUpdater.UpdateOne<TDocument, TKey, TField>(session, documentToModify, field, value, cancellationToken);
}
/// <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>
/// <typeparam name="TField">The type of the field to update.</typeparam>
/// <param name="session">The client session.</param>
/// <param name="filter">The filter for the update.</param>
/// <param name="field">The field to update.</param>
/// <param name="value">The value of the field.</param>
/// <param name="partitionKey">The optional partition key.</param>
/// <param name="cancellationToken">The optional cancellation token.</param>
/// <returns></returns>
public virtual async Task<bool> UpdateOneAsync<TDocument, TKey, TField>(IClientSessionHandle session, FilterDefinition<TDocument> filter, Expression<Func<TDocument, TField>> field, TField value, string partitionKey = null, CancellationToken cancellationToken = default(CancellationToken))
where TDocument : IDocument<TKey>
where TKey : IEquatable<TKey>
{
return await MongoDbUpdater.UpdateOneAsync<TDocument, TKey, TField>(session, filter, field, value, partitionKey, cancellationToken);
}
/// <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>
/// <typeparam name="TField">The type of the field to update.</typeparam>
/// <param name="session">The client session.</param>
/// <param name="filter">The filter for the update.</param>
/// <param name="field">The field to update.</param>
/// <param name="value">The value of the field.</param>
/// <param name="partitionKey">The optional partition key.</param>
/// <param name="cancellationToken">The optional cancellation token.</param>
/// <returns></returns>
public virtual async Task<bool> UpdateOneAsync<TDocument, TKey, TField>(IClientSessionHandle session, Expression<Func<TDocument, bool>> filter, Expression<Func<TDocument, TField>> field, TField value, string partitionKey = null, CancellationToken cancellationToken = default(CancellationToken))
where TDocument : IDocument<TKey>
where TKey : IEquatable<TKey>
{
return await MongoDbUpdater.UpdateOneAsync<TDocument, TKey, TField>(session, filter, field, value, partitionKey, cancellationToken);
}
/// <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>
/// <typeparam name="TField">The type of the field to update.</typeparam>
/// <param name="session">The client session.</param>
/// <param name="filter">The filter for the update.</param>
/// <param name="field">The field to update.</param>
/// <param name="value">The value of the field.</param>
/// <param name="partitionKey">The optional partition key.</param>
/// <param name="cancellationToken">The optional cancellation token.</param>
/// <returns></returns>
public virtual bool UpdateOne<TDocument, TKey, TField>(IClientSessionHandle session, FilterDefinition<TDocument> filter, Expression<Func<TDocument, TField>> field, TField value, string partitionKey = null, CancellationToken cancellationToken = default(CancellationToken))
where TDocument : IDocument<TKey>
where TKey : IEquatable<TKey>
{
return MongoDbUpdater.UpdateOne<TDocument, TKey, TField>(session, filter, field, value, partitionKey, cancellationToken);
}
/// <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>
/// <typeparam name="TField">The type of the field to update.</typeparam>
/// <param name="session">The client session.</param>
/// <param name="filter">The filter for the update.</param>
/// <param name="field">The field to update.</param>
/// <param name="value">The value of the field.</param>
/// <param name="partitionKey">The optional partition key.</param>
/// <param name="cancellationToken">The optional cancellation token.</param>
/// <returns></returns>
public virtual bool UpdateOne<TDocument, TKey, TField>(IClientSessionHandle session, Expression<Func<TDocument, bool>> filter, Expression<Func<TDocument, TField>> field, TField value, string partitionKey = null, CancellationToken cancellationToken = default(CancellationToken))
where TDocument : IDocument<TKey>
where TKey : IEquatable<TKey>
{
return UpdateOne<TDocument, TKey, TField>(session, Builders<TDocument>.Filter.Where(filter), field, value, partitionKey, cancellationToken);
}
}
}
@@ -7,132 +7,6 @@ using System.Threading.Tasks;
namespace MongoDbGenericRepository
{
public interface IBaseMongoRepository_Update : IBaseMongoRepository_Update<Guid>
{
/// <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>
/// For the entity selected by the filter, updates the property field with the given value..
/// </summary>
/// <typeparam name="TDocument">The type representing a Document.</typeparam>
/// <typeparam name="TKey">The type of the primary key for a Document.</typeparam>
/// <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 partition key for the document.</param>
bool UpdateOne<TDocument, TKey, TField>(Expression<Func<TDocument, bool>> 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="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>
/// For the entity selected by the filter, updates the property field with the given value.
/// </summary>
/// <typeparam name="TDocument">The type representing a Document.</typeparam>
/// <typeparam name="TKey">The type of the primary key for a Document.</typeparam>
/// <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 partition key for the document.</param>
Task<bool> UpdateOneAsync<TDocument, TKey, TField>(Expression<Func<TDocument, bool>> 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="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>;
}
/// <summary>
/// The base Repository, it is meant to be inherited from by your custom custom MongoRepository implementation.
/// Its constructor must be given a connection string and a database name.
@@ -140,7 +14,7 @@ namespace MongoDbGenericRepository
public abstract partial class BaseMongoRepository : IBaseMongoRepository_Update
{
private MongoDbUpdater _mongoDbUpdater;
protected MongoDbUpdater MongoDbUpdater
protected virtual MongoDbUpdater MongoDbUpdater
{
get
{
@@ -156,6 +30,7 @@ namespace MongoDbGenericRepository
return _mongoDbUpdater;
}
set { _mongoDbUpdater = value; }
}
#region Update
@@ -451,6 +326,7 @@ namespace MongoDbGenericRepository
return await MongoDbUpdater.UpdateOneAsync<TDocument, TKey, TField>(Builders<TDocument>.Filter.Where(filter), field, value, partitionKey);
}
#endregion Update
}
@@ -0,0 +1,217 @@
using MongoDB.Driver;
using MongoDbGenericRepository.Models;
using System;
using System.Linq.Expressions;
using System.Threading;
using System.Threading.Tasks;
namespace MongoDbGenericRepository.DataAccess.Update
{
public partial class MongoDbUpdater
{
/// <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="session">The client session.</param>
/// <param name="modifiedDocument">The document with the modifications you want to persist.</param>
/// <param name="cancellationToken">The optional cancellation token.</param>
/// <returns></returns>
public virtual async Task<bool> UpdateOneAsync<TDocument, TKey>(IClientSessionHandle session, TDocument modifiedDocument, CancellationToken cancellationToken = default(CancellationToken))
where TDocument : IDocument<TKey>
where TKey : IEquatable<TKey>
{
var filter = Builders<TDocument>.Filter.Eq("Id", modifiedDocument.Id);
var updateRes = await HandlePartitioned<TDocument, TKey>(modifiedDocument)
.ReplaceOneAsync(session, filter, modifiedDocument, cancellationToken: cancellationToken)
.ConfigureAwait(false);
return updateRes.ModifiedCount == 1;
}
/// <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="session">The client session.</param>
/// <param name="modifiedDocument">The document with the modifications you want to persist.</param>
/// <param name="cancellationToken">The optional cancellation token.</param>
/// <returns></returns>
public virtual bool UpdateOne<TDocument, TKey>(IClientSessionHandle session, TDocument modifiedDocument, CancellationToken cancellationToken = default(CancellationToken))
where TDocument : IDocument<TKey>
where TKey : IEquatable<TKey>
{
var filter = Builders<TDocument>.Filter.Eq("Id", modifiedDocument.Id);
var updateRes = HandlePartitioned<TDocument, TKey>(modifiedDocument).ReplaceOne(session, filter, modifiedDocument, cancellationToken: cancellationToken);
return updateRes.ModifiedCount == 1;
}
/// <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="session">The client session.</param>
/// <param name="documentToModify">The document to modify.</param>
/// <param name="update">The update definition.</param>
/// <param name="cancellationToken">The optional cancellation token.</param>
/// <returns></returns>
public virtual async Task<bool> UpdateOneAsync<TDocument, TKey>(IClientSessionHandle session, TDocument documentToModify, UpdateDefinition<TDocument> update, CancellationToken cancellationToken = default(CancellationToken))
where TDocument : IDocument<TKey>
where TKey : IEquatable<TKey>
{
var filter = Builders<TDocument>.Filter.Eq("Id", documentToModify.Id);
var updateRes = await HandlePartitioned<TDocument, TKey>(documentToModify).UpdateOneAsync(session, filter, update, new UpdateOptions { IsUpsert = true }, cancellationToken).ConfigureAwait(false);
return updateRes.ModifiedCount == 1;
}
/// <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="session">The client session.</param>
/// <param name="documentToModify">The document to modify.</param>
/// <param name="update">The update definition.</param>
/// <param name="cancellationToken">The optional cancellation token.</param>
/// <returns></returns>
public virtual bool UpdateOne<TDocument, TKey>(IClientSessionHandle session, TDocument documentToModify, UpdateDefinition<TDocument> update, CancellationToken cancellationToken = default(CancellationToken))
where TDocument : IDocument<TKey>
where TKey : IEquatable<TKey>
{
var filter = Builders<TDocument>.Filter.Eq("Id", documentToModify.Id);
var updateRes = HandlePartitioned<TDocument, TKey>(documentToModify).UpdateOne(session, filter, update, new UpdateOptions { IsUpsert = true }, cancellationToken);
return updateRes.ModifiedCount == 1;
}
/// <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>
/// <typeparam name="TField">The type of the field to update.</typeparam>
/// <param name="session">The client session.</param>
/// <param name="documentToModify">The document to modify.</param>
/// <param name="field">The field to update.</param>
/// <param name="value">The value of the field.</param>
/// <param name="cancellationToken">The optional cancellation token.</param>
/// <returns></returns>
public virtual async Task<bool> UpdateOneAsync<TDocument, TKey, TField>(IClientSessionHandle session, TDocument documentToModify, Expression<Func<TDocument, TField>> field, TField value, CancellationToken cancellationToken = default(CancellationToken))
where TDocument : IDocument<TKey>
where TKey : IEquatable<TKey>
{
var filter = Builders<TDocument>.Filter.Eq("Id", documentToModify.Id);
var updateRes = await HandlePartitioned<TDocument, TKey>(documentToModify)
.UpdateOneAsync(session, filter, Builders<TDocument>.Update.Set(field, value), cancellationToken: cancellationToken)
.ConfigureAwait(false);
return updateRes.ModifiedCount == 1;
}
/// <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>
/// <typeparam name="TField">The type of the field to update.</typeparam>
/// <param name="session">The client session.</param>
/// <param name="documentToModify">The document to modify.</param>
/// <param name="field">The field to update.</param>
/// <param name="value">The value of the field.</param>
/// <param name="cancellationToken">The optional cancellation token.</param>
/// <returns></returns>
public virtual bool UpdateOne<TDocument, TKey, TField>(IClientSessionHandle session, TDocument documentToModify, Expression<Func<TDocument, TField>> field, TField value, CancellationToken cancellationToken = default(CancellationToken))
where TDocument : IDocument<TKey>
where TKey : IEquatable<TKey>
{
var filter = Builders<TDocument>.Filter.Eq("Id", documentToModify.Id);
var updateRes = HandlePartitioned<TDocument, TKey>(documentToModify).UpdateOne(session, filter, Builders<TDocument>.Update.Set(field, value), cancellationToken: cancellationToken);
return updateRes.ModifiedCount == 1;
}
/// <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>
/// <typeparam name="TField">The type of the field to update.</typeparam>
/// <param name="session">The client session.</param>
/// <param name="filter">The filter for the update.</param>
/// <param name="field">The field to update.</param>
/// <param name="value">The value of the field.</param>
/// <param name="partitionKey">The optional partition key.</param>
/// <param name="cancellationToken">The optional cancellation token.</param>
/// <returns></returns>
public virtual async Task<bool> UpdateOneAsync<TDocument, TKey, TField>(IClientSessionHandle session, FilterDefinition<TDocument> filter, Expression<Func<TDocument, TField>> field, TField value, string partitionKey = null, CancellationToken cancellationToken = default(CancellationToken))
where TDocument : IDocument<TKey>
where TKey : IEquatable<TKey>
{
var collection = string.IsNullOrEmpty(partitionKey) ? GetCollection<TDocument, TKey>() : GetCollection<TDocument, TKey>(partitionKey);
var updateRes = await collection.UpdateOneAsync(session, filter, Builders<TDocument>.Update.Set(field, value), cancellationToken: cancellationToken).ConfigureAwait(false);
return updateRes.ModifiedCount == 1;
}
/// <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>
/// <typeparam name="TField">The type of the field to update.</typeparam>
/// <param name="session">The client session.</param>
/// <param name="filter">The filter for the update.</param>
/// <param name="field">The field to update.</param>
/// <param name="value">The value of the field.</param>
/// <param name="partitionKey">The optional partition key.</param>
/// <param name="cancellationToken">The optional cancellation token.</param>
/// <returns></returns>
public virtual Task<bool> UpdateOneAsync<TDocument, TKey, TField>(IClientSessionHandle session, Expression<Func<TDocument, bool>> filter, Expression<Func<TDocument, TField>> field, TField value, string partitionKey = null, CancellationToken cancellationToken = default(CancellationToken))
where TDocument : IDocument<TKey>
where TKey : IEquatable<TKey>
{
return UpdateOneAsync<TDocument, TKey, TField>(session, Builders<TDocument>.Filter.Where(filter), field, value, partitionKey, cancellationToken);
}
/// <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>
/// <typeparam name="TField">The type of the field to update.</typeparam>
/// <param name="session">The client session.</param>
/// <param name="filter">The filter for the update.</param>
/// <param name="field">The field to update.</param>
/// <param name="value">The value of the field.</param>
/// <param name="partitionKey">The optional partition key.</param>
/// <param name="cancellationToken">The optional cancellation token.</param>
/// <returns></returns>
public virtual bool UpdateOne<TDocument, TKey, TField>(IClientSessionHandle session, FilterDefinition<TDocument> filter, Expression<Func<TDocument, TField>> field, TField value, string partitionKey = null, CancellationToken cancellationToken = default(CancellationToken))
where TDocument : IDocument<TKey>
where TKey : IEquatable<TKey>
{
var collection = string.IsNullOrEmpty(partitionKey) ? GetCollection<TDocument, TKey>() : GetCollection<TDocument, TKey>(partitionKey);
var updateRes = collection.UpdateOne(session, filter, Builders<TDocument>.Update.Set(field, value), cancellationToken: cancellationToken);
return updateRes.ModifiedCount == 1;
}
/// <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>
/// <typeparam name="TField">The type of the field to update.</typeparam>
/// <param name="session">The client session.</param>
/// <param name="filter">The filter for the update.</param>
/// <param name="field">The field to update.</param>
/// <param name="value">The value of the field.</param>
/// <param name="partitionKey">The optional partition key.</param>
/// <param name="cancellationToken">The optional cancellation token.</param>
/// <returns></returns>
public virtual bool UpdateOne<TDocument, TKey, TField>(IClientSessionHandle session, Expression<Func<TDocument, bool>> filter, Expression<Func<TDocument, TField>> field, TField value, string partitionKey = null, CancellationToken cancellationToken = default(CancellationToken))
where TDocument : IDocument<TKey>
where TKey : IEquatable<TKey>
{
return UpdateOne<TDocument, TKey, TField>(session, Builders<TDocument>.Filter.Where(filter), field, value, partitionKey, cancellationToken);
}
}
}
@@ -1,17 +1,14 @@
using MongoDB.Driver;
using MongoDB.Driver.Linq;
using MongoDbGenericRepository.DataAccess.Base;
using MongoDbGenericRepository.Models;
using MongoDbGenericRepository.Utils;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Linq.Expressions;
using System.Threading;
using System.Threading.Tasks;
namespace MongoDbGenericRepository.DataAccess.Update
{
public class MongoDbUpdater : DataAccessBase
public partial class MongoDbUpdater : DataAccessBase
{
public MongoDbUpdater(IMongoDbContext mongoDbContext) : base(mongoDbContext)
{
@@ -56,7 +56,7 @@ namespace MongoDbGenericRepository
/// <summary>
/// The MongoDb accessor to insert data.
/// </summary>
protected MongoDbCreator MongoDbCreator
protected virtual MongoDbCreator MongoDbCreator
{
get
{
@@ -72,6 +72,7 @@ namespace MongoDbGenericRepository
}
return _mongoDbCreator;
}
set { _mongoDbCreator = value; }
}
/// <summary>
@@ -98,7 +98,7 @@ namespace MongoDbGenericRepository
/// <summary>
/// The MongoDb accessor to delete data.
/// </summary>
protected MongoDbEraser MongoDbEraser
protected virtual MongoDbEraser MongoDbEraser
{
get
{
@@ -113,6 +113,7 @@ namespace MongoDbGenericRepository
}
return _mongoDbEraser;
}
set { _mongoDbEraser = value; }
}
/// <summary>
@@ -109,7 +109,7 @@ namespace MongoDbGenericRepository
/// <summary>
/// The MongoDb accessor to manage indexes.
/// </summary>
protected MongoDbIndexHandler MongoDbIndexHandler
protected virtual MongoDbIndexHandler MongoDbIndexHandler
{
get
{
@@ -124,6 +124,7 @@ namespace MongoDbGenericRepository
}
return _mongoDbIndexHandler;
}
set { _mongoDbIndexHandler = value; }
}
/// <summary>
@@ -116,7 +116,7 @@ namespace MongoDbGenericRepository
where TKey : IEquatable<TKey>
{
private MongoDbUpdater _mongoDbUpdater;
protected MongoDbUpdater MongoDbUpdater
protected virtual MongoDbUpdater MongoDbUpdater
{
get
{
@@ -132,6 +132,7 @@ namespace MongoDbGenericRepository
return _mongoDbUpdater;
}
set { _mongoDbUpdater = value; }
}
/// <summary>
@@ -46,6 +46,15 @@ namespace MongoDbGenericRepository
Database = Client.GetDatabase(databaseName);
}
/// <summary>
/// Initialise an instance of a <see cref="IMongoDbContext"/> using a connection string
/// </summary>
/// <param name="connectionString"></param>
public MongoDbContext(string connectionString)
: this(connectionString, new MongoUrl(connectionString).DatabaseName)
{
}
/// <summary>
/// The constructor of the MongoDbContext, it needs a connection string and a database name.
/// </summary>
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFrameworks>net45;netstandard2.0;netstandard1.5;</TargetFrameworks>
<TargetFrameworks>net452;netstandard2.0;netstandard1.5;</TargetFrameworks>
<PackageId>MongoDbGenericRepository</PackageId>
<PackageVersion>1.2.0</PackageVersion>
<Authors>Alexandre Spieser</Authors>
@@ -16,8 +16,12 @@
<DocumentationFile>bin\Release\net45\MongoDbGenericRepository.xml</DocumentationFile>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(TargetFramework)|$(Platform)'=='Debug|net452|AnyCPU'">
<DocumentationFile></DocumentationFile>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="MongoDB.Driver" Version="2.7.0" />
<PackageReference Include="MongoDB.Driver" Version="2.9.3" />
</ItemGroup>
</Project>
@@ -2,7 +2,7 @@
<package >
<metadata>
<id>MongoDbGenericRepository</id>
<version>1.3.9</version>
<version>1.4.3</version>
<title>MongoDb Generic Repository</title>
<authors>Alexandre Spieser</authors>
<owners>Alexandre Spieser</owners>
@@ -14,7 +14,15 @@
<copyright>Copyright 2019 (c) Alexandre Spieser. All rights reserved.</copyright>
<tags>MongoDb Repository Generic NoSql</tags>
<dependencies>
<dependency id="MongoDB.Driver" version="2.7.0" />
<group targetFramework=".NETFramework4.5.2">
<dependency id="MongoDB.Driver" version="2.9.3" exclude="Build,Analyzers" />
</group>
<group targetFramework=".NETStandard1.5">
<dependency id="MongoDB.Driver" version="2.9.3" exclude="Build,Analyzers" />
</group>
<group targetFramework=".NETStandard2.0">
<dependency id="MongoDB.Driver" version="2.9.3" exclude="Build,Analyzers"/>
</group>
</dependencies>
</metadata>
<files>
File diff suppressed because it is too large Load Diff
Binary file not shown.
Binary file not shown.
@@ -1,7 +1,7 @@
{
"runtimeTarget": {
"name": ".NETStandard,Version=v1.5/",
"signature": "b945d8e228876adfa8e84019c7873fce5baf0c0b"
"signature": "89b5d0501e3f13fb98f678ed96fc31de9d7405cf"
},
"compilationOptions": {},
"targets": {
@@ -9,18 +9,18 @@
".NETStandard,Version=v1.5/": {
"MongoDbGenericRepository/1.0.0": {
"dependencies": {
"MongoDB.Driver": "2.7.0",
"MongoDB.Driver": "2.9.3",
"NETStandard.Library": "1.6.1"
},
"runtime": {
"MongoDbGenericRepository.dll": {}
}
},
"DnsClient/1.0.7": {
"DnsClient/1.2.0": {
"dependencies": {
"Microsoft.Win32.Primitives": "4.3.0",
"NETStandard.Library": "1.6.1",
"System.Buffers": "4.3.0",
"System.Buffers": "4.4.0",
"System.Collections": "4.3.0",
"System.Collections.Concurrent": "4.3.0",
"System.Globalization.Extensions": "4.3.0",
@@ -37,8 +37,8 @@
},
"runtime": {
"lib/netstandard1.3/DnsClient.dll": {
"assemblyVersion": "1.0.7.0",
"fileVersion": "1.0.7.0"
"assemblyVersion": "1.2.0.0",
"fileVersion": "1.2.0.0"
}
}
},
@@ -63,51 +63,55 @@
"System.Runtime.InteropServices": "4.3.0"
}
},
"MongoDB.Bson/2.7.0": {
"MongoDB.Bson/2.9.3": {
"dependencies": {
"NETStandard.Library": "1.6.1",
"System.Collections.NonGeneric": "4.0.1",
"System.Diagnostics.Process": "4.1.0",
"System.Dynamic.Runtime": "4.0.11",
"System.Reflection.Emit.Lightweight": "4.0.1"
"System.Reflection.Emit.Lightweight": "4.3.0",
"System.Runtime.Serialization.Formatters": "4.3.0"
},
"runtime": {
"lib/netstandard1.5/MongoDB.Bson.dll": {
"assemblyVersion": "2.7.0.0",
"fileVersion": "2.7.0.0"
"assemblyVersion": "2.9.3.0",
"fileVersion": "2.9.3.0"
}
}
},
"MongoDB.Driver/2.7.0": {
"MongoDB.Driver/2.9.3": {
"dependencies": {
"MongoDB.Bson": "2.7.0",
"MongoDB.Driver.Core": "2.7.0",
"MongoDB.Bson": "2.9.3",
"MongoDB.Driver.Core": "2.9.3",
"NETStandard.Library": "1.6.1",
"System.ComponentModel.TypeConverter": "4.1.0",
"System.Linq.Queryable": "4.0.1"
},
"runtime": {
"lib/netstandard1.5/MongoDB.Driver.dll": {
"assemblyVersion": "2.7.0.0",
"fileVersion": "2.7.0.0"
"assemblyVersion": "2.9.3.0",
"fileVersion": "2.9.3.0"
}
}
},
"MongoDB.Driver.Core/2.7.0": {
"MongoDB.Driver.Core/2.9.3": {
"dependencies": {
"DnsClient": "1.0.7",
"MongoDB.Bson": "2.7.0",
"DnsClient": "1.2.0",
"MongoDB.Bson": "2.9.3",
"NETStandard.Library": "1.6.1",
"SharpCompress": "0.23.0",
"System.Collections.Specialized": "4.0.1",
"System.Diagnostics.TextWriterTraceListener": "4.0.0",
"System.Diagnostics.TraceSource": "4.0.0",
"System.Net.NameResolution": "4.3.0",
"System.Net.Security": "4.0.0",
"System.Security.SecureString": "4.0.0"
"System.Net.Security": "4.3.2",
"System.Security.SecureString": "4.0.0",
"System.Threading.Thread": "4.3.0"
},
"runtime": {
"lib/netstandard1.5/MongoDB.Driver.Core.dll": {
"assemblyVersion": "2.7.0.0",
"fileVersion": "2.7.0.0"
"assemblyVersion": "2.9.3.0",
"fileVersion": "2.9.3.0"
}
}
},
@@ -195,12 +199,24 @@
"runtime.ubuntu.14.04-x64.runtime.native.System.Security.Cryptography.OpenSsl/4.3.0": {},
"runtime.ubuntu.16.04-x64.runtime.native.System.Security.Cryptography.OpenSsl/4.3.0": {},
"runtime.ubuntu.16.10-x64.runtime.native.System.Security.Cryptography.OpenSsl/4.3.0": {},
"SharpCompress/0.23.0": {
"dependencies": {
"NETStandard.Library": "1.6.1",
"System.Text.Encoding.CodePages": "4.5.1"
},
"runtime": {
"lib/netstandard1.3/SharpCompress.dll": {
"assemblyVersion": "0.23.0.0",
"fileVersion": "0.23.0.0"
}
}
},
"System.AppContext/4.3.0": {
"dependencies": {
"System.Runtime": "4.3.0"
}
},
"System.Buffers/4.3.0": {
"System.Buffers/4.4.0": {
"dependencies": {
"System.Diagnostics.Debug": "4.3.0",
"System.Diagnostics.Tracing": "4.3.0",
@@ -210,8 +226,8 @@
},
"runtime": {
"lib/netstandard1.1/System.Buffers.dll": {
"assemblyVersion": "4.0.1.0",
"fileVersion": "4.6.24705.1"
"assemblyVersion": "4.0.2.0",
"fileVersion": "4.6.25519.3"
}
}
},
@@ -380,6 +396,22 @@
"runtime.native.System": "4.3.0"
}
},
"System.Diagnostics.TextWriterTraceListener/4.0.0": {
"dependencies": {
"System.Diagnostics.TraceSource": "4.0.0",
"System.Globalization": "4.3.0",
"System.IO": "4.3.0",
"System.Resources.ResourceManager": "4.3.0",
"System.Runtime": "4.3.0",
"System.Threading": "4.3.0"
},
"runtime": {
"lib/netstandard1.3/System.Diagnostics.TextWriterTraceListener.dll": {
"assemblyVersion": "4.0.0.0",
"fileVersion": "1.0.24212.1"
}
}
},
"System.Diagnostics.Tools/4.3.0": {
"dependencies": {
"Microsoft.NETCore.Platforms": "1.1.0",
@@ -417,7 +449,7 @@
"System.ObjectModel": "4.3.0",
"System.Reflection": "4.3.0",
"System.Reflection.Emit": "4.0.1",
"System.Reflection.Emit.ILGeneration": "4.0.1",
"System.Reflection.Emit.ILGeneration": "4.3.0",
"System.Reflection.Primitives": "4.3.0",
"System.Reflection.TypeExtensions": "4.1.0",
"System.Resources.ResourceManager": "4.3.0",
@@ -469,7 +501,7 @@
"System.IO.Compression/4.3.0": {
"dependencies": {
"Microsoft.NETCore.Platforms": "1.1.0",
"System.Buffers": "4.3.0",
"System.Buffers": "4.4.0",
"System.Collections": "4.3.0",
"System.Diagnostics.Debug": "4.3.0",
"System.IO": "4.3.0",
@@ -487,7 +519,7 @@
},
"System.IO.Compression.ZipFile/4.3.0": {
"dependencies": {
"System.Buffers": "4.3.0",
"System.Buffers": "4.4.0",
"System.IO": "4.3.0",
"System.IO.Compression": "4.3.0",
"System.IO.FileSystem": "4.3.0",
@@ -633,7 +665,7 @@
"System.Runtime.Handles": "4.3.0"
}
},
"System.Net.Security/4.0.0": {
"System.Net.Security/4.3.2": {
"dependencies": {
"Microsoft.NETCore.Platforms": "1.1.0",
"Microsoft.Win32.Primitives": "4.3.0",
@@ -649,6 +681,7 @@
"System.Runtime.Handles": "4.3.0",
"System.Runtime.InteropServices": "4.3.0",
"System.Security.Claims": "4.3.0",
"System.Security.Cryptography.Encoding": "4.3.0",
"System.Security.Cryptography.Primitives": "4.3.0",
"System.Security.Cryptography.X509Certificates": "4.3.0",
"System.Security.Principal": "4.3.0",
@@ -696,7 +729,7 @@
"dependencies": {
"System.IO": "4.3.0",
"System.Reflection": "4.3.0",
"System.Reflection.Emit.ILGeneration": "4.0.1",
"System.Reflection.Emit.ILGeneration": "4.3.0",
"System.Reflection.Primitives": "4.3.0",
"System.Runtime": "4.3.0"
},
@@ -707,7 +740,7 @@
}
}
},
"System.Reflection.Emit.ILGeneration/4.0.1": {
"System.Reflection.Emit.ILGeneration/4.3.0": {
"dependencies": {
"System.Reflection": "4.3.0",
"System.Reflection.Primitives": "4.3.0",
@@ -715,22 +748,22 @@
},
"runtime": {
"lib/netstandard1.3/System.Reflection.Emit.ILGeneration.dll": {
"assemblyVersion": "4.0.1.0",
"fileVersion": "1.0.24212.1"
"assemblyVersion": "4.0.2.0",
"fileVersion": "4.6.24705.1"
}
}
},
"System.Reflection.Emit.Lightweight/4.0.1": {
"System.Reflection.Emit.Lightweight/4.3.0": {
"dependencies": {
"System.Reflection": "4.3.0",
"System.Reflection.Emit.ILGeneration": "4.0.1",
"System.Reflection.Emit.ILGeneration": "4.3.0",
"System.Reflection.Primitives": "4.3.0",
"System.Runtime": "4.3.0"
},
"runtime": {
"lib/netstandard1.3/System.Reflection.Emit.Lightweight.dll": {
"assemblyVersion": "4.0.1.0",
"fileVersion": "1.0.24212.1"
"assemblyVersion": "4.0.2.0",
"fileVersion": "4.6.24705.1"
}
}
},
@@ -831,6 +864,33 @@
}
}
},
"System.Runtime.Serialization.Formatters/4.3.0": {
"dependencies": {
"System.Collections": "4.3.0",
"System.Reflection": "4.3.0",
"System.Resources.ResourceManager": "4.3.0",
"System.Runtime": "4.3.0",
"System.Runtime.Serialization.Primitives": "4.3.0"
},
"runtime": {
"lib/netstandard1.4/System.Runtime.Serialization.Formatters.dll": {
"assemblyVersion": "4.0.1.0",
"fileVersion": "4.6.24705.1"
}
}
},
"System.Runtime.Serialization.Primitives/4.3.0": {
"dependencies": {
"System.Resources.ResourceManager": "4.3.0",
"System.Runtime": "4.3.0"
},
"runtime": {
"lib/netstandard1.3/System.Runtime.Serialization.Primitives.dll": {
"assemblyVersion": "4.1.2.0",
"fileVersion": "4.6.24705.1"
}
}
},
"System.Security.Claims/4.3.0": {
"dependencies": {
"System.Collections": "4.3.0",
@@ -944,6 +1004,17 @@
"System.Runtime": "4.3.0"
}
},
"System.Text.Encoding.CodePages/4.5.1": {
"dependencies": {
"NETStandard.Library": "1.6.1"
},
"runtime": {
"lib/netstandard1.3/System.Text.Encoding.CodePages.dll": {
"assemblyVersion": "4.0.2.0",
"fileVersion": "4.6.24705.1"
}
}
},
"System.Text.Encoding.Extensions/4.3.0": {
"dependencies": {
"Microsoft.NETCore.Platforms": "1.1.0",
@@ -1082,12 +1153,12 @@
"serviceable": false,
"sha512": ""
},
"DnsClient/1.0.7": {
"DnsClient/1.2.0": {
"type": "package",
"serviceable": true,
"sha512": "sha512-f3k5ufhUSL658fy/ac1mReqRIr0jGMyOJFvBqJ+7cASq01NIysYbrrRDjboYKAGrd0Y2mc1A749uQvT8vAA91A==",
"path": "dnsclient/1.0.7",
"hashPath": "dnsclient.1.0.7.nupkg.sha512"
"sha512": "sha512-P34wUkeqU4FoQiOMV8OjpdeDZKs4d3r+VlHuKJ6eO5feiZgna3+9MF5orHRUn3DAv1g/HPE5hlkGucmxmsFfBw==",
"path": "dnsclient/1.2.0",
"hashPath": "dnsclient.1.2.0.nupkg.sha512"
},
"Microsoft.NETCore.Platforms/1.1.0": {
"type": "package",
@@ -1113,30 +1184,30 @@
"Microsoft.Win32.Registry/4.0.0": {
"type": "package",
"serviceable": true,
"sha512": "sha512-mYUxH/YY9PwvuWY93/qsovFHAh+Lu2CNxNHWxB/x0dnpaEy6oIy/9d7R2J6dFaLZ7jhE7emLjn7A8kSzsP1A+Q==",
"sha512": "sha512-UiSp7lTxGtsF6J96wwErFeM0jygj/bWWKvbqwtRP2t6OohgT7TCTpjvQ1+7DLQLH3DR70i6+eRGX/y85WFuz1Q==",
"path": "microsoft.win32.registry/4.0.0",
"hashPath": "microsoft.win32.registry.4.0.0.nupkg.sha512"
},
"MongoDB.Bson/2.7.0": {
"MongoDB.Bson/2.9.3": {
"type": "package",
"serviceable": true,
"sha512": "sha512-vzpTDHYX/X6gF9qtDuKRJiLkqpj5OZuT1bIzJCiBiU8CwJ37becYmaXuy/QSuWnYN6j6ZdVTWILKbWt2MXL8DA==",
"path": "mongodb.bson/2.7.0",
"hashPath": "mongodb.bson.2.7.0.nupkg.sha512"
"sha512": "sha512-iuLdgI/8Q3AnboPR0OTFDpqVAxTskW9IQLhxKt+O4IQ3s9hHVLLp1dGLChrwrcK+3Fa2MFNHvm6W8tEMV4VUmw==",
"path": "mongodb.bson/2.9.3",
"hashPath": "mongodb.bson.2.9.3.nupkg.sha512"
},
"MongoDB.Driver/2.7.0": {
"MongoDB.Driver/2.9.3": {
"type": "package",
"serviceable": true,
"sha512": "sha512-5wP5BBwm5YO6h2Vhw6zQmOwSW9WP2d6kgRM6E7uIbwIJz4+j2trS2Wo7/+IYow5WVN8Jd6O27bIB/4gKNepO1Q==",
"path": "mongodb.driver/2.7.0",
"hashPath": "mongodb.driver.2.7.0.nupkg.sha512"
"sha512": "sha512-nSHXATq6u9CSwfO/xCQSZe6JgJeVmLng0v6fwc6WFTYVnssAZjIaj1BiNu3XshHP+vYCzYZUmbPtRHltaXQiuw==",
"path": "mongodb.driver/2.9.3",
"hashPath": "mongodb.driver.2.9.3.nupkg.sha512"
},
"MongoDB.Driver.Core/2.7.0": {
"MongoDB.Driver.Core/2.9.3": {
"type": "package",
"serviceable": true,
"sha512": "sha512-SepB4KT+zXA3iFaIFwXVKmk6BZIp0EGE/iWqNbDZ1mca9e8EhtqYPwOOzFmEbdKAzmVvF1y86kNI4agWP6I5sg==",
"path": "mongodb.driver.core/2.7.0",
"hashPath": "mongodb.driver.core.2.7.0.nupkg.sha512"
"sha512": "sha512-j95XZhXTukZHUnZmEFEJPERscccfa42iLPbPBlwRJMK5XEZ9myCcxnWACvJwYXrU6RoRwUzYCFYoSHj6lHfgmA==",
"path": "mongodb.driver.core/2.9.3",
"hashPath": "mongodb.driver.core.2.9.3.nupkg.sha512"
},
"NETStandard.Library/1.6.1": {
"type": "package",
@@ -1236,6 +1307,13 @@
"path": "runtime.ubuntu.16.10-x64.runtime.native.system.security.cryptography.openssl/4.3.0",
"hashPath": "runtime.ubuntu.16.10-x64.runtime.native.system.security.cryptography.openssl.4.3.0.nupkg.sha512"
},
"SharpCompress/0.23.0": {
"type": "package",
"serviceable": true,
"sha512": "sha512-HBbT47JHvNrsZX2dTBzUBOSzBt+EmIRGLIBkbxcP6Jef7DB4eFWQX5iHWV3Nj7hABFPCjISrZ8s0z72nF2zFHQ==",
"path": "sharpcompress/0.23.0",
"hashPath": "sharpcompress.0.23.0.nupkg.sha512"
},
"System.AppContext/4.3.0": {
"type": "package",
"serviceable": true,
@@ -1243,12 +1321,12 @@
"path": "system.appcontext/4.3.0",
"hashPath": "system.appcontext.4.3.0.nupkg.sha512"
},
"System.Buffers/4.3.0": {
"System.Buffers/4.4.0": {
"type": "package",
"serviceable": true,
"sha512": "sha512-ratu44uTIHgeBeI0dE8DWvmXVBSo4u7ozRZZHOMmK/JPpYyo0dAfgSiHlpiObMQ5lEtEyIXA40sKRYg5J6A8uQ==",
"path": "system.buffers/4.3.0",
"hashPath": "system.buffers.4.3.0.nupkg.sha512"
"sha512": "sha512-Ii2bedd4HVzddupdU35n3ygohUPlNn7MDimBOYcwWNce2NizQ1fCSaQJY1Tzv80aMqOGpVcU4wZr/Xe50xcTwg==",
"path": "system.buffers/4.4.0",
"hashPath": "system.buffers.4.4.0.nupkg.sha512"
},
"System.Collections/4.3.0": {
"type": "package",
@@ -1323,10 +1401,17 @@
"System.Diagnostics.Process/4.1.0": {
"type": "package",
"serviceable": true,
"sha512": "sha512-4dlFhzwmI3hl32P+8c9hnytYtV7Xldhsokm5i7Fvv5PmTS68TQCfsuJrREIyF9N1B8zlsSomp7AVrXLe45kKFQ==",
"sha512": "sha512-S2YC+MwpWZ6e7h2lqNce/ubMjD4vf2Ea/uOEncYNH1/fFXaXlKDM9ig/zCE1rR+wwYzE8FXtvj+1Nymh6oZ9bg==",
"path": "system.diagnostics.process/4.1.0",
"hashPath": "system.diagnostics.process.4.1.0.nupkg.sha512"
},
"System.Diagnostics.TextWriterTraceListener/4.0.0": {
"type": "package",
"serviceable": true,
"sha512": "sha512-oRsXCz76GDDMrwjMjH6keR9erFIofhGaIMc2d4NykI4rdBEuUP5ZswYA30LGPdyCK7DV4bMBEJL3nJFyAJoS/g==",
"path": "system.diagnostics.textwritertracelistener/4.0.0",
"hashPath": "system.diagnostics.textwritertracelistener.4.0.0.nupkg.sha512"
},
"System.Diagnostics.Tools/4.3.0": {
"type": "package",
"serviceable": true,
@@ -1337,7 +1422,7 @@
"System.Diagnostics.TraceSource/4.0.0": {
"type": "package",
"serviceable": true,
"sha512": "sha512-bGUeY5wiCHYSWbYZS3QjbaQ1hNoJ1RQBQMB3E0Cgh6AH//4rXfXIOHKIW46HDOsTEDoNfvFNDXphL5W5B/XMwQ==",
"sha512": "sha512-q5bGzzvXVi+dIMiPWRhXZV7r+Os3TEOuRW5LHsAUDGpqJHol8XiLokVpsgAfPqHHNkyx1bbv5lRZqRkRrGZKxQ==",
"path": "system.diagnostics.tracesource/4.0.0",
"hashPath": "system.diagnostics.tracesource.4.0.0.nupkg.sha512"
},
@@ -1460,12 +1545,12 @@
"path": "system.net.primitives/4.3.0",
"hashPath": "system.net.primitives.4.3.0.nupkg.sha512"
},
"System.Net.Security/4.0.0": {
"System.Net.Security/4.3.2": {
"type": "package",
"serviceable": true,
"sha512": "sha512-iavC4j5XrRyX3aXbn23jHHF0NTxw9F+2vi3a94VY4BgfrYm5VQBh8OzU1TkNahTSlcKzjGhEc7ZfTfe4b62J6Q==",
"path": "system.net.security/4.0.0",
"hashPath": "system.net.security.4.0.0.nupkg.sha512"
"sha512": "sha512-xT2jbYpbBo3ha87rViHoTA6WdvqOAW37drmqyx/6LD8p7HEPT2qgdxoimRzWtPg8Jh4X5G9BV2seeTv4x6FYlA==",
"path": "system.net.security/4.3.2",
"hashPath": "system.net.security.4.3.2.nupkg.sha512"
},
"System.Net.Sockets/4.3.0": {
"type": "package",
@@ -1495,19 +1580,19 @@
"path": "system.reflection.emit/4.0.1",
"hashPath": "system.reflection.emit.4.0.1.nupkg.sha512"
},
"System.Reflection.Emit.ILGeneration/4.0.1": {
"System.Reflection.Emit.ILGeneration/4.3.0": {
"type": "package",
"serviceable": true,
"sha512": "sha512-Ov6dU8Bu15Bc7zuqttgHF12J5lwSWyTf1S+FJouUXVMSqImLZzYaQ+vRr1rQ0OZ0HqsrwWl4dsKHELckQkVpgA==",
"path": "system.reflection.emit.ilgeneration/4.0.1",
"hashPath": "system.reflection.emit.ilgeneration.4.0.1.nupkg.sha512"
"sha512": "sha512-59tBslAk9733NXLrUJrwNZEzbMAcu8k344OYo+wfSVygcgZ9lgBdGIzH/nrg3LYhXceynyvTc8t5/GD4Ri0/ng==",
"path": "system.reflection.emit.ilgeneration/4.3.0",
"hashPath": "system.reflection.emit.ilgeneration.4.3.0.nupkg.sha512"
},
"System.Reflection.Emit.Lightweight/4.0.1": {
"System.Reflection.Emit.Lightweight/4.3.0": {
"type": "package",
"serviceable": true,
"sha512": "sha512-sSzHHXueZ5Uh0OLpUQprhr+ZYJrLPA2Cmr4gn0wj9+FftNKXx8RIMKvO9qnjk2ebPYUjZ+F2ulGdPOsvj+MEjA==",
"path": "system.reflection.emit.lightweight/4.0.1",
"hashPath": "system.reflection.emit.lightweight.4.0.1.nupkg.sha512"
"sha512": "sha512-oadVHGSMsTmZsAF864QYN1t1QzZjIcuKU3l2S9cZOwDdDueNTrqq1yRj7koFfIGEnKpt6NjpL3rOzRhs4ryOgA==",
"path": "system.reflection.emit.lightweight/4.3.0",
"hashPath": "system.reflection.emit.lightweight.4.3.0.nupkg.sha512"
},
"System.Reflection.Extensions/4.3.0": {
"type": "package",
@@ -1579,6 +1664,20 @@
"path": "system.runtime.numerics/4.3.0",
"hashPath": "system.runtime.numerics.4.3.0.nupkg.sha512"
},
"System.Runtime.Serialization.Formatters/4.3.0": {
"type": "package",
"serviceable": true,
"sha512": "sha512-KT591AkTNFOTbhZlaeMVvfax3RqhH1EJlcwF50Wm7sfnBLuHiOeZRRKrr1ns3NESkM20KPZ5Ol/ueMq5vg4QoQ==",
"path": "system.runtime.serialization.formatters/4.3.0",
"hashPath": "system.runtime.serialization.formatters.4.3.0.nupkg.sha512"
},
"System.Runtime.Serialization.Primitives/4.3.0": {
"type": "package",
"serviceable": true,
"sha512": "sha512-Wz+0KOukJGAlXjtKr+5Xpuxf8+c8739RI1C+A2BoQZT+wMCCoMDDdO8/4IRHfaVINqL78GO8dW8G2lW/e45Mcw==",
"path": "system.runtime.serialization.primitives/4.3.0",
"hashPath": "system.runtime.serialization.primitives.4.3.0.nupkg.sha512"
},
"System.Security.Claims/4.3.0": {
"type": "package",
"serviceable": true,
@@ -1642,6 +1741,13 @@
"path": "system.text.encoding/4.3.0",
"hashPath": "system.text.encoding.4.3.0.nupkg.sha512"
},
"System.Text.Encoding.CodePages/4.5.1": {
"type": "package",
"serviceable": true,
"sha512": "sha512-4J2JQXbftjPMppIHJ7IC+VXQ9XfEagN92vZZNoG12i+zReYlim5dMoXFC1Zzg7tsnKDM7JPo5bYfFK4Jheq44w==",
"path": "system.text.encoding.codepages/4.5.1",
"hashPath": "system.text.encoding.codepages.4.5.1.nupkg.sha512"
},
"System.Text.Encoding.Extensions/4.3.0": {
"type": "package",
"serviceable": true,
@@ -1666,7 +1772,7 @@
"System.Threading.Overlapped/4.3.0": {
"type": "package",
"serviceable": true,
"sha512": "sha512-JpukcZA7kre2gQ7GrhtvZu1xv/LVEG5HV9AajQ3XV7l36T6ICalw/llfkBHeK/eqo8UWpMNqkWGCzzlSuqE6pg==",
"sha512": "sha512-JWEtWIoYBHzMmgt2I/1e4FFG6veDL4yzA1Y7iuEY2G+GyZyrzqx/GQlM92M+d81D1cH2dp2KRhbZdQebn8Q+RA==",
"path": "system.threading.overlapped/4.3.0",
"hashPath": "system.threading.overlapped.4.3.0.nupkg.sha512"
},
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
+15 -2
View File
@@ -4,7 +4,7 @@ An example of generic repository implementation using the MongoDB C# Sharp 2.0 d
Now available as a nuget package:
https://www.nuget.org/packages/MongoDbGenericRepository/
Covered by 200+ integration tests and counting.
Covered by 400+ integration tests and counting.
The MongoDbGenericRepository is also used in [AspNetCore.Identity.MongoDbCore](https://github.com/alexandre-spieser/AspNetCore.Identity.MongoDbCore).
@@ -40,6 +40,18 @@ Here is an example of repository usage, where the TestRepository is implementing
}
}
```
If all your documents have the same type of `Id`, you can use the more specific `BaseMongoRepository<TKey>` where `TKey` is the type of the `Id` of your documents.
```csharp
public class TestTKeyRepository<TKey> : BaseMongoRepository<TKey>, ITestRepository<TKey> where TKey : IEquatable<TKey>
{
const string connectionString = "mongodb://localhost:27017/MongoDbTests";
private static readonly ITestRepository<TKey> _instance = new TestTKeyRepository<TKey>(connectionString);
/// <inheritdoc />
private TestTKeyRepository(string connectionString) : base(connectionString)
{
}
}
```
## Instantiation
@@ -47,6 +59,7 @@ The repository can be instantiated like so:
```csharp
ITestRepository testRepository = new TestRepository(connectionString, "MongoDbTests");
ITestRepository<TKey> testTKeyRepository = new TestTKeyRepository<TKey>(connectionString);
```
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:
@@ -145,7 +158,7 @@ It is now possible to change the collection name by using the `CollectionName` a
Documents of this type will be inserted into a collection named "MyCollectionName".
## Index Management
From version 1.3.8 the `MongoDbGenericRepository` implements the `IMongoDbCollectionIndexRepository` interface.
From version 1.3.8 the `MongoDbGenericRepository` implements the `IBaseMongoRepository_Index` and `IBaseMongoRepository_Index<TKey>` interfaces.
This exposes the functionality to programmatically manage indexes against your collections in a generic fashion.
The following methods are exposed and fully integration tested: