dotnet-ef is the command-line tool for Entity Framework Core (EF Core) design-time work. In a board-game API, it can turn C# entities into database tables, keep those tables aligned with model changes, and prepare schema changes for deployment. section 4.3.2 section 4.3.5
A code-first setup follows this sequence:
- Install the EF Core packages and dotnet-ef, then run `dotnet ef` to check that the tool is available. The `--global` installation switch makes it available across projects. section 4.3.2
- Create the entity classes and `ApplicationDbContext`, and configure its database connection string. These give migrations a model and a database to work with. section 4.3.5 section 4.5
- Run `dotnet ef migrations add Initial` from the project root to generate an initial migration. Check for the new `/Migrations/` folder: it contains the migration and a model snapshot used to calculate later changes. section 4.3.5
- Run `dotnet ef database update Initial` to apply that migration. Adding a migration creates files; updating the database is the separate step that changes its structure. section 4.3.5
Code-first starts with C# entities and uses migrations to generate and update the schema. Database-first starts with an existing schema and uses scaffolding to generate entities. To roll back a later schema change, apply an earlier migration and inspect the database to confirm the unwanted tables or columns are gone. section 4.3.2 section 4.4.6
Preparing a production database
Run `dotnet ef migrations script -o ./Migrations/script.sql` on a development machine to generate a SQL script for the missing board-game tables. A DBA can review the script before it runs in production. A migration bundle is another option: it runs without requiring dotnet-ef on the production machine. section 12.4.4
