Notes

.NET - Entity Framework Core notes

author: Paul Kim

categories: dotnet, ef

tags: dotnet, ef

commands

# verify EF Core CLI tools are correctly installed
dotnet restore
dotnet ef

# List available migrations
dotnet ef migrations list

# Add a new migration
dotnet ef migrations add <NAME>

# Remove the last migration
dotnet ef migrations remove

# Generate a SQL script from migrations
dotnet ef migrations script

# Drop the database for specific environment
dotnet ef database drop

# Updates the database to a specified migration
dotnet ef database update

examples

# Example 1: add new migration called "MyFirstMigration" and update database to that migration

dotnet ef migrations add MyFirstMigration
dotnet ef database update

# Example 2: update database to "CreateIdentitySchema" migration and remove the last migration

dotnet ef database update CreateIdentitySchema
dotnet ef migrations remove

# Example 3: update database to very beginning and remove last migration

dotnet ef database update 0
dotnet ef migrations remove

# Example 3: add new migration called "CreateIdentityBlogPost" in "Data/Migrations" folder

dotnet ef migrations add "CreateIdentityBlogPost" --output-dir "Data/Migrations"
dotnet ef migrations remove
Source

ChromeEdgeFirefoxOpera

© 2021 paulkode.com. All rights reserved.