Skip to content

ApplicationContext: Passing parameters to Migrations

ses4j edited this page Jul 5, 2012 · 5 revisions

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

To set the ApplicationContext when running migrate.exe

Requires pull request https://github.com/schambers/fluentmigrator/pull/271 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