Skip to content

Instantly share code, notes, and snippets.

@NMZivkovic
Created April 15, 2018 18:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save NMZivkovic/4bfcfc1de1b8e7790e16fd1892f0b655 to your computer and use it in GitHub Desktop.
Save NMZivkovic/4bfcfc1de1b8e7790e16fd1892f0b655 to your computer and use it in GitHub Desktop.
public class Repository<TEntity> : IReporitory<TEntity> where TEntity : class
{
protected readonly DbContext Context;
protected readonly DbSet<TEntity> Entities;
public Repository(DbContext context)
{
Context = context;
Entities = Context.Set<TEntity>();
}
public void Add(TEntity entity)
{
Entities.Add(entity);
}
public void Remove(TEntity entity)
{
Entities.Remove(entity);
}
public TEntity Get(int id)
{
return Entities.Find(id);
}
public IEnumerable<TEntity> GetAll()
{
return Entities.ToList();
}
public IEnumerable<TEntity> Find(Expression<Func<TEntity, bool>> predicate)
{
return Entities.Where(predicate);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment