public void Deletar(Aluguel aluguel) { DbEntityEntry dbEntityEntry = _contexto.Entry(aluguel); if (dbEntityEntry.State == EntityState.Detached) { _contexto.Aluguel.Attach(aluguel); } _contexto.Aluguel.Remove(aluguel); _contexto.SaveChanges(); }
public void Deletar(Cliente cliente) { DbEntityEntry dbEntityEntry = _contexto.Entry(cliente); if (dbEntityEntry.State == EntityState.Detached) { _contexto.Clientes.Attach(cliente); } _contexto.Clientes.Remove(cliente); _contexto.SaveChanges(); }
public void Deletar(Carro carro) { using (var dbTransact = _contexto.Database.BeginTransaction()) { try { DbEntityEntry dbEntityEntry = _contexto.Entry(carro); if (dbEntityEntry.State == EntityState.Detached) { _contexto.Carros.Attach(carro); } _contexto.Carros.Remove(carro); _contexto.SaveChanges(); dbTransact.Commit(); } catch (Exception) { dbTransact.Rollback(); } } }