一、前言
Entity Framework(后面简称EF)作为微软家的ORM,自然而然从.NET Framework延续到了.NET Core。
二、程序包管理器控制台
为了能够在控制台中使用命令行来操作EF,需要先安装Microsoft.EntityFrameworkCore.Tools。
安装
Install-Package Microsoft.EntityFrameworkCore.Tools
![](http://upload-images.jianshu.io/upload_images/7131940-3dc87d7c373aaad4.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/790/format/webp)
更新
通过该指令就可以升级Microsoft.EntityFrameworkCore.Tools
Update-Package Microsoft.EntityFrameworkCore.Tools
查看
通过该指令就可以查看Microsoft.EntityFrameworkCore.Tools
Get-Help about_EntityFrameworkCore
![](http://upload-images.jianshu.io/upload_images/7131940-3930db6707bbe7c6.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/910/format/webp)
出现以上描述,则说明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.