Example #1
0
 public List <T> GetAll()
 {
     using (var context = DbContextCreator.Create())
     {
         return(context.Set <T>().ToList());
     }
 }
Example #2
0
 public int GetCount()
 {
     using (var context = DbContextCreator.Create())
     {
         return(context.Set <T>().Count());
     }
 }
 public T GetByPK(K key)
 {
     using (DbContext context = DbContextCreator.Create())
     {
         return(context.Set <T>().Find(key));
     }
 }
Example #4
0
        public void Delete(T entity)
        {
            using (var context = DbContextCreator.Create())
            {
                context.Entry(entity).State = System.Data.Entity.EntityState.Deleted;

                context.SaveChanges();
            }
        }
Example #5
0
        public void Insert(T entity)
        {
            using (var context = DbContextCreator.Create())
            {
                context.Set <T>().Add(entity);

                context.SaveChanges();
            }
        }
        public K GetMaxKey()
        {
            using (var context = DbContextCreator.Create())
            {
                var query = context.Set <T>()
                            .OrderByDescending(KeySelector)
                            .Select(KeySelector);

                return(query.FirstOrDefault());
            }
        }