public void Delete(object id) { using (var context = new HSERPEntities(_connectString)) { TEntity entity = context.Set <TEntity>().Find(id); context.Set <TEntity>().Remove(entity); Save(context); } }
public void Delete(List <long?> parametersId) { using (var context = new HSERPEntities(_connectString)) { foreach (var id in parametersId) { TEntity entity = context.Set <TEntity>().Find(id); context.Set <TEntity>().Remove(entity); } Save(context); } }
public TEntity GetById(object id) { using (var context = new HSERPEntities(_connectString)) { try { return(context.Set <TEntity>().Find(id)); } catch { return(null); } } }
public void Update(TEntity parameter) { using (var context = new HSERPEntities(_connectString)) { try { context.Set <TEntity>().Attach(parameter); context.Entry(parameter).State = EntityState.Modified; context.SaveChanges(); } catch (Exception e) { Debug.WriteLine(e.Message); } } }
public IEnumerable <TEntity> GetAll() { using (var context = new HSERPEntities(_connectString)) { try { var list = context.Set <TEntity>().ToList(); return(list); } catch (Exception e) { Console.WriteLine(e.InnerException.Message); return(null); } } }
public TEntity Insert(TEntity parameter) { using (var context = new HSERPEntities(_connectString)) { try { var para = context.Set <TEntity>().Add(parameter); context.SaveChanges(); return(para); } catch (DbUpdateException e) { Console.WriteLine(e.InnerException.Message); return(null); } } }
public void Insert(List <TEntity> parameters) { using (var context = new HSERPEntities(_connectString)) { try { foreach (var info in parameters) { context.Set <TEntity>().Add(info); } context.SaveChanges(); } catch (DbUpdateException e) { Console.WriteLine(e.InnerException.Message); } } }
public void Update(List <TEntity> parameters) { using (var context = new HSERPEntities(_connectString)) { try { foreach (var info in parameters) { context.Set <TEntity>().Attach(info); context.Entry(info).State = EntityState.Modified; } context.SaveChanges(); } catch (Exception e) { Debug.WriteLine(e.Message); } } }