Created
October 11, 2017 15:17
-
-
Save cosoria/53be3341a0da610362482d74b604ff5d to your computer and use it in GitHub Desktop.
Base class for Entity Framework Repositories
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 abstract class EntityFrameworkRepository<TEntity> : Disposable, IRepository<TEntity> where TEntity : IEntity | |
{ | |
protected readonly IEntityFrameworkUnitOfWork _uow; | |
protected readonly IEntityFrameworkContext _context; | |
protected EntityFrameworkRepository(IEntityFrameworkUnitOfWork uow) | |
{ | |
_uow = uow; | |
_context = uow.Context; | |
} | |
public abstract TEntity Get(object key); | |
public abstract IEnumerable<TEntity> GetAll(); | |
public abstract IEnumerable<TEntity> GetAllMatching(Expression<Func<TEntity, bool>> filter); | |
public void Add(TEntity entry) | |
{ | |
_context.MarkAsAdded(entry); | |
} | |
public void Delete(object key) | |
{ | |
var entry = Get(key); | |
_context.MarkAsDeleted(entry); | |
} | |
public void Update(TEntity entry) | |
{ | |
_context.MarkAsModified(entry); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment