public virtual void Remove(int id) { using (var ctx = new ErpContext()) { var obj = ctx.Set<T>().Find(id); ctx.Set<T>().Remove(obj); ctx.SaveChanges(); } }
public virtual T GetSingle(int id) { using (var ctx = new ErpContext()) { return ctx.Set<T>().Find(id); } }
public virtual void Update(T obj) { using (var ctx = new ErpContext()) { ctx.Set<T>().AddOrUpdate(obj); ctx.SaveChanges(); } }
public virtual T Create(T obj) { using (var ctx = new ErpContext()) { var newObj = ctx.Set<T>().Add(obj); ctx.SaveChanges(); return newObj; } }
public virtual List<T> GetAll(Func<T, bool> where = null) { using (var ctx = new ErpContext()) { List<T> baseQuery = ctx.Set<T>().ToList(); if (where != null) baseQuery = baseQuery.Where(where).ToList(); // running filter in-memory, because of non-db fields like displayname's etc. return baseQuery.ToList(); } }