예제 #1
0
        public static SqlTable SetForeignKeyTo(this SqlTable table, string referredTableName, string fkName, IEnumerable <SqlEngineVersionSpecificProperty> properties, ColumnReference[] columnReferences)
        {
            var map = new List <ColumnReference>(columnReferences);
            var referredTableNameWithSchema = new SchemaAndTableName(referredTableName);
            var fk = new ForeignKeyRegistrationToReferredTableExistingColumns(table, referredTableNameWithSchema, fkName, map);

            if (properties != null)
            {
                fk.SqlEngineVersionSpecificProperties.Add(properties);
            }

            table.Properties.Add(fk);
            Prepare(table);
            return(table);
        }
        public static void ReferredTableExistingColumns(DatabaseDefinition definition, SqlTable sqlTable, ForeignKeyRegistrationToReferredTableExistingColumns fkRegistration)
        {
            var referredTable = definition.GetTable(fkRegistration.ReferredTableName);

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

            foreach (var fkGroup in fkRegistration.Map)
            {
                fk.ForeignKeyColumns.Add(new ForeignKeyColumnMap(sqlTable.Columns[fkGroup.ColumnName], referredTable[fkGroup.ReferredColumnName]));
            }
        }