Raymond Raymond

About --idempotent Flag in dotnet ef migrations script

event 2021-09-18 visibility 2,180 comment 0 insights toc
more_vert
insights Stats

Entity Framework is commonly used in .NET applications. The feature I like most is to generate database migration scripts automatically. This is commonly used in DevOps projects to generate delta SQL scripts to apply to production databases automatically.

About dotnet ef migrations script 

The usage of the command:

Usage: dotnet ef migrations script [arguments] [options]

Arguments:
  <FROM> The starting migration. Defaults to '0' (the initial database).
  <TO> The target migration. Defaults to the last migration.
Options:
  -o|--output <FILE> The file to write the result to.
  -i|--idempotent Generate a script that can be used on a database at any migration.
  --no-transactions Don't generate SQL transaction statements.
  -c|--context <DBCONTEXT> The DbContext to use.
  -p|--project <PROJECT> The project to use. Defaults to the current working directory.
  -s|--startup-project <PROJECT> The startup project to use. Defaults to the current working directory.
  --framework <FRAMEWORK> The target framework. Defaults to the first one in the project.
  --configuration <CONFIGURATION> The configuration to use.
  --runtime <RUNTIME_IDENTIFIER> The runtime to use.
  --msbuildprojectextensionspath <PATH> The MSBuild project extensions path. Defaults to "obj".
  --no-build Don't build the project. Intended to be used when the build is up-to-date.
  -h|--help Show help information
  -v|--verbose Show verbose output.
  --no-color Don't colorize output.
  --prefix-output Prefix output with level.

About --idempotent flag

As specified by the usage, this is used to generate a script that can be used on a database at any migration.

When this flag is set, the EF tool will generate scripts to check if any migration script is already applied to database; if yes, it will skip running that script.

Example

dotnet ef migrations script --idempotent

For more information, refer to official documentation: Applying Migrations.

More from Kontext
comment Comments
No comments yet.

Please log in or register to comment.

account_circle Log in person_add Register

Log in with external accounts