Linux command
dotnet-ef 命令
安全
权限或系统影响较大,执行前请核对目标。
常用示例
Add migration
dotnet ef migrations add [MigrationName]
Update database
dotnet ef database update
List migrations
dotnet ef migrations list
Remove last migration
dotnet ef migrations remove
Generate SQL script
dotnet ef migrations script -o [script.sql]
Rollback to migration
dotnet ef database update [MigrationName]
Scaffold DbContext
dotnet ef dbcontext scaffold "[connection_string]" [Microsoft.EntityFrameworkCore.SqlServer]
说明
dotnet ef is the Entity Framework Core CLI tools for database migrations and scaffolding. It enables code-first database development and reverse engineering from existing databases. The migrations system tracks schema changes in code, generating incremental updates that can be applied to databases. Each migration is a class describing schema modifications. dbcontext scaffold reverse-engineers a DbContext and entity classes from an existing database, useful for database-first development or migrating legacy databases.
参数
- migrations add _NAME_
- Create new migration.
- migrations list
- List available migrations.
- migrations remove
- Remove last migration.
- database update _MIGRATION_
- Apply migrations to database.
- dbcontext scaffold _CONN_ _PROVIDER_
- Generate code from database.
- --context _NAME_
- DbContext class to use.
- --project _PATH_
- Project containing DbContext.
- --help
- Display help information.
FAQ
What is the dotnet-ef command used for?
dotnet ef is the Entity Framework Core CLI tools for database migrations and scaffolding. It enables code-first database development and reverse engineering from existing databases. The migrations system tracks schema changes in code, generating incremental updates that can be applied to databases. Each migration is a class describing schema modifications. dbcontext scaffold reverse-engineers a DbContext and entity classes from an existing database, useful for database-first development or migrating legacy databases.
How do I run a basic dotnet-ef example?
Run `dotnet ef migrations add [MigrationName]` in a terminal, then adjust file names, paths, flags, or remote targets for your system.
What does migrations add _NAME_ do in dotnet-ef?
Create new migration.