一、.NetCore EF 之命令行


一、前言

    最近在學習研究ABP,使用到微軟的ORM框架 Entity Framework(后面簡稱EF),將其基本操作記錄下來。

二、程序包管理器控制台

為了能夠在控制台中使用命令行來操作EF,需要先安裝Microsoft.EntityFrameworkCore.Tools

安裝
Install-Package Microsoft.EntityFrameworkCore.Tools
更新

通過該指令就可以升級Microsoft.EntityFrameworkCore.Tools

Update-Package Microsoft.EntityFrameworkCore.Tools 
查看

通過該指令就可以查看Microsoft.EntityFrameworkCore.Tools

Get-Help about_EntityFrameworkCore

 

 


 

 
出現以上圖形信息,則說明 Microsoft.EntityFrameworkCore.Tools安裝成功,下面就可以進行更新、創建、刪除數據庫和數據表了。

 


三、命令行指令

  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-Migration Generates a SQL script from migrations. Update-Database Updates the database to a specified migration.




四、CodeFirst 命令步驟

添加EntityFramework

命令:Install-Package EntityFramework

1、啟用遷移

Enable-Migrations 

2、為掛起的Model變化添加遷移腳本

Add-Migration 名字    (在已有數據庫中使用Code First時標記當前數據庫狀態: Add-Migration 名字 -IgnoreChanges)

3、將掛起的遷移更新到數據庫

Update-Database



免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM