EF Core 遷移整理
阿新 • • 發佈:2020-07-30
EF Core 遷移整理
PowerShell Add-Migration InitialCreate 多資料來源 Add-Migration InitialCreate -Context MyDbContext -OutputDir Migrations\SqlServerMigrations Add-Migration InitialCreate -Context MySqliteDbContext -OutputDir Migrations\SqliteMigrations Console dotnet ef migrations add InitialCreate dotnet ef migrations add InitialCreate--context MyDbContext --output-dir Migrations/SqlServerMigrations dotnet ef migrations add InitialCreate --context MySqliteDbContext --output-dir Migrations/SqliteMigrations
更新資料庫
PowerShell Update-Database Console dotnet ef database update
刪除遷移
PowerShell Remove-Migration Console dotnet ef migrations remove
還原遷移
PowerShell Update-Database LastGoodMigration Console dotnet ef database update LastGoodMigration
生成遷移Sql
PowerShell Script-Migration Script-Migration -From migrationName1 -To migrationName2 -Context ContextName Console dotnet ef migrations script dotnet ef migrations script -From migrationName1 -To migrationName2 -Context ContextName
遷移指令碼的幫助說明
我們可以通過命令來獲取幫助說明
Get-Help about_EntityFrameworkCore get-help Add-Migration -full get-help Script-Migration -full