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 @   郑小超  阅读(379)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 分享一个免费、快速、无限量使用的满血 DeepSeek R1 模型,支持深度思考和联网搜索!
· 基于 Docker 搭建 FRP 内网穿透开源项目(很简单哒)
· ollama系列01:轻松3步本地部署deepseek,普通电脑可用
· 25岁的心里话
· 按钮权限的设计及实现
历史上的今天:
2017-05-10 C# 装箱和拆箱
点击右上角即可分享
微信分享提示