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); } }
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); } }
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); } }
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); } }