示例#1
0
 public IEnumerable <GenericEntity> GetAll()
 {
     try
     {
         using (var ctx = new KitControleContext())
         {
             return(ctx.Set <GenericEntity>().ToList());
         }
     }
     catch (DbUpdateException duEx)
     {
         throw new Exception("Erro ao executar comando no Entity", new Exception(duEx.ToString()));
     }
     catch (DbEntityValidationException dEx)
     {
         throw new Exception("Erro ao executar comando no Entity", new Exception(dEx.ToString()));
     }
     catch (Exception ex)
     {
         throw new Exception("Erro ao executar comando no Entity", ex);
     }
 }
示例#2
0
 public GenericEntity GetById(int Id)
 {
     try
     {
         using (var ctx = new KitControleContext())
         {
             return(ctx.Set <GenericEntity>().Find(Id));
         }
     }
     catch (DbUpdateException duEx)
     {
         throw new Exception("Erro ao executar comando no Entity", new Exception(duEx.ToString()));
     }
     catch (DbEntityValidationException dEx)
     {
         throw new Exception("Erro ao executar comando no Entity", new Exception(dEx.ToString()));
     }
     catch (Exception ex)
     {
         throw new Exception("Erro ao executar comando no Entity", ex);
     }
 }
示例#3
0
 public void Alterar(GenericEntity entity)
 {
     try
     {
         using (var ctx = new KitControleContext())
         {
             ctx.Entry(entity).State = EntityState.Modified;
             ctx.SaveChanges();
         }
     }
     catch (DbUpdateException duEx)
     {
         throw new Exception("Erro ao executar comando no Entity", new Exception(duEx.ToString()));
     }
     catch (DbEntityValidationException dEx)
     {
         throw new Exception("Erro ao executar comando no Entity", new Exception(dEx.ToString()));
     }
     catch (Exception ex)
     {
         throw new Exception("Erro ao executar comando no Entity", ex);
     }
 }
示例#4
0
 public void Remover(GenericEntity entity)
 {
     try
     {
         using (var ctx = new KitControleContext())
         {
             ctx.Set <GenericEntity>().Remove(entity);
             ctx.SaveChanges();
         }
     }
     catch (DbUpdateException duEx)
     {
         throw new Exception("Erro ao executar comando no Entity", new Exception(duEx.ToString()));
     }
     catch (DbEntityValidationException dEx)
     {
         throw new Exception("Erro ao executar comando no Entity", new Exception(dEx.ToString()));
     }
     catch (Exception ex)
     {
         throw new Exception("Erro ao executar comando no Entity", ex);
     }
 }