System.Data.XSDSchema.HandleConstraint C# (CSharp) Method

HandleConstraint() private method

private HandleConstraint ( XmlSchemaIdentityConstraint keyNode ) : void
keyNode System.Xml.Schema.XmlSchemaIdentityConstraint
return void
        internal void HandleConstraint(XmlSchemaIdentityConstraint keyNode)
        {
            string name = null;

            name = XmlConvert.DecodeName(keyNode.Name);
            if (name == null || name.Length == 0)
                throw ExceptionBuilder.MissingAttribute(Keywords.NAME);

            if (_constraintNodes.ContainsKey(name))
                throw ExceptionBuilder.DuplicateConstraintRead(name);

            // we do not process key defined outside the current node
            string tableName = GetTableName(keyNode);
            string tableNs = GetMsdataAttribute(keyNode, Keywords.MSD_TABLENS);

            DataTable table = _ds.Tables.GetTableSmart(tableName, tableNs);

            if (table == null)
                return;

            _constraintNodes.Add(name, new ConstraintTable(table, keyNode));

            bool fPrimaryKey = GetBooleanAttribute(keyNode, Keywords.MSD_PRIMARYKEY,  /*default:*/ false);
            name = GetStringAttribute(keyNode, "ConstraintName", /*default:*/ name);



            DataColumn[] key = BuildKey(keyNode, table);

            if (0 < key.Length)
            {
                UniqueConstraint found = (UniqueConstraint)key[0].Table.Constraints.FindConstraint(new UniqueConstraint(name, key));

                if (found == null)
                {
                    key[0].Table.Constraints.Add(name, key, fPrimaryKey);
                    SetExtProperties(key[0].Table.Constraints[name], keyNode.UnhandledAttributes);
                }
                else
                {
                    key = found.ColumnsReference;
                    SetExtProperties(found, keyNode.UnhandledAttributes);
                    if (fPrimaryKey)
                        key[0].Table.PrimaryKey = key;
                }
                if (keyNode is XmlSchemaKey)
                {
                    for (int i = 0; i < key.Length; i++)
                        key[i].AllowDBNull = false;
                }
            }
        }