DotNetMigrations.Migrations.MigrationScriptFile.Write C# (CSharp) Method

Write() public method

Writes the given contents into the migration script file.
public Write ( MigrationScriptContents contents ) : void
contents MigrationScriptContents
return void
        public void Write(MigrationScriptContents contents)
        {
            var sb = new StringBuilder();
            sb.AppendLine(SetupStartTag);
            sb.AppendLine();
            sb.AppendLine(contents.Setup);
            sb.AppendLine();
            sb.AppendLine(SetupEndTag);
            sb.AppendLine();
            sb.AppendLine();
            sb.AppendLine(TeardownStartTag);
            sb.AppendLine();
            sb.AppendLine(contents.Teardown);
            sb.AppendLine();
            sb.Append(TeardownEndTag);

            File.WriteAllText(FilePath, sb.ToString());
        }

Usage Example

        /// <summary>
        /// Creates a blank migration script with the given name.
        /// </summary>
        /// <param name="migrationName">name of the migration script</param>
        /// <returns>The path to the new migration script.</returns>
        public string CreateBlankScript(string migrationName)
        {
            long version = GetNewVersionNumber();
            var path = GetPath(null);
            path = Path.Combine(path, version + "_" + SanitizeMigrationName(migrationName) + ".sql");

            var contents = new MigrationScriptContents(null, null);

            var file = new MigrationScriptFile(path);
            file.Write(contents);

            return path;
        }
All Usage Examples Of DotNetMigrations.Migrations.MigrationScriptFile::Write