public TableSchema(DataModelSchema dataModelSchema, XmlSchemaElement xmlSchemaElement) : base(dataModelSchema, xmlSchemaElement) { // Initialize the object. this.DataModelSchema = dataModelSchema; this.Name = xmlSchemaElement.Name; this.QualifiedName = xmlSchemaElement.QualifiedName; this.IsPersistent = GetIsPersistentAttribute(xmlSchemaElement); this.Columns = new ColumnSchemaCollection(); this.Constraints = new ConstraintSchemaCollection(); this.Keys = new List <ConstraintSchema>(); this.ParentKeyrefs = new List <KeyrefSchema>(); this.TypeSchema = GetTypeSchema(xmlSchemaElement); GetColumns(xmlSchemaElement.SchemaType, this.Columns); Constraints.ItemAdded += new ConstraintEvent(ConstraintAddedHandler); }
/// <summary> /// Create a description of a column in a data model. /// </summary> /// <param name="dataModelSchema">The Schema of the entire data model.</param> /// <param name="xmlSchemaObject">The schema of the column.</param> public ColumnSchema(DataModelSchema dataModelSchema, XmlSchemaObject xmlSchemaObject) : base(dataModelSchema, xmlSchemaObject) { // Initialize the object this.dataModelSchema = dataModelSchema; this.Name = string.Empty; this.QualifiedName = XmlQualifiedName.Empty; this.DataType = typeof(System.Object); this.MinOccurs = 0.0M; this.DefaultValue = null; this.FixedValue = null; // Extract the column properties from an Element. if (xmlSchemaObject is XmlSchemaElement) { XmlSchemaElement xmlSchemaElement = xmlSchemaObject as XmlSchemaElement; this.Name = xmlSchemaElement.Name; this.QualifiedName = xmlSchemaElement.QualifiedName; this.DataType = xmlSchemaElement.ElementSchemaType.Datatype.ValueType; this.MinOccurs = xmlSchemaElement.MinOccurs; this.DefaultValue = ConvertValue(xmlSchemaElement.DefaultValue); this.FixedValue = ConvertValue(xmlSchemaElement.FixedValue); } // Extract the column properties from an Attribute. if (xmlSchemaObject is XmlSchemaAttribute) { XmlSchemaAttribute xmlSchemaAttribute = xmlSchemaObject as XmlSchemaAttribute; this.Name = xmlSchemaAttribute.Name; this.QualifiedName = xmlSchemaAttribute.QualifiedName; this.DataType = xmlSchemaAttribute.AttributeSchemaType.Datatype.ValueType; this.DefaultValue = ConvertValue(xmlSchemaAttribute.DefaultValue); this.FixedValue = ConvertValue(xmlSchemaAttribute.FixedValue); } // Determine the IsIdentityColumn property. object autoIncrementAttribute = GetUnhandledAttribute(xmlSchemaObject, "AutoIncrement"); this.IsAutoIncrement = autoIncrementAttribute == null ? false : Convert.ToBoolean(autoIncrementAttribute); // Determine the IsPersistent property. object isColumnPersistentAttribute = GetUnhandledAttribute(xmlSchemaObject, "IsPersistent"); this.IsPersistent = isColumnPersistentAttribute == null ? true : Convert.ToBoolean(isColumnPersistentAttribute); // Determine the AutoIncrementSeed property. object autoIncrementSeedAttribute = GetUnhandledAttribute(xmlSchemaObject, "AutoIncrementSeed"); this.AutoIncrementSeed = autoIncrementSeedAttribute == null ? 0 : Convert.ToInt32(autoIncrementSeedAttribute); // Determine the AutoIncrementStop property object autoIncrementStepAttribute = GetUnhandledAttribute(xmlSchemaObject, "AutoIncrementStep"); this.AutoIncrementStep = autoIncrementStepAttribute == null ? 0 : Convert.ToInt32(autoIncrementStepAttribute); // In an object oriented architecture it is important to know at which level of the hierarchy a column is initially // declared. Just like the equivalent in the object oriented languages, this field indicates which table actually owns // the data of a given column. XmlSchemaObject parentObject = xmlSchemaObject.Parent; while (!(parentObject is XmlSchemaComplexContentExtension) && !(parentObject is XmlSchemaComplexType)) { parentObject = parentObject.Parent; } this.DeclaringType = FindDeclaringType(parentObject, xmlSchemaObject); }