private void ProcessRelationIdentity (XmlSchemaElement element, ConstraintStructure c)
{
// Basic concept came from XmlSchemaMapper.cs
string tableName = c.TableName;
DataColumn [] cols;
DataTable dt = dataset.Tables [tableName];
if (dt == null)
throw new DataException (String.Format ("Invalid XPath selection inside selector. Cannot find: {0}", tableName));
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 (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] = col;
}
string name = c.ReferName;
// get the unique constraint for the releation
UniqueConstraint uniq = FindConstraint (name, element);
// generate the FK.
ForeignKeyConstraint fkc = new ForeignKeyConstraint(c.ConstraintName, uniq.Columns, cols);
dt.Constraints.Add (fkc);
if (!c.IsConstraintOnly) {
// generate the relation.
DataRelation rel = new DataRelation (c.ConstraintName, uniq.Columns, cols, true);
rel.Nested = c.IsNested;
rel.SetParentKeyConstraint (uniq);
rel.SetChildKeyConstraint (fkc);
dataset.Relations.Add (rel);
}
}