Advertisement
Guest User

Untitled

a guest
Mar 20th, 2019
54
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.38 KB | None | 0 0
  1. using System.Collections.Generic;
  2. using System.Data.Entity;
  3. using System.Linq;
  4. using System.Runtime.Remoting.Contexts;
  5.  
  6. namespace CarService.Repository
  7. {
  8. public class GenericRepository<T> : IRepository<T> where T : class
  9. {
  10. private readonly CarServiceDataModelContainer context = null;
  11. private readonly DbSet<T> table = null;
  12.  
  13. public GenericRepository()
  14. {
  15. this.context = new CarServiceDataModelContainer();
  16. table = context.Set<T>();
  17. }
  18. public GenericRepository(CarServiceDataModelContainer _context)
  19. {
  20. this.context = _context;
  21. table = _context.Set<T>();
  22. }
  23. public IEnumerable<T> GetAll()
  24. {
  25. var x = context.Autoturisme.Local;
  26. return table.ToList();
  27. }
  28. public T GetById(object id)
  29. {
  30. return table.Find(id);
  31. }
  32. public void Insert(T obj)
  33. {
  34. table.Add(obj);
  35. }
  36. public void Update(T obj)
  37. {
  38. table.Attach(obj);
  39. context.Entry(obj).State = EntityState.Modified;
  40. }
  41. public void Delete(object id)
  42. {
  43. T existing = table.Find(id);
  44. table.Remove(existing);
  45. }
  46. public void Save()
  47. {
  48. context.SaveChanges();
  49. }
  50. }
  51. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement