Advertisement
Guest User

Untitled

a guest
Sep 25th, 2017
60
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.64 KB | None | 0 0
  1. public interface IRepository<T>
  2. {
  3. void Add(T item);
  4. T Find(object id);
  5. IEnumerable<T> List();
  6. }
  7.  
  8. public class PostgresqlRepository<T,K> : IRepository<T> where T : class
  9. where K : DbContext,new()
  10. {
  11. public void Add(T item)
  12. {
  13. using (var db = new K())
  14. {
  15. db.Set<T>().Add(item);
  16. db.SaveChanges();
  17. }
  18. }
  19.  
  20. public T Find(object id)
  21. {
  22. using (var db = new K())
  23. {
  24. return db.Set<T>().Find(id);
  25. }
  26. }
  27.  
  28. public IEnumerable<T> List()
  29. {
  30. using (var db = new K())
  31. {
  32. return db.Set<T>().ToList();
  33. }
  34. }
  35. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement