public override void Eliminar(ObjetoDelete od) { _command = new MySqlCommand(GenerarDeleteFrom(od), _connection); try { _connection.Open(); _command.ExecuteNonQuery(); } catch (MySqlException exc) { if (exc.Number == 547) throw new Exception("Existen relaciones hacia este elemento. Elimínelas y vuelva a intentarlo"); else { throw new Exception("Mensaje: " + exc.Message + "\n\n" + "Consulta: " + _command.CommandText); } } finally { _connection.Close(); } }
public string GenerarDeleteFrom(ObjetoDelete od) { string whereCadena = ""; foreach (ValorWhere vw in od.ListaValoresWhere) { whereCadena += "(" + GenerarCondicion(vw) + ") and "; } whereCadena = RemoverUltimosCaracteres(whereCadena, 4); return string.Format("DELETE FROM {0} WHERE {1};", od.Tabla, whereCadena); }
public abstract void Eliminar(ObjetoDelete od);