示例#1
0
 public bool Delete <T>(T entity) where T : BaseModel
 {
     using (HContext dbContext = new HContext())
     {
         dbContext.Set <T>().Attach(entity);
         dbContext.Entry <T>(entity).State = EntityState.Deleted;
         int result = dbContext.SaveChanges();
         return(result > 0);
     }
 }
示例#2
0
 public T Add <T>(T entity) where T : BaseModel
 {
     using (HContext dbContext = new HContext())
     {
         dbContext.Set <T>().Attach(entity);
         dbContext.Entry <T>(entity).State = EntityState.Added;
         dbContext.SaveChanges();
         return(entity);
     }
 }
示例#3
0
 public bool Update <T>(IList <T> entityList) where T : BaseModel
 {
     using (HContext dbContext = new HContext())
     {
         foreach (var entity in entityList)
         {
             dbContext.Set <T>().Attach(entity);
             dbContext.Entry <T>(entity).State = EntityState.Modified;
         }
         int result = dbContext.SaveChanges();
         return(result > 0);
     }
 }
示例#4
0
 public IList <T> Add <T>(IList <T> entityList) where T : BaseModel
 {
     using (HContext dbContext = new HContext())
     {
         foreach (T entity in entityList)
         {
             dbContext.Set <T>().Attach(entity);
             dbContext.Entry <T>(entity).State = EntityState.Added;
         }
         dbContext.SaveChanges();
         return(entityList);
     }
 }