コード例 #1
0
		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);
			}
		}
コード例 #2
0
		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));
		}