Entity Framework Core工具使用命令列
阿新 • 來源:網路 • 發佈:2022-01-31
命令列表
Cmdlet Description
-----------------------FvXdVVBJO--- -----------------------------------------------http://www.cppcns.com----
Add-Migration Adds a new migration.
Drop-Database Drops the database.
Get-DbContext Gets information about a DbContext type.
Remove-Migrwww.cppcns.comation Removes the last migration.
Scaffold-DbContext Scaffolds a DbContext and entity types for a database.
Script-DbContext Generates a SQL script from the current DbContext.
Script-Migration Generates a SQL script from migrations.
Update-Database Updates the database to a specified migration.Add-Migration
說明: 新增新的遷移。

以下示例建立一個指定名稱A的遷移
- Add-Migration A
Drop-Database
說明: 刪除。

以下示例刪除資料庫
- Drop-Database -WhatIf
Get-DataContext
說明: 獲取資料庫上下文得相關資訊
Remove-Migration
說明: 刪除上次遷移(回滾為遷移完成的程式碼更改)

以下示例強制刪除上一次遷移
- Remove-Migration -Force
Scaffold-DbContext
說明: 為資料庫和實體型別生成程式碼。為了生成實體型別,資料庫表必須具有主鍵。DbContextScaffold-DbContext

Script-Migration
說明: 生成 SQL ,該指令碼將從一個選定遷移到另一個選定遷移的所有更改應用。

下面的示例使用遷移名稱為初始建立遷移建立指令碼FvXdVVBJO。
- Script-Migration -To InitialCreate
下面的示例使用遷移 ID 為初始建立遷移後的所有遷移建立指令碼。
- Script-Migration -From 20180904195021_InitialCreate
Update-Database
說明: 將資料庫更新為上次遷移或指定的遷移。

下面示例為還原所有遷移
- Update-Database -Migration 0
以下示例將資料庫更新為指定的遷移。第一個使用遷移名稱,第二個使用遷移 ID 和指定的連線: - Update-Database -Migration InitialCreate
- Update-Database -Migration 20180904195021_InitialCreate -Connection your_connection_string
到此這篇關於Entity Framework Core工具使用命令列的文章就介紹到這了。希望對大家的學習有所幫助,也希望大家多多支援我們。
