internal void DeserializeConstraints(SerializationInfo info, StreamingContext context, int serIndex, bool allConstraints)
{
ArrayList constraintList = (ArrayList)info.GetValue(string.Format(CultureInfo.InvariantCulture, "DataTable_{0}.Constraints", serIndex), typeof(ArrayList));
foreach (ArrayList list in constraintList)
{
string con = (string)list[0];
if (con.Equals("U"))
{
//Unique Constraints
string constraintName = (string)list[1];
int[] keyColumnIndexes = (int[])list[2];
bool isPrimaryKey = (bool)list[3];
PropertyCollection extendedProperties = (PropertyCollection)list[4];
DataColumn[] keyColumns = new DataColumn[keyColumnIndexes.Length];
for (int i = 0; i < keyColumnIndexes.Length; i++)
{
keyColumns[i] = Columns[keyColumnIndexes[i]];
}
//Create the constraint.
UniqueConstraint uc = new UniqueConstraint(constraintName, keyColumns, isPrimaryKey);
uc._extendedProperties = extendedProperties;
//Add the unique constraint and it will in turn set the primary keys also if needed.
Constraints.Add(uc);
}
else
{
//ForeignKeyConstraints
Debug.Assert(con.Equals("F"));
string constraintName = (string)list[1];
int[] parentInfo = (int[])list[2];
int[] childInfo = (int[])list[3];
int[] rules = (int[])list[4];
PropertyCollection extendedProperties = (PropertyCollection)list[5];
//ParentKey Columns.
DataTable parentTable = (allConstraints == false) ? this : DataSet.Tables[parentInfo[0]];
DataColumn[] parentkeyColumns = new DataColumn[parentInfo.Length - 1];
for (int i = 0; i < parentkeyColumns.Length; i++)
{
parentkeyColumns[i] = parentTable.Columns[parentInfo[i + 1]];
}
//ChildKey Columns.
DataTable childTable = (allConstraints == false) ? this : DataSet.Tables[childInfo[0]];
DataColumn[] childkeyColumns = new DataColumn[childInfo.Length - 1];
for (int i = 0; i < childkeyColumns.Length; i++)
{
childkeyColumns[i] = childTable.Columns[childInfo[i + 1]];
}
//Create the Constraint.
ForeignKeyConstraint fk = new ForeignKeyConstraint(constraintName, parentkeyColumns, childkeyColumns);
fk.AcceptRejectRule = (AcceptRejectRule)rules[0];
fk.UpdateRule = (Rule)rules[1];
fk.DeleteRule = (Rule)rules[2];
fk._extendedProperties = extendedProperties;
//Add just the foreign key constraint without creating unique constraint.
Constraints.Add(fk, false);
}
}
}