예제 #1
0
 public override T FindById(IdT id)
 {
     using (var db = new NgContext())
     {
         var _dbSet = db.Set <T>();
         return(_dbSet.Find(id));
     }
 }
예제 #2
0
 public override void Edit(T entity)
 {
     using (var db = new NgContext())
     {
         var dbSet = db.Set <T>();
         dbSet.Update(entity);
     }
 }
예제 #3
0
 public override ICollection <T> FindAll()
 {
     using (var db = new NgContext())
     {
         var _dbSet = db.Set <T>();
         return(_dbSet.ToList());
     }
 }
예제 #4
0
 public override T Find(Func <T, bool> expression)
 {
     using (var db = new NgContext())
     {
         var _dbSet = db.Set <T>();
         return(_dbSet.FirstOrDefault(expression));
     }
 }
예제 #5
0
 public override T Find(Expression <Func <T, object> > expression, Func <object, bool> func)
 {
     using (var db = new NgContext())
     {
         var _dbSet = db.Set <T>().Select(expression).AsEnumerable().FirstOrDefault(func);
         return((T)_dbSet);
     }
 }
예제 #6
0
 public override T Find(Expression <Func <T, object> > expression, int id)
 {
     using (var db = new NgContext())
     {
         var _dbSet = db.Set <T>().Select(expression).ToList().FirstOrDefault(t => (t as T).Id == id);
         return((T)_dbSet);
     }
 }
예제 #7
0
 public override void Add(T entity)
 {
     using (var db = new NgContext())
     {
         var _dbSet = db.Set <T>();
         _dbSet.Add(entity);
         db.SaveChanges();
     }
 }
예제 #8
0
 public override ICollection <T> FindAll(Expression <Func <T, object> > expression)
 {
     using (var db = new NgContext())
     {
         db.ChangeTracker.QueryTrackingBehavior = QueryTrackingBehavior.NoTracking;
         var _dbSet = db.Set <T>().Select(expression).AsNoTracking().ToList();
         return(_dbSet.Cast <T>().ToList());
     }
 }
예제 #9
0
 public override ICollection <T> FindAll()
 {
     using (var db = new NgContext())
     {
         db.ChangeTracker.QueryTrackingBehavior = QueryTrackingBehavior.NoTracking;
         var _dbSet = db.Set <T>();
         return(_dbSet.ToList());
     }
 }
예제 #10
0
 public override void Save(T entity)
 {
     using (var db = new NgContext())
     {
         var dbSet = db.Set <T>();
         db.Update(entity);
         db.SaveChanges();
     }
 }
예제 #11
0
 public override T FindById(int id)
 {
     using (var db = new NgContext())
     {
         db.ChangeTracker.QueryTrackingBehavior = QueryTrackingBehavior.NoTracking;
         var _dbSet = db.Set <T>();
         return(_dbSet.Find(id));
     }
 }
예제 #12
0
 public override ICollection <T> FindAll(Func <T, bool> expression)
 {
     using (var db = new NgContext())
     {
         db.ChangeTracker.QueryTrackingBehavior = QueryTrackingBehavior.NoTracking;
         var _dbSet = db.Set <T>();
         return(_dbSet.ToList().Where(expression).ToList());
     }
 }
예제 #13
0
 public override int Add(T entity)
 {
     using (var db = new NgContext())
     {
         var _dbSet = db.Set <T>();
         var item   = _dbSet.Add(entity);
         db.SaveChanges();
         return(item.Entity.Id);
     }
 }
예제 #14
0
 public override void Delete(IdT id)
 {
     using (var db = new NgContext())
     {
         var dbSet = db.Set <T>();
         dbSet.Remove(new T()
         {
             Id = id
         });
         db.SaveChanges();
     }
 }
예제 #15
0
 public override void Delete(int id)
 {
     using (var db = new NgContext())
     {
         db.ChangeTracker.QueryTrackingBehavior = QueryTrackingBehavior.NoTracking;
         var dbSet = db.Set <T>();
         dbSet.Remove(new T()
         {
             Id = id
         });
         db.SaveChanges();
     }
 }
예제 #16
0
 public override ICollection <T> FindAll(EntityExpression <T> entityExpression, Func <T, bool> func = null)
 {
     using (var db = new NgContext())
     {
         var _dbSet = db.Set <T>().Include(entityExpression.ExpressionList.First());
         foreach (var exp in entityExpression.ExpressionList)
         {
             _dbSet = _dbSet.Include(exp);
         }
         if (func != null)
         {
             return(_dbSet.Where(func).ToList());
         }
         return(_dbSet.ToList());
     }
 }