private void ProcessSelfIdentity (ConstraintStructure c)
{
// Basic concept came from XmlSchemaMapper.cs
string tableName = c.TableName;
DataTable dt = dataset.Tables [tableName];
if (dt == null) {
if (forDataSet)
throw new DataException (String.Format ("Invalid XPath selection inside selector. Cannot find: {0}", tableName));
else
// nonexistent table name. .NET ignores it for DataTable.ReadXmlSchema().
return;
}
DataColumn [] cols = new DataColumn [c.Columns.Length];
for (int i = 0; i < cols.Length; i++) {
string colName = c.Columns [i];
bool isAttr = c.IsAttribute [i];
DataColumn col = dt.Columns [colName];
if (col == null)
throw new DataException (String.Format ("Invalid XPath selection inside field. Cannot find: {0}", tableName));
if (isAttr && col.ColumnMapping != MappingType.Attribute)
throw new DataException ("The XPath specified attribute field, but mapping type is not attribute.");
if (!isAttr && col.ColumnMapping != MappingType.Element)
throw new DataException ("The XPath specified simple element field, but mapping type is not simple element.");
cols [i] = dt.Columns [colName];
}
bool isPK = c.IsPrimaryKey;
string constraintName = c.ConstraintName;
dt.Constraints.Add (new UniqueConstraint (
constraintName, cols, isPK));
}