TKey support, continued
This commit is contained in:
@@ -7,13 +7,16 @@
|
|||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="15.5.0-preview-20170810-02" />
|
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="15.5.0-preview-20170810-02" />
|
||||||
<PackageReference Include="MongoDB.Driver" Version="2.4.4" />
|
<PackageReference Include="MongoDB.Driver" Version="2.4.4" />
|
||||||
<PackageReference Include="MongoDbGenericRepository" Version="1.2.1" />
|
|
||||||
<PackageReference Include="xunit" Version="2.3.0-beta5-build3769" />
|
<PackageReference Include="xunit" Version="2.3.0-beta5-build3769" />
|
||||||
<PackageReference Include="xunit.runner.console" Version="2.3.0-beta5-build3769" />
|
<PackageReference Include="xunit.runner.console" Version="2.3.0-beta5-build3769" />
|
||||||
<PackageReference Include="xunit.runner.visualstudio" Version="2.3.0-beta5-build3769" />
|
<PackageReference Include="xunit.runner.visualstudio" Version="2.3.0-beta5-build3769" />
|
||||||
<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>
|
||||||
|
|||||||
@@ -7,4 +7,12 @@
|
|||||||
<connectionStrings>
|
<connectionStrings>
|
||||||
<add name="MongoDbTests" connectionString="mongodb://localhost:27017" />
|
<add name="MongoDbTests" connectionString="mongodb://localhost:27017" />
|
||||||
</connectionStrings>
|
</connectionStrings>
|
||||||
|
<runtime>
|
||||||
|
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
|
||||||
|
<dependentAssembly>
|
||||||
|
<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" />
|
||||||
|
</dependentAssembly>
|
||||||
|
</assemblyBinding>
|
||||||
|
</runtime>
|
||||||
</configuration>
|
</configuration>
|
||||||
@@ -31,16 +31,13 @@
|
|||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<Reference Include="MongoDB.Bson, Version=2.4.4.0, Culture=neutral, processorArchitecture=MSIL">
|
<Reference Include="MongoDB.Bson, Version=2.4.4.0, Culture=neutral, processorArchitecture=MSIL">
|
||||||
<HintPath>..\packages\MongoDbGenericRepository.1.2.1\lib\net45\MongoDB.Bson.dll</HintPath>
|
<HintPath>..\packages\MongoDB.Bson.2.4.4\lib\net45\MongoDB.Bson.dll</HintPath>
|
||||||
</Reference>
|
</Reference>
|
||||||
<Reference Include="MongoDB.Driver, Version=2.4.4.0, Culture=neutral, processorArchitecture=MSIL">
|
<Reference Include="MongoDB.Driver, Version=2.4.4.0, Culture=neutral, processorArchitecture=MSIL">
|
||||||
<HintPath>..\packages\MongoDbGenericRepository.1.2.1\lib\net45\MongoDB.Driver.dll</HintPath>
|
<HintPath>..\packages\MongoDB.Driver.2.4.4\lib\net45\MongoDB.Driver.dll</HintPath>
|
||||||
</Reference>
|
</Reference>
|
||||||
<Reference Include="MongoDB.Driver.Core, Version=2.4.4.0, Culture=neutral, processorArchitecture=MSIL">
|
<Reference Include="MongoDB.Driver.Core, Version=2.4.4.0, Culture=neutral, processorArchitecture=MSIL">
|
||||||
<HintPath>..\packages\MongoDbGenericRepository.1.2.1\lib\net45\MongoDB.Driver.Core.dll</HintPath>
|
<HintPath>..\packages\MongoDB.Driver.Core.2.4.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.2.1\lib\net45\MongoDbGenericRepository.dll</HintPath>
|
|
||||||
</Reference>
|
</Reference>
|
||||||
<Reference Include="nunit.framework, Version=3.7.1.0, Culture=neutral, PublicKeyToken=2638cd05610744eb, processorArchitecture=MSIL">
|
<Reference Include="nunit.framework, Version=3.7.1.0, Culture=neutral, PublicKeyToken=2638cd05610744eb, processorArchitecture=MSIL">
|
||||||
<HintPath>..\packages\NUnit.3.7.1\lib\net45\nunit.framework.dll</HintPath>
|
<HintPath>..\packages\NUnit.3.7.1\lib\net45\nunit.framework.dll</HintPath>
|
||||||
@@ -49,8 +46,9 @@
|
|||||||
<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.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
|
<Reference Include="System.Runtime.InteropServices.RuntimeInformation, Version=4.0.1.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
|
||||||
<HintPath>..\packages\MongoDbGenericRepository.1.2.1\lib\net45\System.Runtime.InteropServices.RuntimeInformation.dll</HintPath>
|
<HintPath>..\packages\System.Runtime.InteropServices.RuntimeInformation.4.3.0\lib\net45\System.Runtime.InteropServices.RuntimeInformation.dll</HintPath>
|
||||||
|
<Private>True</Private>
|
||||||
</Reference>
|
</Reference>
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
@@ -78,5 +76,11 @@
|
|||||||
<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>
|
||||||
@@ -3,8 +3,8 @@
|
|||||||
<package id="MongoDB.Bson" version="2.4.4" targetFramework="net461" />
|
<package id="MongoDB.Bson" version="2.4.4" targetFramework="net461" />
|
||||||
<package id="MongoDB.Driver" version="2.4.4" targetFramework="net461" />
|
<package id="MongoDB.Driver" version="2.4.4" targetFramework="net461" />
|
||||||
<package id="MongoDB.Driver.Core" version="2.4.4" targetFramework="net461" />
|
<package id="MongoDB.Driver.Core" version="2.4.4" targetFramework="net461" />
|
||||||
<package id="MongoDbGenericRepository" version="1.2.1" targetFramework="net461" />
|
|
||||||
<package id="NUnit" version="3.7.1" targetFramework="net461" />
|
<package id="NUnit" version="3.7.1" 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.RuntimeInformation" version="4.0.0" targetFramework="net461" />
|
<package id="System.Runtime.InteropServices" version="4.3.0" targetFramework="net461" />
|
||||||
|
<package id="System.Runtime.InteropServices.RuntimeInformation" version="4.3.0" targetFramework="net461" />
|
||||||
</packages>
|
</packages>
|
||||||
@@ -31,6 +31,17 @@ namespace MongoDbGenericRepository
|
|||||||
/// <param name="document">The document you want to add.</param>
|
/// <param name="document">The document you want to add.</param>
|
||||||
Task AddOneAsync<TDocument>(TDocument document) where TDocument : IDocument;
|
Task AddOneAsync<TDocument>(TDocument document) where TDocument : IDocument;
|
||||||
|
|
||||||
|
/// <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>
|
/// <summary>
|
||||||
/// Adds a document to the collection.
|
/// Adds a document to the collection.
|
||||||
/// Populates the Id and AddedAtUtc fields if necessary.
|
/// Populates the Id and AddedAtUtc fields if necessary.
|
||||||
@@ -39,6 +50,17 @@ namespace MongoDbGenericRepository
|
|||||||
/// <param name="document">The document you want to add.</param>
|
/// <param name="document">The document you want to add.</param>
|
||||||
void AddOne<TDocument>(TDocument document) where TDocument : IDocument;
|
void AddOne<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>
|
||||||
|
/// <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>
|
/// <summary>
|
||||||
/// Asynchronously adds a list of documents to the collection.
|
/// Asynchronously adds a list of documents to the collection.
|
||||||
/// Populates the Id and AddedAtUtc fields if necessary.
|
/// Populates the Id and AddedAtUtc fields if necessary.
|
||||||
@@ -419,6 +441,7 @@ namespace MongoDbGenericRepository
|
|||||||
/// The connection string.
|
/// The connection string.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public string ConnectionString { get; set; }
|
public string ConnectionString { get; set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// The database name.
|
/// The database name.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@@ -462,6 +485,21 @@ namespace MongoDbGenericRepository
|
|||||||
await HandlePartitioned(document).InsertOneAsync(document);
|
await HandlePartitioned(document).InsertOneAsync(document);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <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>
|
||||||
|
public async Task AddOneAsync<TDocument, TKey>(TDocument document)
|
||||||
|
where TDocument : IDocument<TKey>
|
||||||
|
where TKey : IEquatable<TKey>
|
||||||
|
{
|
||||||
|
FormatDocument<TDocument, TKey>(document);
|
||||||
|
await HandlePartitioned<TDocument, TKey>(document).InsertOneAsync(document);
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Adds a document to the collection.
|
/// Adds a document to the collection.
|
||||||
/// Populates the Id and AddedAtUtc fields if necessary.
|
/// Populates the Id and AddedAtUtc fields if necessary.
|
||||||
@@ -474,6 +512,21 @@ namespace MongoDbGenericRepository
|
|||||||
HandlePartitioned(document).InsertOne(document);
|
HandlePartitioned(document).InsertOne(document);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <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>
|
||||||
|
public void AddOne<TDocument, TKey>(TDocument document)
|
||||||
|
where TDocument : IDocument<TKey>
|
||||||
|
where TKey : IEquatable<TKey>
|
||||||
|
{
|
||||||
|
FormatDocument<TDocument, TKey>(document);
|
||||||
|
HandlePartitioned<TDocument, TKey>(document).InsertOne(document);
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Asynchronously adds a list of documents to the collection.
|
/// Asynchronously adds a list of documents to the collection.
|
||||||
/// Populates the Id and AddedAtUtc fields if necessary.
|
/// Populates the Id and AddedAtUtc fields if necessary.
|
||||||
@@ -493,6 +546,28 @@ namespace MongoDbGenericRepository
|
|||||||
await HandlePartitioned(documents.FirstOrDefault()).InsertManyAsync(documents);
|
await HandlePartitioned(documents.FirstOrDefault()).InsertManyAsync(documents);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <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>
|
||||||
|
public async Task AddManyAsync<TDocument, TKey>(IEnumerable<TDocument> documents)
|
||||||
|
where TDocument : IDocument<TKey>
|
||||||
|
where TKey : IEquatable<TKey>
|
||||||
|
{
|
||||||
|
if (!documents.Any())
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
foreach (var doc in documents)
|
||||||
|
{
|
||||||
|
FormatDocument<TDocument, TKey>(doc);
|
||||||
|
}
|
||||||
|
await HandlePartitioned<TDocument, TKey>(documents.FirstOrDefault()).InsertManyAsync(documents);
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Adds a list of documents to the collection.
|
/// Adds a list of documents to the collection.
|
||||||
/// Populates the Id and AddedAtUtc fields if necessary.
|
/// Populates the Id and AddedAtUtc fields if necessary.
|
||||||
@@ -643,6 +718,157 @@ namespace MongoDbGenericRepository
|
|||||||
|
|
||||||
#endregion
|
#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>(Guid 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>(Guid 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="filter">A LINQ expression filter.</param>
|
||||||
/// <param name="partitionKey">An optional partitionKey</param>
|
/// <param name="partitionKey">An optional partitionKey</param>
|
||||||
public long Count<TDocument, TKey>(Expression<Func<TDocument, bool>> filter, string partitionKey = null)
|
public long Count<TDocument, TKey>(Expression<Func<TDocument, bool>> filter, string partitionKey = null)
|
||||||
@@ -669,6 +895,38 @@ namespace MongoDbGenericRepository
|
|||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Updates a document.
|
/// 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>
|
||||||
|
public bool UpdateOne<TDocument>(TDocument modifiedDocument) where TDocument : IDocument
|
||||||
|
{
|
||||||
|
var updateRes = HandlePartitioned(modifiedDocument).ReplaceOne(x => x.Id == modifiedDocument.Id, modifiedDocument);
|
||||||
|
return updateRes.ModifiedCount == 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
#endregion Update
|
||||||
|
|
||||||
|
#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>
|
||||||
|
public async Task<bool> UpdateOneAsync<TDocument, TKey>(TDocument modifiedDocument)
|
||||||
|
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(filter, modifiedDocument);
|
||||||
|
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="TKey">The type of the primary key for a Document.</typeparam>
|
||||||
/// <param name="modifiedDocument">The document with the modifications you want to persist.</param>
|
/// <param name="modifiedDocument">The document with the modifications you want to persist.</param>
|
||||||
public bool UpdateOne<TDocument, TKey>(TDocument modifiedDocument)
|
public bool UpdateOne<TDocument, TKey>(TDocument modifiedDocument)
|
||||||
|
|||||||
Reference in New Issue
Block a user