Beispiel #1
0
 public override T FindById(IdT id)
 {
     using (var db = new NgContext())
     {
         var _dbSet = db.Set <T>();
         return(_dbSet.Find(id));
     }
 }
Beispiel #2
0
 public override void Edit(T entity)
 {
     using (var db = new NgContext())
     {
         var dbSet = db.Set <T>();
         dbSet.Update(entity);
     }
 }
Beispiel #3
0
 public override ICollection <T> FindAll()
 {
     using (var db = new NgContext())
     {
         var _dbSet = db.Set <T>();
         return(_dbSet.ToList());
     }
 }
Beispiel #4
0
 public override T Find(Func <T, bool> expression)
 {
     using (var db = new NgContext())
     {
         var _dbSet = db.Set <T>();
         return(_dbSet.FirstOrDefault(expression));
     }
 }
Beispiel #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);
     }
 }
Beispiel #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);
     }
 }
Beispiel #7
0
 public override void Add(T entity)
 {
     using (var db = new NgContext())
     {
         var _dbSet = db.Set <T>();
         _dbSet.Add(entity);
         db.SaveChanges();
     }
 }
Beispiel #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());
     }
 }
Beispiel #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());
     }
 }
Beispiel #10
0
 public override void Save(T entity)
 {
     using (var db = new NgContext())
     {
         var dbSet = db.Set <T>();
         db.Update(entity);
         db.SaveChanges();
     }
 }
Beispiel #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));
     }
 }
Beispiel #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());
     }
 }
Beispiel #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);
     }
 }
Beispiel #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();
     }
 }
Beispiel #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();
     }
 }
Beispiel #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());
     }
 }