Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System.Collections.Generic;
- using System.Data.Entity;
- using System.Linq;
- using System.Runtime.Remoting.Contexts;
- namespace CarService.Repository
- {
- public class GenericRepository<T> : IRepository<T> where T : class
- {
- private readonly CarServiceDataModelContainer context = null;
- private readonly DbSet<T> table = null;
- public GenericRepository()
- {
- this.context = new CarServiceDataModelContainer();
- table = context.Set<T>();
- }
- public GenericRepository(CarServiceDataModelContainer _context)
- {
- this.context = _context;
- table = _context.Set<T>();
- }
- public IEnumerable<T> GetAll()
- {
- var x = context.Autoturisme.Local;
- return table.ToList();
- }
- public T GetById(object id)
- {
- return table.Find(id);
- }
- public void Insert(T obj)
- {
- table.Add(obj);
- }
- public void Update(T obj)
- {
- table.Attach(obj);
- context.Entry(obj).State = EntityState.Modified;
- }
- public void Delete(object id)
- {
- T existing = table.Find(id);
- table.Remove(existing);
- }
- public void Save()
- {
- context.SaveChanges();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement