Skip to content

Instantly share code, notes, and snippets.

@arman-hpp
Last active May 25, 2016 15:19
Show Gist options
  • Save arman-hpp/9944ea0f9b05142185571924c9fc7621 to your computer and use it in GitHub Desktop.
Save arman-hpp/9944ea0f9b05142185571924c9fc7621 to your computer and use it in GitHub Desktop.
public static class DbMigrationExtensions
{
public static void AlterDataFileSize(this DbMigration dbMigration, int size)
{
var sqlMethod = dbMigration.GetType().GetMethod("Sql", BindingFlags.Instance | BindingFlags.NonPublic);
sqlMethod.Invoke(dbMigration, new object[] { $@"
DECLARE @dbName varchar(100) = (SELECT db_name())
DECLARE @sqlCommand nvarchar(1000) = ('ALTER DATABASE ' + @dbName + ' MODIFY FILE ( NAME = ''' + @dbName +''', SIZE = {size}MB )')
EXECUTE sp_executesql @sqlCommand, N'@dbName varchar(100)', @dbName = @dbName
", true, null });
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment