dotnet-ef
Manage Entity Framework Core databases
TLDR
Update the database to a specified migration
Drop the database
List available DbContext types
Generate code for a DbContext and entity types for a database
Add a new migration
Remove the last migration, rolling back the code changes that were done for the latest migration
List available migrations
Generate an SQL script from migrations range
SYNOPSIS
dotnet ef [options] [command] [arguments]
PARAMETERS
-h|--help
Show help information
--version
Show version information
-v|--verbose
Show verbose output (+v, ++v, +++v for more detail)
--no-color
Disable ANSI color output
--prefix-output
Prefix output lines with log level
DESCRIPTION
dotnet ef is the command-line interface for Entity Framework Core (EF Core), Microsoft's ORM for .NET. It enables developers to manage database schemas, migrations, and model scaffolding efficiently.
Primary uses include:
• Creating, adding, and applying migrations to evolve database schemas from C# models (code-first).
• Scaffolding DbContext and entity classes from existing databases (database-first).
• Dropping, updating, or scripting database operations.
Integrated with the .NET SDK, it supports databases like SQL Server, PostgreSQL, MySQL, and SQLite. Typical workflow: design models, run dotnet ef migrations add InitialCreate, then dotnet ef database update. Verbose logging and color output aid debugging.
Essential for ASP.NET Core apps, it automates repetitive tasks, ensuring consistency between code and database. Requires specifying project, startup project, or connection strings via options.
CAVEATS
Requires global or local installation via dotnet tool install --global dotnet-ef. Specify --project or --startup-project for multi-project solutions. Subcommands have additional options; use --help for details.
SUBCOMMANDS
dbcontext: info, list, scaffold.
database: drop, update.
migrations: add, list, remove, script.
INSTALLATION
dotnet tool install --global dotnet-ef --version 8.0.0 (match EF Core version). Or dotnet tool install dotnet-ef for local use.
HISTORY
Stable release with EF Core 2.0 (2017); preview in EF Core 1.x. Evolved with .NET releases, adding support for new providers and features like design-time factories.
SEE ALSO
dotnet(1)


