예제 #1
0
        /// <summary>
        ///     Creates a new database constraint within the table.
        /// </summary>
        public DomainTableConstraint CreateConstraint()
        {
            DomainTableConstraint constraint = new DomainTableConstraint(this);

            _tableConstraints.Add(constraint);
            return(constraint);
        }
예제 #2
0
        /// <summary>
        ///     Parses a data record into a <see cref="DatabaseConstraintColumn" /> instance.
        /// </summary>
        private DomainTableConstraintColumn ParseConstraintColumn(DomainTableConstraint constraint, IDataRecord record)
        {
            DomainTableConstraintColumn constraintColumn = constraint.CreateColumn();

            constraintColumn.ConstraintColumn = constraint.Table.TableColumns.FirstOrDefault(column => column.ColumnName == record["column_name"].ConvertTo <String>());
            constraintColumn.ReferencedColumn = constraint.ReferencedTable.TableColumns.FirstOrDefault(column => column.ColumnName == record["column_reference"].ConvertTo <String>());
            return(constraintColumn);
        }
예제 #3
0
 /// <summary>
 ///     Deserialises the version history from the specified xml element.
 /// </summary>
 internal static void Deserialise(DomainTableConstraint constraint, XmlNode parentNode)
 {
     foreach (XmlNode xmlNode in parentNode.SelectNodes("column"))
     {
         DomainTableConstraintColumn result = constraint.CreateColumn();
         result.Deserialise(xmlNode);
     }
 }
예제 #4
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);
     }
 }
예제 #5
0
 /// <summary>
 ///     Deserialises the version history from the specified xml element.
 /// </summary>
 internal static void Deserialise(Domain domain, XmlNode parentNode)
 {
     foreach (XmlNode xmlNode in parentNode.SelectNodes("table"))
     {
         DomainTable result = domain.CreateTable();
         result.Deserialise(xmlNode);
         DomainTableColumn.Deserialise(result, xmlNode);
         DomainTableIndex.Deserialise(result, xmlNode);
         DomainTableConstraint.Deserialise(result, xmlNode);
     }
 }
예제 #6
0
        /// <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);
        }
예제 #7
0
 /// <summary>
 ///     Initialises a new <see cref="DomainTableConstraintColumn" /> instance.
 /// </summary>
 public DomainTableConstraintColumn(DomainTableConstraint constraint) : base(constraint.Version)
 {
     _constraint = constraint;
 }