-
- // in this method we find the row that this row is in a relation with them.
- // in shortly we find all child rows of this row.
- // then we function according to the DeleteRule of the foriegnkey.
-
-
- // 1. find if this row is attached to dataset.
- // 2. find if EnforceConstraints is true.
- // 3. find if there are any constraint on the table that the row is in.
- if (_table.DataSet != null && _table.DataSet.EnforceConstraints && _table.Constraints.Count > 0)
- {
- foreach (DataTable table in _table.DataSet.Tables)
- {
- // loop on all ForeignKeyConstrain of the table.
- foreach (Constraint constraint in table.Constraints) {
- if (constraint is ForeignKeyConstraint) {
- ForeignKeyConstraint fk = (ForeignKeyConstraint) constraint;
- if (fk.RelatedTable == _table) {
- switch (action) {
- case DataRowAction.Delete:
- CheckChildRows(fk, action, fk.DeleteRule);
- break;
- case DataRowAction.Commit:
- case DataRowAction.Rollback:
- if (fk.AcceptRejectRule != AcceptRejectRule.None)
- CheckChildRows(fk, action, Rule.Cascade);
- break;
- default:
- CheckChildRows(fk, action, fk.UpdateRule);
- break;
- }
- }
- }
+ DataSet ds = _table.DataSet;
+
+ if (ds == null || !ds.EnforceConstraints)
+ return;
+
+ // if the table we're attached-to doesn't have an constraints, no foreign keys are pointing to us ...
+ if (_table.Constraints.Count == 0)
+ return;
+
+ foreach (DataTable table in ds.Tables) {
+ // loop on all ForeignKeyConstrain of the table.
+ foreach (Constraint constraint in table.Constraints) {
+ ForeignKeyConstraint fk = constraint as ForeignKeyConstraint;
+ if (fk == null || fk.RelatedTable != _table)
+ continue;
+
+ switch (action) {
+ case DataRowAction.Delete:
+ CheckChildRows (fk, action, fk.DeleteRule);
+ break;
+ case DataRowAction.Commit:
+ case DataRowAction.Rollback:
+ if (fk.AcceptRejectRule != AcceptRejectRule.None)
+ CheckChildRows (fk, action, Rule.Cascade);
+ break;
+ default:
+ CheckChildRows (fk, action, fk.UpdateRule);
+ break;