Skip to content

ApplicationContext: Passing parameters to Migrations

medianick edited this page Oct 18, 2012 · 5 revisions

ApplicationContext is an object passed in by the [Migration Runner](Migration Runners) that is available to migrations to be used as a switch.

To set the ApplicationContext when running migrate.exe

Run migrate.exe ... --context MyArgument. This will set the application context to the string "MyArgument".

To set the ApplicationContext when running migration in code

Set runner.ApplicationContext to an arbitrary C# object, such as a string: runner.ApplicationContext = "MyArgument"; or when creating the RunnerContext:

var migrationContext = new FluentMigrator.Runner.Initialization.RunnerContext(announcer)
{
    ApplicationContext = clientName
};

To use the ApplicationContext

Inside your migration, you can access the context via this.ApplicationContext. So for instance:

if ((string)this.ApplicationContext == "MyArgument")
    this.Delete.Column("BadColumn").FromTable("MyTable");
Clone this wiki locally