internal void SerializeConstraints(SerializationInfo info, StreamingContext context, int serIndex, bool allConstraints)
{
if (allConstraints)
{
Debug.Assert(DataSet != null);
}
ArrayList constraintList = new ArrayList();
for (int i = 0; i < Constraints.Count; i++)
{
Constraint c = Constraints[i];
UniqueConstraint uc = c as UniqueConstraint;
if (uc != null)
{
int[] colInfo = new int[uc.Columns.Length];
for (int j = 0; j < colInfo.Length; j++)
{
colInfo[j] = uc.Columns[j].Ordinal;
}
ArrayList list = new ArrayList();
list.Add("U");
list.Add(uc.ConstraintName);
list.Add(colInfo);
list.Add(uc.IsPrimaryKey);
list.Add(uc.ExtendedProperties);
constraintList.Add(list);
}
else
{
ForeignKeyConstraint fk = c as ForeignKeyConstraint;
Debug.Assert(fk != null);
bool shouldSerialize = (allConstraints == true) || (fk.Table == this && fk.RelatedTable == this);
if (shouldSerialize)
{
int[] parentInfo = new int[fk.RelatedColumns.Length + 1];
parentInfo[0] = allConstraints ? DataSet.Tables.IndexOf(fk.RelatedTable) : 0;
for (int j = 1; j < parentInfo.Length; j++)
{
parentInfo[j] = fk.RelatedColumns[j - 1].Ordinal;
}
int[] childInfo = new int[fk.Columns.Length + 1];
childInfo[0] = allConstraints ? DataSet.Tables.IndexOf(fk.Table) : 0; //Since the constraint is on the current table, this is the child table.
for (int j = 1; j < childInfo.Length; j++)
{
childInfo[j] = fk.Columns[j - 1].Ordinal;
}
ArrayList list = new ArrayList();
list.Add("F");
list.Add(fk.ConstraintName);
list.Add(parentInfo);
list.Add(childInfo);
list.Add(new int[] { (int)fk.AcceptRejectRule, (int)fk.UpdateRule, (int)fk.DeleteRule });
list.Add(fk.ExtendedProperties);
constraintList.Add(list);
}
}
}
info.AddValue(string.Format(CultureInfo.InvariantCulture, "DataTable_{0}.Constraints", serIndex), constraintList);
}