Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

taking latest updates from original repo. #1

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 10 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
Simple repository pattern for [DocumentDB](https://azure.microsoft.com/en-us/services/documentdb/)
Simple repository pattern for [Cosmos DB](https://azure.microsoft.com/en-us/services/cosmos-db/)

[![Nuget](https://img.shields.io/badge/nuget-1.1.0-blue.svg?maxAge=3600)](https://www.nuget.org/packages/DocumentDB.Repository/1.1.0)
[![Nuget](https://img.shields.io/badge/nuget-1.2.0-blue.svg?maxAge=3600)](https://www.nuget.org/packages/DocumentDB.Repository/1.2.0)

# Installation

Use NuGet to install the [package](https://www.nuget.org/packages/DocumentDB.Repository/1.1.0).
Use NuGet to install the [package](https://www.nuget.org/packages/DocumentDB.Repository/1.2.0).

```
PM> Install-Package DocumentDB.Repository
Expand Down Expand Up @@ -100,7 +100,13 @@ private static async Task MainAsync(string[] args)

// query all the smiths
var smiths = (await repo.WhereAsync(p => p.LastName.Equals("Smith", StringComparison.OrdinalIgnoreCase))).ToList();

// count all persons
var personsCount = await repo.CountAsync();

// count all jacks
var jacksCount = await repo.CountAsync(p => p.FirstName == "Jack");

// remove matt from collection
await repo.RemoveAsync(matt.Id);

Expand All @@ -113,4 +119,4 @@ Full example can be found [here](https://github.com/Crokus/documentdb-repo/blob/

# License

documentdb-repo is provided under the MIT license.
cosmosdb-repo is provided under the MIT license.
2 changes: 1 addition & 1 deletion src/DocumentDb.Repository.Samples/App.config
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly>
<assemblyIdentity name="Microsoft.Azure.Documents.Client" publicKeyToken="31bf3856ad364e35" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-1.11.0.0" newVersion="1.11.0.0" />
<bindingRedirect oldVersion="0.0.0.0-1.14.0.0" newVersion="1.14.0.0" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="Newtonsoft.Json" publicKeyToken="30ad4fe6b2a6aeed" culture="neutral" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,8 @@
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<ItemGroup>
<Reference Include="Microsoft.Azure.Documents.Client, Version=1.11.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
<HintPath>..\packages\Microsoft.Azure.DocumentDB.1.11.3\lib\net45\Microsoft.Azure.Documents.Client.dll</HintPath>
<Private>True</Private>
<Reference Include="Microsoft.Azure.Documents.Client, Version=1.14.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
<HintPath>..\packages\Microsoft.Azure.DocumentDB.1.14.1\lib\net45\Microsoft.Azure.Documents.Client.dll</HintPath>
</Reference>
<Reference Include="Microsoft.Azure.Documents.Client.TransientFaultHandling, Version=1.5.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
<HintPath>..\packages\Microsoft.Azure.DocumentDB.TransientFaultHandling.1.5.0\lib\net45\Microsoft.Azure.Documents.Client.TransientFaultHandling.dll</HintPath>
Expand Down Expand Up @@ -75,12 +74,12 @@
</ProjectReference>
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<Import Project="..\packages\Microsoft.Azure.DocumentDB.1.11.3\build\Microsoft.Azure.DocumentDB.targets" Condition="Exists('..\packages\Microsoft.Azure.DocumentDB.1.11.3\build\Microsoft.Azure.DocumentDB.targets')" />
<Import Project="..\packages\Microsoft.Azure.DocumentDB.1.14.1\build\Microsoft.Azure.DocumentDB.targets" Condition="Exists('..\packages\Microsoft.Azure.DocumentDB.1.14.1\build\Microsoft.Azure.DocumentDB.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\Microsoft.Azure.DocumentDB.1.11.3\build\Microsoft.Azure.DocumentDB.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\Microsoft.Azure.DocumentDB.1.11.3\build\Microsoft.Azure.DocumentDB.targets'))" />
<Error Condition="!Exists('..\packages\Microsoft.Azure.DocumentDB.1.14.1\build\Microsoft.Azure.DocumentDB.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\Microsoft.Azure.DocumentDB.1.14.1\build\Microsoft.Azure.DocumentDB.targets'))" />
</Target>
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.
Expand Down
8 changes: 7 additions & 1 deletion src/DocumentDb.Repository.Samples/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,12 @@ private static async Task MainAsync(string[] args)
Console.WriteLine(phone);
}

// count all persons
var personsCount = await repo.CountAsync();

// count all jacks
var jacksCount = await repo.CountAsync(p => p.FirstName == "Jack");

// remove matt from collection
await repo.RemoveAsync(matt.FullName);

Expand All @@ -111,7 +117,7 @@ private static async Task MainAsync(string[] args)

// should output nothing
await PrintPersonCollection(repo);

// remove collection
await repo.RemoveAsync();
}
Expand Down
2 changes: 1 addition & 1 deletion src/DocumentDb.Repository.Samples/packages.config
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="EnterpriseLibrary.TransientFaultHandling" version="6.0.1304.0" targetFramework="net45" />
<package id="Microsoft.Azure.DocumentDB" version="1.11.3" targetFramework="net45" />
<package id="Microsoft.Azure.DocumentDB" version="1.14.1" targetFramework="net45" />
<package id="Microsoft.Azure.DocumentDB.TransientFaultHandling" version="1.5.0" targetFramework="net45" />
<package id="Newtonsoft.Json" version="9.0.1" targetFramework="net45" />
</packages>
10 changes: 5 additions & 5 deletions src/DocumentDb.Repository/DocumentDb.Repository.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,8 @@
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<ItemGroup>
<Reference Include="Microsoft.Azure.Documents.Client, Version=1.11.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
<HintPath>..\packages\Microsoft.Azure.DocumentDB.1.11.3\lib\net45\Microsoft.Azure.Documents.Client.dll</HintPath>
<Private>True</Private>
<Reference Include="Microsoft.Azure.Documents.Client, Version=1.14.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
<HintPath>..\packages\Microsoft.Azure.DocumentDB.1.14.1\lib\net45\Microsoft.Azure.Documents.Client.dll</HintPath>
</Reference>
<Reference Include="Microsoft.Azure.Documents.Client.TransientFaultHandling, Version=1.5.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
<HintPath>..\packages\Microsoft.Azure.DocumentDB.TransientFaultHandling.1.5.0\lib\net45\Microsoft.Azure.Documents.Client.TransientFaultHandling.dll</HintPath>
Expand All @@ -57,6 +56,7 @@
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="IDocumentDbRepository.cs" />
<Compile Include="Infrastructure\AsyncLazy.cs" />
<Compile Include="DocumentDbRepository.cs" />
<Compile Include="DocumentDbInitializer.cs" />
Expand All @@ -68,12 +68,12 @@
<None Include="packages.config" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<Import Project="..\packages\Microsoft.Azure.DocumentDB.1.11.3\build\Microsoft.Azure.DocumentDB.targets" Condition="Exists('..\packages\Microsoft.Azure.DocumentDB.1.11.3\build\Microsoft.Azure.DocumentDB.targets')" />
<Import Project="..\packages\Microsoft.Azure.DocumentDB.1.14.1\build\Microsoft.Azure.DocumentDB.targets" Condition="Exists('..\packages\Microsoft.Azure.DocumentDB.1.14.1\build\Microsoft.Azure.DocumentDB.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\Microsoft.Azure.DocumentDB.1.11.3\build\Microsoft.Azure.DocumentDB.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\Microsoft.Azure.DocumentDB.1.11.3\build\Microsoft.Azure.DocumentDB.targets'))" />
<Error Condition="!Exists('..\packages\Microsoft.Azure.DocumentDB.1.14.1\build\Microsoft.Azure.DocumentDB.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\Microsoft.Azure.DocumentDB.1.14.1\build\Microsoft.Azure.DocumentDB.targets'))" />
</Target>
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.
Expand Down
11 changes: 8 additions & 3 deletions src/DocumentDb.Repository/DocumentDbRepository.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@

namespace DocumentDB.Repository
{
public class DocumentDbRepository<T> where T : class
public class DocumentDbRepository<T> : IDocumentDbRepository<T> where T : class
{
private readonly IReliableReadWriteDocumentClient _client;
private readonly string _databaseId;
Expand Down Expand Up @@ -81,9 +81,14 @@ public async Task<T> AddOrUpdateAsync(T entity, RequestOptions requestOptions =
return upsertedEntity;
}

public async Task<long> CountAsync()
public async Task<int> CountAsync()
{
return _client.CreateDocumentQuery<T>((await _collection).SelfLink).AsEnumerable().LongCount();
return _client.CreateDocumentQuery<T>((await _collection).SelfLink).Count();
}

public async Task<int> CountAsync(Expression<Func<T, bool>> predicate)
{
return _client.CreateDocumentQuery<T>((await _collection).SelfLink).Where(predicate).Count();
}

public async Task<IEnumerable<T>> GetAllAsync()
Expand Down
23 changes: 23 additions & 0 deletions src/DocumentDb.Repository/IDocumentDbRepository.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
using Microsoft.Azure.Documents.Client;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Linq.Expressions;
using System.Threading.Tasks;

namespace DocumentDB.Repository
{
public interface IDocumentDbRepository<T> where T : class
{
Task<bool> RemoveAsync(RequestOptions requestOptions = null);
Task<bool> RemoveAsync(string id, RequestOptions requestOptions = null);
Task<T> AddOrUpdateAsync(T entity, RequestOptions requestOptions = null);
Task<int> CountAsync();
Task<int> CountAsync(Expression<Func<T, bool>> predicate);
Task<IEnumerable<T>> GetAllAsync();
Task<T> GetByIdAsync(string id);
Task<T> FirstOrDefaultAsync(Func<T, bool> predicate);
Task<IQueryable<T>> WhereAsync(Expression<Func<T, bool>> predicate);
Task<IQueryable<T>> QueryAsync();
}
}
2 changes: 1 addition & 1 deletion src/DocumentDb.Repository/app.config
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly>
<assemblyIdentity name="Microsoft.Azure.Documents.Client" publicKeyToken="31bf3856ad364e35" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-1.11.0.0" newVersion="1.11.0.0" />
<bindingRedirect oldVersion="0.0.0.0-1.14.0.0" newVersion="1.14.0.0" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="Newtonsoft.Json" publicKeyToken="30ad4fe6b2a6aeed" culture="neutral" />
Expand Down
2 changes: 1 addition & 1 deletion src/DocumentDb.Repository/packages.config
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="EnterpriseLibrary.TransientFaultHandling" version="6.0.1304.0" targetFramework="net45" />
<package id="Microsoft.Azure.DocumentDB" version="1.11.3" targetFramework="net45" />
<package id="Microsoft.Azure.DocumentDB" version="1.14.1" targetFramework="net45" />
<package id="Microsoft.Azure.DocumentDB.TransientFaultHandling" version="1.5.0" targetFramework="net45" />
<package id="Newtonsoft.Json" version="9.0.1" targetFramework="net45" />
</packages>