Last active
July 17, 2020 12:14
-
-
Save mizrael/47b601b0a09d4b6f03f6 to your computer and use it in GitHub Desktop.
simple mongodb repository implementation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class Repository<TEntity> : IRepository<TEntity> | |
{ | |
private readonly IMongoCollection<TEntity> _collection; | |
public Repository(IMongoCollection<TEntity> collection) | |
{ | |
if (null == collection) | |
throw new ArgumentNullException("collection"); | |
_collection = collection; | |
this.CollectionName = collection.CollectionNamespace.CollectionName; | |
} | |
public string CollectionName { get; private set; } | |
public Task<long> CountAsync(FilterDefinition<TEntity> filter) | |
{ | |
return _collection.CountAsync(filter); | |
} | |
public IFindFluent<TEntity, TEntity> Find(FilterDefinition<TEntity> filter) | |
{ | |
return _collection.Find(filter); | |
} | |
public IFindFluent<TEntity, TEntity> Find(Expression<Func<TEntity, bool>> filter) | |
{ | |
return _collection.Find(filter); | |
} | |
public Task<TEntity> FindOneAndReplaceAsync(FilterDefinition<TEntity> filter, TEntity replacement) | |
{ | |
return _collection.FindOneAndReplaceAsync(filter, replacement); | |
} | |
public Task<TEntity> FindOneAndReplaceAsync(Expression<Func<TEntity, bool>> filter, TEntity replacement) | |
{ | |
return _collection.FindOneAndReplaceAsync(filter, replacement); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment