Я нашел ответ! Вы устанавливаете int в параметрах Runner, как показано ниже
opt.TransactionPerSession = true;
Полный метод, который создает IServiceProvide
private static IServiceProvider CreateServices(string connectionString,
CommandLineArguments commandLineArguments)
{
return new ServiceCollection()
// Add common FluentMigrator services
.AddFluentMigratorCore()
.ConfigureRunner(rb => rb
// Add SQL Server support to FluentMigrator
.AddSqlServer()
// Set the connection string
.WithGlobalConnectionString(connectionString)
// Define the assembly containing the migrations
.ScanIn(typeof(Program).Assembly).For.Migrations().For.EmbeddedResources())
// Enable logging to console in the FluentMigrator way
.AddLogging(lb => lb.AddFluentMigratorConsole())
.Configure<RunnerOptions>(opt => {
opt.Tags = commandLineArguments.Tags.ToArray();
opt.TransactionPerSession = true; })
// Build the service provider
.BuildServiceProvider(false);
}
Приведенный ниже код является полным примером, который использует IServiceProvider
var serviceProvider = CreateServices(connectionString, commandLineArguments);
// Put the database update into a scope to ensure
// that all resources will be disposed.
using (var scope = serviceProvider.CreateScope())
{
try
{
UpdateDatabase(scope.ServiceProvider, commandLineArguments);
}
catch (Exception e)
{
Console.WriteLine("There was a problem with the migration: " + e.Message + "\n" +
e.StackTrace);
}
migrationRun = true;
}
Код обновления базы данных:
private static void UpdateDatabase(IServiceProvider serviceProvider, CommandLineArguments commandLineArguments)
{
// Instantiate the runner
var runner = serviceProvider.GetRequiredService<IMigrationRunner>();
if (commandLineArguments.Downgrade)
{
runner.MigrateDown(commandLineArguments.Version != -1 ? commandLineArguments.Version : 0);
}
else
{
if (commandLineArguments.Version != -1)
{
runner.MigrateUp(commandLineArguments.Version);
}
else
{
runner.MigrateUp();
}
}
}