internal bool CanRemove(DataColumn column, bool fThrowException) { if (column == null) { if (!fThrowException) { return(false); } else { throw ExceptionBuilder.ArgumentNull("column"); } } if (column.table != table) { if (!fThrowException) { return(false); } else { throw ExceptionBuilder.CannotRemoveColumn(); } } // allow subclasses to complain first. table.OnRemoveColumn(column); // We need to make sure the column is not involved in any Relations or Constriants if (table.primaryKey != null && table.primaryKey.Key.ContainsColumn(column)) { if (!fThrowException) { return(false); } else { throw ExceptionBuilder.CannotRemovePrimaryKey(); } } for (int i = 0; i < table.ParentRelations.Count; i++) { if (table.ParentRelations[i].ChildKey.ContainsColumn(column)) { if (!fThrowException) { return(false); } else { throw ExceptionBuilder.CannotRemoveChildKey(table.ParentRelations[i].RelationName); } } } for (int i = 0; i < table.ChildRelations.Count; i++) { if (table.ChildRelations[i].ParentKey.ContainsColumn(column)) { if (!fThrowException) { return(false); } else { throw ExceptionBuilder.CannotRemoveChildKey(table.ChildRelations[i].RelationName); } } } for (int i = 0; i < table.Constraints.Count; i++) { if (table.Constraints[i].ContainsColumn(column)) { if (!fThrowException) { return(false); } else { throw ExceptionBuilder.CannotRemoveConstraint(table.Constraints[i].ConstraintName, table.Constraints[i].Table.TableName); } } } if (table.DataSet != null) { for (ParentForeignKeyConstraintEnumerator en = new ParentForeignKeyConstraintEnumerator(table.DataSet, table); en.GetNext();) { Constraint constraint = en.GetConstraint(); if (((ForeignKeyConstraint)constraint).ParentKey.ContainsColumn(column)) { if (!fThrowException) { return(false); } else { throw ExceptionBuilder.CannotRemoveConstraint(constraint.ConstraintName, constraint.Table.TableName); } } } } for (int i = 0; i < ColumnQueue.columnCount; i++) { DataColumn col = ColumnQueue.columns[i]; if (fInClear && (col.Table == table || col.Table == null)) { continue; } Debug.Assert(col.Computed, "invalid (non an expression) column in the expression column queue"); DataExpression expr = col.DataExpression; if (expr.DependsOn(column)) { if (!fThrowException) { return(false); } else { throw ExceptionBuilder.CannotRemoveExpression(col.ColumnName, col.Expression); } } } return(true); }
internal bool CanRemove(DataColumn?column, bool fThrowException) { if (column == null) { if (!fThrowException) { return(false); } else { throw ExceptionBuilder.ArgumentNull(nameof(column)); } } if (column._table != _table) { if (!fThrowException) { return(false); } else { throw ExceptionBuilder.CannotRemoveColumn(); } } // allow subclasses to complain first. _table.OnRemoveColumnInternal(column); // We need to make sure the column is not involved in any Relations or Constriants if (_table._primaryKey != null && _table._primaryKey.Key.ContainsColumn(column)) { if (!fThrowException) { return(false); } else { throw ExceptionBuilder.CannotRemovePrimaryKey(); } } for (int i = 0; i < _table.ParentRelations.Count; i++) { if (_table.ParentRelations[i].ChildKey.ContainsColumn(column)) { if (!fThrowException) { return(false); } else { throw ExceptionBuilder.CannotRemoveChildKey(_table.ParentRelations[i].RelationName); } } } for (int i = 0; i < _table.ChildRelations.Count; i++) { if (_table.ChildRelations[i].ParentKey.ContainsColumn(column)) { if (!fThrowException) { return(false); } else { throw ExceptionBuilder.CannotRemoveChildKey(_table.ChildRelations[i].RelationName); } } } for (int i = 0; i < _table.Constraints.Count; i++) { if (_table.Constraints[i].ContainsColumn(column)) { if (!fThrowException) { return(false); } else { throw ExceptionBuilder.CannotRemoveConstraint(_table.Constraints[i].ConstraintName, _table.Constraints[i].Table !.TableName); } } } if (_table.DataSet != null) { for (ParentForeignKeyConstraintEnumerator en = new ParentForeignKeyConstraintEnumerator(_table.DataSet, _table); en.GetNext();) { Constraint constraint = en.GetConstraint(); if (((ForeignKeyConstraint)constraint).ParentKey.ContainsColumn(column)) { if (!fThrowException) { return(false); } else { throw ExceptionBuilder.CannotRemoveConstraint(constraint.ConstraintName, constraint.Table !.TableName); } } } } if (column._dependentColumns != null) { for (int i = 0; i < column._dependentColumns.Count; i++) { DataColumn col = column._dependentColumns[i]; if (_fInClear && (col.Table == _table || col.Table == null)) { continue; } if (col.Table == null) { continue; } Debug.Assert(col.Computed, "invalid (non an expression) column in the expression dependent columns"); DataExpression?expr = col.DataExpression; if ((expr != null) && (expr.DependsOn(column))) { if (!fThrowException) { return(false); } else { throw ExceptionBuilder.CannotRemoveExpression(col.ColumnName, col.Expression); } } } } // you can't remove a column participating in an index, // while index events are suspended else the indexes won't be properly maintained. // However, all the above checks should catch those participating columns. // except when a column is in a DataView RowFilter or Sort clause foreach (Index _ in _table.LiveIndexes) { } return(true); }
internal bool CanRemove(DataColumn column, bool fThrowException) { if (column == null) { if (fThrowException) { throw ExceptionBuilder.ArgumentNull("column"); } return(false); } if (column.table != this.table) { if (fThrowException) { throw ExceptionBuilder.CannotRemoveColumn(); } return(false); } this.table.OnRemoveColumnInternal(column); if ((this.table.primaryKey != null) && this.table.primaryKey.Key.ContainsColumn(column)) { if (fThrowException) { throw ExceptionBuilder.CannotRemovePrimaryKey(); } return(false); } for (int i = 0; i < this.table.ParentRelations.Count; i++) { if (this.table.ParentRelations[i].ChildKey.ContainsColumn(column)) { if (fThrowException) { throw ExceptionBuilder.CannotRemoveChildKey(this.table.ParentRelations[i].RelationName); } return(false); } } for (int j = 0; j < this.table.ChildRelations.Count; j++) { if (this.table.ChildRelations[j].ParentKey.ContainsColumn(column)) { if (fThrowException) { throw ExceptionBuilder.CannotRemoveChildKey(this.table.ChildRelations[j].RelationName); } return(false); } } for (int k = 0; k < this.table.Constraints.Count; k++) { if (this.table.Constraints[k].ContainsColumn(column)) { if (fThrowException) { throw ExceptionBuilder.CannotRemoveConstraint(this.table.Constraints[k].ConstraintName, this.table.Constraints[k].Table.TableName); } return(false); } } if (this.table.DataSet != null) { ParentForeignKeyConstraintEnumerator enumerator = new ParentForeignKeyConstraintEnumerator(this.table.DataSet, this.table); while (enumerator.GetNext()) { Constraint constraint = enumerator.GetConstraint(); if (((ForeignKeyConstraint)constraint).ParentKey.ContainsColumn(column)) { if (fThrowException) { throw ExceptionBuilder.CannotRemoveConstraint(constraint.ConstraintName, constraint.Table.TableName); } return(false); } } } if (column.dependentColumns != null) { for (int m = 0; m < column.dependentColumns.Count; m++) { DataColumn column2 = column.dependentColumns[m]; if ((!this.fInClear || ((column2.Table != this.table) && (column2.Table != null))) && (column2.Table != null)) { DataExpression dataExpression = column2.DataExpression; if ((dataExpression != null) && dataExpression.DependsOn(column)) { if (fThrowException) { throw ExceptionBuilder.CannotRemoveExpression(column2.ColumnName, column2.Expression); } return(false); } } } } using (List <Index> .Enumerator enumerator2 = this.table.LiveIndexes.GetEnumerator()) { while (enumerator2.MoveNext()) { Index current = enumerator2.Current; } } return(true); }