public void ScriptObject(Table table, Options options) { // script table without constraints StringCollection script = table.Script(_scriptingOptions); string path = _directoryService.GetTablesDirectory(options.Root); string fileName = Path.Combine(path, string.Concat(table.Name, ".sql")); _fileWriter.WriteFile(fileName, script.Cast <string>()); // script constraints string foreignKeyPath = _directoryService.GetForeignKeysDirectory(options.Root); string addForeignKeyFileName = Path.Combine(foreignKeyPath, string.Concat(table.Name, "AddFks.sql")); string addForeignKeys = string.Join("\r\nGO\r\n\r\n", table.ForeignKeys.Cast <ForeignKey>().SelectMany(fk => fk.Script().Cast <string>())); string dropForeignKeyFileName = Path.Combine(foreignKeyPath, string.Concat(table.Name, "DropFks.sql")); string dropForeignKeys = string.Join("\r\nGO\r\n\r\n", table.ForeignKeys .Cast <ForeignKey>() .SelectMany(fk => fk.Script(new ScriptingOptions { ScriptDrops = true }).Cast <string>())); if (table.ForeignKeys.Cast <ForeignKey>().Any()) { _fileWriter.WriteFile(addForeignKeyFileName, new [] { addForeignKeys }); _fileWriter.WriteFile(dropForeignKeyFileName, new [] { dropForeignKeys }); } }
public void CreateTables(Options options) { string directory = _directoryService.GetTablesDirectory(options.Root); if (!Directory.Exists(directory)) { throw new Exception(string.Format("Directory '{0}' does not exist", directory)); } IEnumerable <string> files = Directory.GetFiles(directory); ProcessDirectoryFiles(files, options); }