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);
}