[英]How I can create migration for SQL queries in Entity Framework 6?
I am using Entity framework 6 code 1st.我正在使用实体框架 6 代码 1st。
I have couple SQL queried as follows:我有一对 SQL 查询如下:
delete from [dbo].[User];
insert into [dbo].[User] (id, permission_id)
values (1, (select [id] from [permission] where [name] = 'write')),
(......
I need to Add Migration for these Scripts, How I can create migration for SQL queries?我需要为这些脚本添加迁移,如何为 SQL 查询创建迁移?
install the ef core tools ( reference )安装 ef 核心工具(参考)
dotnet tool install --global dotnet-ef
issue a command from the cli to create a migration ( reference )从 cli 发出命令以创建迁移( 参考)
dotnet ef migrations add InitialCreate
You will also need to have a reference to Microsoft.EntityFrameworkCore.Design
in the startup project.您还需要在启动项目中引用
Microsoft.EntityFrameworkCore.Design
。
In a lot of my work I have a web assembly (api) and a separate model/repository assembly, so a typical migration command for me looks like在我的很多工作中,我都有一个 web 程序集(api)和一个单独的模型/存储库程序集,所以对我来说典型的迁移命令看起来像
dotnet ef migrations add MigraitonName -s StartupProject -p RepositoryProejct -c DbContext
Once you have a migration you can run the following command to update your database完成迁移后,您可以运行以下命令来更新数据库
dotnet ef database update
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.