示例#1
0
 public List <T> GetAll()
 {
     using (var context = DbContextCreator.Create())
     {
         return(context.Set <T>().ToList());
     }
 }
示例#2
0
 public T GetByPK(K key)
 {
     using (DbContext context = DbContextCreator.Create())
     {
         return(context.Set <T>().Find(key));
     }
 }
示例#3
0
 public int GetCount()
 {
     using (var context = DbContextCreator.Create())
     {
         return(context.Set <T>().Count());
     }
 }
 public T GetByPK(K1 key1, K2 key2, K3 key3)
 {
     using (var context = DbContextCreator.Create())
     {
         return(context
                .Set <T>()
                .Find(key1, key2, key3));
     }
 }
 public T GetByPK(K key)
 {
     using (var context = DbContextCreator.Create())
     {
         return(context.Set <T>()
                .Where(IsKey(key))
                .FirstOrDefault());
     }
 }
示例#6
0
        public void Delete(T entity)
        {
            using (var context = DbContextCreator.Create())
            {
                context.Entry(entity).State = System.Data.Entity.EntityState.Deleted;

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

                context.SaveChanges();
            }
        }
示例#8
0
        public void Update(T entity)
        {
            using (var context = DbContextCreator.Context())
            {
                context.Entry(entity).State = System.Data.Entity.EntityState.Modified;

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

                return(query.FirstOrDefault());
            }
        }
        public T GetByPK(K1 key1, K2 key2, K3 key3)
        {
            using (var context = DbContextCreator.Create())
            {
                var query = context
                            .Set <T>()
                            .Where(IsKey(key1, key2, key3))
                            .Select(x => x);

                return(query.FirstOrDefault());
            }
        }