public MigrationTable(Table table) { var migrationColumnFactory = new MigrationColumnFactory(this); Columns = table.ColumnIterator.Select(c => migrationColumnFactory.Create(c)).ToList(); var foreignKeyColumns = table.ForeignKeyIterator.Select(c => migrationColumnFactory.Create(c)).ToList(); Columns = Columns.Where(c => !foreignKeyColumns.Any(fk => fk.Name == c.Name)).ToList(); Columns.AddRange(foreignKeyColumns); if (table.PrimaryKey != null) { var primaryColumns = Columns.Where(c => table.PrimaryKey.Columns.Any(cc => cc.Name == c.Name)).First(); // we have only one primary key column primaryColumns.SetAsPrimaryKey(); } Name = table.Name; }