예제 #1
0
 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();
     }
 }
예제 #2
0
 public virtual T GetSingle(int id)
 {
     using (var ctx = new ErpContext())
     {
         return ctx.Set<T>().Find(id);
     }
 }
예제 #3
0
 public virtual void Update(T obj)
 {
     using (var ctx = new ErpContext())
     {
         ctx.Set<T>().AddOrUpdate(obj);
         ctx.SaveChanges();
     }
 }
예제 #4
0
 public virtual T Create(T obj)
 {
     using (var ctx = new ErpContext())
     {
         var newObj = ctx.Set<T>().Add(obj);
         ctx.SaveChanges();
         return newObj;
     }
 }
예제 #5
0
        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();
            }
        }