Entity Framework Core工具使用命令行
命令列表
Cmdlet Description -------------------------- --------------------------------------------------- Add-Migration Adds a new migration. Drop-Database Drops the database. Get-DbContext Gets information about a DbContext type. Remove-Migration 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
說明: 添加新的遷移。
以下示例創(chuàng)建一個(gè)指定名稱A的遷移
- Add-Migration A
Drop-Database
說明: 刪除數(shù)據(jù)庫。
以下示例刪除數(shù)據(jù)庫
- Drop-Database -WhatIf
Get-DataContext
說明: 獲取數(shù)據(jù)庫上下文得相關(guān)信息
Remove-Migration
說明: 刪除上次遷移(回滾為遷移完成的代碼更改)
以下示例強(qiáng)制刪除上一次遷移
- Remove-Migration -Force
Scaffold-DbContext
說明: 為數(shù)據(jù)庫和實(shí)體類型生成代碼。為了生成實(shí)體類型,數(shù)據(jù)庫表必須具有主鍵。DbContextScaffold-DbContext
Script-Migration
說明: 生成 SQL 腳本,該腳本將從一個(gè)選定遷移到另一個(gè)選定遷移的所有更改應(yīng)用。
下面的示例使用遷移名稱為初始創(chuàng)建遷移創(chuàng)建腳本。
- Script-Migration -To InitialCreate
下面的示例使用遷移 ID 為初始創(chuàng)建遷移后的所有遷移創(chuàng)建腳本。
- Script-Migration -From 20180904195021_InitialCreate
Update-Database
說明: 將數(shù)據(jù)庫更新為上次遷移或指定的遷移。
下面示例為還原所有遷移
- Update-Database -Migration 0
以下示例將數(shù)據(jù)庫更新為指定的遷移。第一個(gè)使用遷移名稱,第二個(gè)使用遷移 ID 和指定的連接: - Update-Database -Migration InitialCreate
- Update-Database -Migration 20180904195021_InitialCreate -Connection your_connection_string
到此這篇關(guān)于Entity Framework Core工具使用命令行的文章就介紹到這了。希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
- Entity Framework Core使用控制臺(tái)程序生成數(shù)據(jù)庫表
- Entity Framework Core延遲加載(懶加載)用法
- Entity?Framework?Core實(shí)現(xiàn)Like查詢?cè)斀?/a>
- Entity Framework Core中執(zhí)行SQL語句和存儲(chǔ)過程的方法介紹
- Entity Framework Core批處理SQL語句
- Entity Framework Core實(shí)現(xiàn)軟刪除與查詢過濾器
- Entity Framework Core生成列并跟蹤列記錄
- ASP.NET Core在WebApi項(xiàng)目中使用MiniProfiler分析Entity Framework Core
- Entity?Framework?Core關(guān)聯(lián)刪除
- 詳解如何在ASP.NET Core中應(yīng)用Entity Framework
- Entity Framework Core對(duì)Web項(xiàng)目生成數(shù)據(jù)庫表
相關(guān)文章
ASP.NET Core基礎(chǔ)之請(qǐng)求處理管道
這篇文章介紹了ASP.NET Core的請(qǐng)求處理管道,對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧2022-02-02ASP.NET Core應(yīng)用啟動(dòng)Startup類簡(jiǎn)介
這篇文章介紹了ASP.NET Core中的應(yīng)用啟動(dòng)Startup類,文中通過示例代碼介紹的非常詳細(xì)。對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下2022-04-04