简体   繁体   English

如何在实体框架 6 中为 SQL 查询创建迁移?

[英]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.

相关问题 我可以将任意SQL查询映射到Entity Framework字段吗? - Can I map arbitrary SQL queries to Entity Framework fields? 如何使用Entity Framework 4.2执行数据库迁移? - How can I perform database migration using Entity Framework 4.2? 如何动态构建实体框架查询? - How can I build Entity Framework queries dynamically? 实体框架5和SQL查询 - Entity Framework 5 and SQL Queries 如何从实体框架实体(对象)创建列表? - How can I create a List off of an Entity Framework entity (object)? 如何基于具有实体框架的现有 DbContext 为 Docker 图像创建 SQL 服务器数据库方案? - How can I create the SQL Server database scheme for a Docker image based on an existing DbContext with Entity Framework? 每次使用Entity Framework更新数据库时如何创建新迁移 - How do I create a new migration each time I update the database with Entity Framework 如何首先在特定路径中通过实体框架代码创建 sql 数据库 - how can i create sql database by entity framework code first in specific path “脚本迁移”可以在 .NET Entity Framework Core 中创建数据库吗? - Can "Script-Migration" create the database in .NET Entity Framework Core? Entity Framework Core 迁移是否会影响 SQL 服务器索引? - Is Entity Framework Core migration can affect SQL Server indexes?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM