private void GenerateUpBody() { bool isFirstSchema = true; foreach (dynamic schema in _database.Schemas) { if (!_options.IsSchemaIncluded(schema.Name) || schema.IsSystemObject) { Console.WriteLine("Skipping schema [{0}]", schema.Name); continue; } if (isFirstSchema) { AppendLine("//", 3); AppendLine("// Schemas", 3); AppendLine("//", 3); isFirstSchema = false; } HandleSchema(schema); } if (!isFirstSchema) // there were schemas { AppendLine(); } AppendLine("//", 3); AppendLine("// Tables", 3); AppendLine("//", 3); var tablesWithForeignKeys = new List <Table>(); foreach (Table table in _database.Tables.Cast <Table>().OrderBy(t => t.Schema).ThenBy(t => t.Name)) { if (!_options.IsSchemaIncluded(table.Schema) || !_options.IsTableIncluded(table.Name) || table.Name.StartsWith("__", StringComparison.Ordinal) || // hide special tables such as the EF migration history table (table.Name == _options.VersioningTableName && table.Schema == _options.VersioningTableSchema)) { Console.WriteLine("Skipping table [{0}].[{1}]", table.Schema, table.Name); continue; } HandleTable(table); if (table.ForeignKeys.Count > 0) { tablesWithForeignKeys.Add(table); } } if (tablesWithForeignKeys.Any()) { AppendLine(); AppendLine("//", 3); AppendLine("// Foreign Keys", 3); AppendLine("//", 3); } foreach (var table in tablesWithForeignKeys) { foreach (ForeignKey foreignKey in table.ForeignKeys) { HandleForeignKey(table, foreignKey); } } if (_database.UserDefinedTableTypes.Count > 0) { AppendLine(); AppendLine("//", 3); AppendLine("// User Defined Table Types", 3); AppendLine("//", 3); } foreach (UserDefinedTableType tableType in _database.UserDefinedTableTypes) { HandleUserDefinedTableType(tableType); } }