EF Core相关工具使用

1、安装ef tools

首先确保本地netcore sdk安装完毕,如下是卸载tool、安装指定版本tool、更新到指定版本的tool 的命令:

dotnet tool uninstall --global dotnet-ef
dotnet tool install --global dotnet-ef --version 5.0.0
dotnet tool update --global dotnet-ef --version 5.0.5

 

2、在目标项目安装Microsoft.EntityFrameworkCore.Tools nuget包 

 

3、定位到指定项目解决方案下(..csproj文件不是sln) 让cmd工作目录定位到当前目录

 

4、迁移dbcontext

dotnet ef migrations add InitialIdentityServerPersistedGrantDbMigration -c PersistedGrantDbContext -o Data/Migrations/IdentityServer/PersistedGrantDb

 

5、更新到数据库

dotnet ef database update --context PersistedGrantDbContext

 

6、删除指定上下文对应的数据库(慎用)

dotnet ef database drop --context PersistedGrantDbContext

 

7、为迁移创建sql脚本

dotnet ef migrations script 0  20220510070558_InitialIdentityServerPersistedGrantDbMigration --context PersistedGrantDbContext -o Data/Migrations/IdentityServer/PersistedGrantDb/1.sql

注意:指令中的script 0 代表为20220510070558_InitialIdentityServerPersistedGrantDbMigration创建迁移脚本,如果不加0,如下:

dotnet ef migrations script 20220510070558_InitialIdentityServerPersistedGrantDbMigration --context PersistedGrantDbContext -o Data/Migrations/IdentityServer/PersistedGrantDb/1.sql

则代表为20220510070558_InitialIdentityServerPersistedGrantDbMigration之后的迁移创建迁移脚本.

 dotnet tool update --global dotnet-ef
posted @ 2022-05-10 15:22  郑小超  阅读(335)  评论(0编辑  收藏  举报