/// <inheritdoc/> public void DeleteFromDatabase(IMapsDirectlyToDatabaseTable oTableWrapperObject) { //do not log information about access credentials if (!(oTableWrapperObject is IDataAccessCredentials)) { _logger.Debug("Deleted," + oTableWrapperObject.GetType().Name + "," + oTableWrapperObject.ID + "," + oTableWrapperObject); } lock (_oLockUpdateCommands) { //if the repository has obscure dependencies if (ObscureDependencyFinder != null) { ObscureDependencyFinder.ThrowIfDeleteDisallowed(oTableWrapperObject);//confirm that deleting the object is allowed by the dependencies } using (var con = GetConnection()) { using (DbCommand cmd = DatabaseCommandHelper.GetCommand( "DELETE FROM " + oTableWrapperObject.GetType().Name + " WHERE ID =@ID", con.Connection, con.Transaction)) { DatabaseCommandHelper.AddParameterWithValueToCommand("@ID", cmd, oTableWrapperObject.ID); cmd.ExecuteNonQuery(); } //likewise if there are obscure depenedency handlers let them handle cascading this delete into the mists of their obscure functionality (e.g. deleting a Catalogue in CatalogueRepository would delete all Evaluations of that Catalogue in the DQE repository because they would then be orphans) if (ObscureDependencyFinder != null) { ObscureDependencyFinder.HandleCascadeDeletesForDeletedObject(oTableWrapperObject); } } } }
/// <inheritdoc/> public void DeleteFromDatabase(IMapsDirectlyToDatabaseTable oTableWrapperObject) { _logger.Debug("Deleted," + oTableWrapperObject.GetType().Name + "," + oTableWrapperObject.ID + "," + oTableWrapperObject); lock (_oLockUpdateCommands) { //if the repository has obscure dependencies if (ObscureDependencyFinder != null) { ObscureDependencyFinder.ThrowIfDeleteDisallowed(oTableWrapperObject);//confirm that deleting the object is allowed by the dependencies } using (var con = GetConnection()) { DbCommand cmd = DatabaseCommandHelper.GetCommand("DELETE FROM " + oTableWrapperObject.GetType().Name + " WHERE ID =@ID", con.Connection, con.Transaction); DatabaseCommandHelper.AddParameterWithValueToCommand("@ID", cmd, oTableWrapperObject.ID); int affectedRows = cmd.ExecuteNonQuery(); if (affectedRows != 1) { throw new Exception("Attempted to delete object of type " + oTableWrapperObject.GetType().Name + " from table " + oTableWrapperObject.GetType().Name + " with ID " + oTableWrapperObject.ID + " but the DELETE command resulted in " + affectedRows + " affected rows"); } //likewise if there are obscure depenedency handlers let them handle cascading this delete into the mists of their obscure functionality (e.g. deleting a Catalogue in CatalogueRepository would delete all Evaluations of that Catalogue in the DQE repository because they would then be orphans) if (ObscureDependencyFinder != null) { ObscureDependencyFinder.HandleCascadeDeletesForDeletedObject(oTableWrapperObject); } } } }