Skip to content
This repository was archived by the owner on Feb 22, 2020. It is now read-only.
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
18 changes: 12 additions & 6 deletions MongoRepository/MongoRepository.Net45.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -40,16 +40,16 @@
<DocumentationFile>bin\Release\MongoRepository.Net45.xml</DocumentationFile>
</PropertyGroup>
<ItemGroup>
<Reference Include="MongoDB.Bson, Version=2.2.0.262, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\packages\MongoDB.Bson.2.2.0\lib\net45\MongoDB.Bson.dll</HintPath>
<Reference Include="MongoDB.Bson, Version=2.2.4.26, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\packages\MongoDB.Bson.2.2.4\lib\net45\MongoDB.Bson.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="MongoDB.Driver, Version=2.2.0.262, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\packages\MongoDB.Driver.2.2.0\lib\net45\MongoDB.Driver.dll</HintPath>
<Reference Include="MongoDB.Driver, Version=2.2.4.26, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\packages\MongoDB.Driver.2.2.4\lib\net45\MongoDB.Driver.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="MongoDB.Driver.Core, Version=2.2.0.262, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\packages\MongoDB.Driver.Core.2.2.0\lib\net45\MongoDB.Driver.Core.dll</HintPath>
<Reference Include="MongoDB.Driver.Core, Version=2.2.4.26, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\packages\MongoDB.Driver.Core.2.2.4\lib\net45\MongoDB.Driver.Core.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="System" />
Expand All @@ -62,6 +62,7 @@
<Compile Include="CollectionName.cs" />
<Compile Include="Entity.cs" />
<Compile Include="IEntity.cs" />
<Compile Include="Repository\IRepositoryAsync.cs" />
<Compile Include="RepositoryManager\CollectionStatsResult.cs" />
<Compile Include="RepositoryManager\IRepositoryManager.cs" />
<Compile Include="RepositoryManager\MongoRepositoryManager.cs" />
Expand All @@ -79,6 +80,11 @@
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<Import Project="$(SolutionDir)\.nuget\NuGet.targets" Condition="Exists('$(SolutionDir)\.nuget\NuGet.targets')" />
<Import Project="..\packages\OctoPack.3.0.71\tools\OctoPack.targets" Condition="Exists('..\packages\OctoPack.3.0.71\tools\OctoPack.targets')" />
<Target Name="EnsureOctoPackImported" BeforeTargets="BeforeBuild" Condition="'$(OctoPackImported)' == ''">
<Error Condition="!Exists('..\packages\OctoPack.3.0.71\tools\OctoPack.targets') And ('$(RunOctoPack)' != '' And $(RunOctoPack))" Text="You are trying to build with OctoPack, but the NuGet targets file that OctoPack depends on is not available on this computer. This is probably because the OctoPack package has not been committed to source control, or NuGet Package Restore is not enabled. Please enable NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=317567." HelpKeyword="BCLBUILD2001" />
<Error Condition="Exists('..\packages\OctoPack.3.0.71\tools\OctoPack.targets') And ('$(RunOctoPack)' != '' And $(RunOctoPack))" Text="OctoPack cannot be run because NuGet packages were restored prior to the build running, and the targets file was unavailable when the build started. Please build the project again to include these packages in the build. You may also need to make sure that your build server does not delete packages prior to each build. For more information, see http://go.microsoft.com/fwlink/?LinkID=317568." HelpKeyword="BCLBUILD2002" />
</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.
<Target Name="BeforeBuild">
Expand Down
94 changes: 94 additions & 0 deletions MongoRepository/Repository/IRepositoryAsync.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
namespace MongoRepository
{
using MongoDB.Driver;
using MongoDB.Driver.Linq;
using System;
using System.Collections.Generic;
using System.Linq.Expressions;
using System.Threading.Tasks;


public interface IRepositoryAsync<T, TKey> : IRepository<T, TKey>
where T : IEntity<TKey>
{
Task<T> GetByIdAsync(TKey id);

/// <summary>
/// Returns all of the entities in the repository.
/// </summary>
/// <returns>A List of type T containing all of the entities in the repository.</returns>
Task<List<T>> GetAllAsync();

/// <summary>
/// Adds the new entity in the repository.
/// </summary>
/// <param name="entity">The entity to add.</param>
/// <returns>The added entity including its new ObjectId.</returns>
Task<T> AddAsync(T entity);

/// <summary>
/// Adds the new entities in the repository.
/// </summary>
/// <param name="entities">The entities of type T.</param>
Task AddAsync(IEnumerable<T> entities);

/// <summary>
/// Upserts an entity.
/// </summary>
/// <param name="entity">The entity.</param>
/// <returns>The updated entity.</returns>
Task<T> UpdateAsync(T entity);

/// <summary>
/// Upserts the entities.
/// </summary>
/// <param name="entities">The entities to update.</param>
Task UpdateAsync(IEnumerable<T> entities);

/// <summary>
/// Deletes the given entity.
/// </summary>
/// <param name="entity">The entity to delete.</param>
Task<DeleteResult> DeleteAsync(TKey Id);

/// <summary>
/// Deletes the given entity.
/// </summary>
/// <param name="entity">The entity to delete.</param>
Task<DeleteResult> DeleteAsync(T entity);

/// <summary>
/// Deletes the entities matching the predicate.
/// </summary>
/// <param name="predicate">The expression.</param>
Task<DeleteResult> DeleteAsync(Expression<Func<T, bool>> predicate);

/// <summary>
/// Deletes all entities in the repository.
/// </summary>
Task<DeleteResult> DeleteAllAsync();

/// <summary>
/// Counts the total entities in the repository.
/// </summary>
/// <returns>Count of entities in the repository.</returns>
Task<long> CountAsync();

/// <summary>
/// Checks if the entity exists for given predicate.
/// </summary>
/// <param name="predicate">The expression.</param>
/// <returns>True when an entity matching the predicate exists, false otherwise.</returns>
Task<bool> ExistsAsync(Expression<Func<T, bool>> predicate);

}

/// <summary>
/// IRepository definition.
/// </summary>
/// <typeparam name="T">The type contained in the repository.</typeparam>
/// <remarks>Entities are assumed to use strings for Id's.</remarks>
public interface IRepositoryAsync<T> : IRepositoryAsync<T, string>
where T : IEntity<string>
{ }
}
Loading