示例#1
0
 /// <summary>
 ///     Deserialises the version history from the specified xml element.
 /// </summary>
 internal static void Deserialise(DomainTable table, XmlNode parentNode)
 {
     foreach (XmlNode xmlNode in parentNode.SelectNodes("constraint"))
     {
         DomainTableConstraint result = table.CreateConstraint();
         result.Deserialise(xmlNode);
         DomainTableConstraintColumn.Deserialise(result, xmlNode);
     }
 }
        /// <summary>
        ///     Parses a data record into a <see cref="DatabaseConstraint" /> instance.
        /// </summary>
        private DomainTableConstraint ParseConstraint(DomainTable table, IDataRecord record)
        {
            DomainTableConstraint constraint = table.CreateConstraint();

            constraint.ConstraintName  = record["key_name"].ConvertTo <String>();
            constraint.ReferencedTable = table.Domain.Tables.FirstOrDefault(t => t.TableName == record["key_object"].ConvertTo <String>());

            // Import the column information
            this.Execute(rec2 => this.ParseConstraintColumn(constraint, rec2), @"
              select column_name = columns.name, column_reference = referenced_column.name
              from sys.schemas
              join sys.objects on objects.schema_id = schemas.schema_id 
              join sys.columns on columns.object_id = objects.object_id 
              join sys.foreign_keys on foreign_keys.parent_object_id = objects.object_id
              join sys.foreign_key_columns on foreign_key_columns.constraint_object_id = foreign_keys.object_id and foreign_key_columns.parent_object_id = foreign_keys.parent_object_id and foreign_key_columns.parent_column_id = columns.column_id
              join sys.columns as referenced_column on referenced_column.object_id = foreign_key_columns.referenced_object_id and referenced_column.column_id = foreign_key_columns.referenced_column_id
              where schemas.name = 'dbo' and objects.type = 'u' and objects.name = @param1 and foreign_keys.object_id = @param2", table.TableName, record["key_id"]).ToArray();
            return(constraint);
        }