Files
irc-netcore-api/IRaCIS.Core.Infra.EFCore/CodeFirst使用说明
T
hang c1743c2934
continuous-integration/drone/push Build is running
修改模型编码测试提交
2026-03-10 11:37:48 +08:00

58 lines
1.7 KiB
Plaintext
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
# 程序包管理控制台使用方式
1、生成迁移文件(add-migration init -Project IRaCIS.Core.Infra.EFCore )
add-migration xxx名字
2、移除生成的迁移文件
Remove-Migration
3、以下命令将数据库更新为最新迁移
Update-Database
4、以下命令将数据库更新为给定迁移:
Update-Database xxxName
5、以下命令将生成一个从指定 from 迁移到指定 to 迁移的 SQL 脚本。
Script-Migration from to
针对字符串类型 不是默认长度400的需要标注:
比如 [StringLength(1000)] 设置1000
比如 [MaxLength] 自动设置为 nvarchar(max)
针对decimal 类型
默认是: [DecimalPrecision(18, 2)]
如果其他的可以这样设置比如: [DecimalPrecision(18, 4)]
# 使用dotnet 命令迁移(dotnet ef dbcontext list -p IRaCIS.Core.Infra.EFCore )
# dotnet ef migrations add 本地迁移名字 -p 项目名 -c 数据库上下文名 -o 迁移文件生成目录
1、生成迁移文件 dotnet ef migrations add Initial -s IRaCIS.Core.API -p IRaCIS.Core.Infra.EFCore -c IRaCISDBContext -o CodeFirst_MSSQL/Migrations
dotnet ef migrations add Initial -p IRaCIS.Core.Infra.EFCore
2、撤销生成的迁移文件
dotnet ef migrations remove -p IRaCIS.Core.Infra.EFCore
3、将迁移文件更新到数据库
dotnet ef database update -p IRaCIS.Core.Infra.EFCore
4、以下命令将数据库更新为给定迁移
dotnet ef database update xxxName -p IRaCIS.Core.Infra.EFCore
5、以下命令将生成一个从指定 from 迁移到指定 to 迁移的 SQL 脚本。
dotnet ef migrations script from to -p IRaCIS.Core.Infra.EFCore
6、查看迁移列表
dotnet ef migrations list -p IRaCIS.Core.Infra.EFCore