This is a multi-platform (Windows, macOS, Linux) GUI application that makes working with Entity Framework Core migrations easier.
Why you should use it:
- You'll no longer need to remember
dotnet efcommands syntax for creating, removing and generating migration scripts. - Dependency on
Microsoft.EntityFrameworkCore.Designcan be dropped inside your project. - You can remove
IDesignTimeDbContextFactory<TDbContext>implementations from your project.
Important: This tool does not apply migrations on your database. It's designed to be non-destructive and you're expected to generate migration script, review it and run it manually in database client of your choice.
- Download binaries for your platform from Releases page and launch the
efmigexecutable. - Click
[+]button to create a new configuration profile. - Fill configuration values
- Profile name: this is a label of your choice for configuration profile.
- dotnet-ef version: See NuGet page for available versions. Enter version matching your project.
- Microsoft.EntityFrameworkCore.Design version: See NuGet page for available versions.
- Target framework version: See this reference table for available versions.
- Migrations directory. Enter a path relative to location of C# project where DbContext exists. Default value is
Migrations. - DbContext .csproj path: pick the path of C# project that holds your DbContext class.
- DbContext fully qualified name: this is a full class name of DbContext, for example
MyApp.MyDbContext. - DbContext configuration: you can use either the Visual Builder or Custom Code mode. See explanation below.
- Save profile.
You have two options for configuring your database connection:
The Visual Builder provides a user-friendly interface to configure your connection:
- Select "Visual Builder" mode in the Configuration Mode section.
- Choose your database provider from the dropdown (PostgreSQL, MySQL, SQL Server, or SQLite).
- Either:
- Fill in individual connection fields (Server, Port, Database, Username, Password), or
- Check "Use connection string directly" and paste your connection string.
- The generated C# code will be shown in real-time in the preview box.
The Visual Builder automatically generates the correct connection code for your selected database provider with proper defaults.
If you prefer to write the configuration code manually:
- Select "Custom Code" mode.
- Write your configuration code directly using C# syntax.
The optionsBuilder variable of type DbContextBuilder<TYourDbContext> is available for you to configure.
Postgres example:
var connectionString = "Host=myserver;Username=mylogin;Password=mypass;Database=mydatabase";
optionsBuilder.UseNpgsql(connectionString);MySQL example:
var connectionString = "server=localhost;user=myuser;password=mypassword;database=mydb;";
var serverVersion = ServerVersion.AutoDetect(connectionString);
optionsBuilder.UseMySql(connectionString, serverVersion);You can invoke one of the following actions:
- Create a new migration. Specify its name beforehand and click
[+]button on the right. - General actions:
- List migrations. This action does nothing but lists already existing migrations.
- Generate full migration script. This action opens default text editor with SQL code of all migrations for you to review.
- Generate unapplied migration script. This action generates SQL script for only the migrations that haven't been applied yet.
- Generate optimized model.
- Last migration actions:
- Remove from code. This action removes most recent migration from the code. Nothing will happen on the actual database. Will fail if the migration is already applied on database - in that case, use "Generate rollback script" action first.
- Recreate and generate script. This action recreates the last migration and generates a SQL script for you to review and manually apply.
- Generate apply script. This actions generates SQL script of last migration for you to review and manually apply.
- Generate rollback script. This action generates SQL script that rolls back last migration for you to review and manually apply.