Guest User

Untitled

a guest
Apr 23rd, 2018
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.74 KB | None | 0 0
  1. public class Repository<TEntity> : IReporitory<TEntity> where TEntity : class
  2. {
  3. protected readonly DbContext Context;
  4. protected readonly DbSet<TEntity> Entities;
  5.  
  6. public Repository(DbContext context)
  7. {
  8. Context = context;
  9. Entities = Context.Set<TEntity>();
  10. }
  11.  
  12. public void Add(TEntity entity)
  13. {
  14. Entities.Add(entity);
  15. }
  16.  
  17. public void Remove(TEntity entity)
  18. {
  19. Entities.Remove(entity);
  20. }
  21.  
  22. public TEntity Get(int id)
  23. {
  24. return Entities.Find(id);
  25. }
  26.  
  27. public IEnumerable<TEntity> GetAll()
  28. {
  29. return Entities.ToList();
  30. }
  31.  
  32. public IEnumerable<TEntity> Find(Expression<Func<TEntity, bool>> predicate)
  33. {
  34. return Entities.Where(predicate);
  35. }
  36. }
Add Comment
Please, Sign In to add comment