private void MergeConstraints(DataTable table)
{
Debug.Assert(_dataSet != null);
// Merge constraints
for (int i = 0; i < table.Constraints.Count; i++)
{
Constraint src = table.Constraints[i];
Constraint?dest = src.Clone(_dataSet, _IgnoreNSforTableLookup);
if (dest == null)
{
_dataSet.RaiseMergeFailed(table,
SR.Format(SR.DataMerge_MissingConstraint, src.GetType().FullName, src.ConstraintName),
_missingSchemaAction
);
}
else
{
Constraint?cons = dest.Table !.Constraints.FindConstraint(dest);
if (cons == null)
{
if (MissingSchemaAction.Add == _missingSchemaAction)
{
try
{
// try to keep the original name
dest.Table.Constraints.Add(dest);
}
catch (DuplicateNameException)
{
// if fail, assume default name
dest.ConstraintName = string.Empty;
dest.Table.Constraints.Add(dest);
}
}
else if (MissingSchemaAction.Error == _missingSchemaAction)
{
_dataSet.RaiseMergeFailed(table,
SR.Format(SR.DataMerge_MissingConstraint, src.GetType().FullName, src.ConstraintName),
_missingSchemaAction
);
}
}
else
{
MergeExtendedProperties(src.ExtendedProperties, cons.ExtendedProperties);
}
}
}
}