コード例 #1
0
        /// <summary>
        /// Sets an existing column as an FK, pointing to the unique key of <paramref name="referredSchemaAndTableName"/>.
        /// </summary>
        /// <param name="singleFkColumn">The existing column to set as FK.</param>
        /// <param name="referredSchemaAndTableName">The referred table as <see cref="SchemaAndTableName"/>.</param>
        /// <param name="fkName">The name of the FK. Auto naming will set name if not provided.</param>
        /// <returns>The original <paramref name="singleFkColumn"/>.</returns>
        public static SqlColumn SetForeignKeyToTable(this SqlColumn singleFkColumn, SchemaAndTableName referredSchemaAndTableName, string fkName = null)
        {
            var fk = new ForeignKeyRegistrationToTableWithUniqueKeyExistingColumn(singleFkColumn, referredSchemaAndTableName, null, fkName);

            singleFkColumn.Table.Properties.Add(fk);
            Prepare(singleFkColumn.Table);
            return(singleFkColumn);
        }
コード例 #2
0
        /// <summary>
        /// Sets an existing column as an FK, pointing to the unique key of <paramref name="referredSchemaAndTableName"/>, providing <paramref name="properties"/>.
        /// </summary>
        /// <param name="singleFkColumn">The existing column to set as FK.</param>
        /// <param name="referredSchemaAndTableName">The referred table as <see cref="SchemaAndTableName"/>.</param>
        /// <param name="properties">Implementation dependent properties.</param>
        /// <param name="fkName">The name of the FK. Auto naming will set name if not provided.</param>
        /// <returns>The original <paramref name="singleFkColumn"/>.</returns>
        public static SqlColumn SetForeignKeyToTable(this SqlColumn singleFkColumn, SchemaAndTableName referredSchemaAndTableName, IEnumerable <SqlEngineVersionSpecificProperty> properties, string fkName = null)
        {
            var fk = new ForeignKeyRegistrationToTableWithUniqueKeyExistingColumn(singleFkColumn, referredSchemaAndTableName, null, fkName);

            fk.SqlEngineVersionSpecificProperties.Add(properties);
            singleFkColumn.Table.Properties.Add(fk);
            Prepare(singleFkColumn.Table);
            return(singleFkColumn);
        }
コード例 #3
0
        public static void PrimaryKeyExistingColumn(DatabaseDefinition definiton, SqlTable sqlTable, ForeignKeyRegistrationToTableWithUniqueKeyExistingColumn fkRegistration)
        {
            var referredTable       = definiton.GetTable(fkRegistration.ReferredTableName);
            var referredUniqueIndex = GetReferredUniqueIndex(referredTable, fkRegistration.SingleReferredColumnName);

            CheckValidity(referredUniqueIndex, fkRegistration.SingleFkColumn.Name);

            var fk = ReplaceFKRegistrationWithNewFK(sqlTable, fkRegistration, referredTable);

            var pkColumn = referredUniqueIndex.SqlColumns[0].SqlColumn;

            if (fkRegistration.SingleFkColumn.Types.Count == 0)
            {
                pkColumn.Types.CopyTo(fkRegistration.SingleFkColumn.Types);
            }

            fk.ForeignKeyColumns.Add(new ForeignKeyColumnMap(fkRegistration.SingleFkColumn, pkColumn));
        }