在Entity Framework Core C#中获取用于特定迁移的SQL文件

编程入门 行业动态 更新时间:2024-10-27 05:30:26
本文介绍了在Entity Framework Core C#中获取用于特定迁移的SQL文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我正在使用Visual Studio EF Core例如,我有迁移文件

I am using visual studio, EF Core I have for example Migration files

例如 20210314142045_RemoveCitizenShip3.cs 作为使用Microsoft.EntityFrameworkCore.Migrations;

for example 20210314142045_RemoveCitizenShip3.cs as using Microsoft.EntityFrameworkCore.Migrations;

namespace CertificateSystem.DB.DB.Migrations { public partial class RemoveCitizenShip3 : Migration { protected override void Up(MigrationBuilder migrationBuilder) { migrationBuilder.DropColumn( name: "CitizenShip", schema: "CertificateSystem", table: "CommercialEntity"); } protected override void Down(MigrationBuilder migrationBuilder) { migrationBuilder.AddColumn<int>( name: "CitizenShip", schema: "CertificateSystem", table: "CommercialEntity", nullable: true); } } }

我想把我的项目发布到产品中,我知道迁移不是处理产品的好方法我认为更新数据库的最佳方法是在开发版本上进行迁移,并从中创建SQL,然后在生产环境中执行SQL

I want to take my project and publish it to production I understand that Migrations Is not a good way to work with on a production I think the best way to update my database it is to make a Migration on the developing version and create a SQL out of it and execute the SQL on the production

我的问题是如何从迁移文件创建SQL文件?

My problem is how do I create a SQL file from a Migration file?

我已阅读 stackoverflow/questions/49552550/get-sql-file-for-specific-migration-in-entity-framework-6-c-sharp

我看到从X到Y的Script-Migration做了一些工作,但是如果我想在特定文件上做呢?我该怎么办?

And I saw that Script-Migration -From X -to Y do some work but If I want to do it on specific file? How can I do it?

推荐答案

您可以

Script-Migration -From <PreviousMigration> -To <LastMigration>

就您而言,

Script-Migration 20180904195021_InitialCreate

上面的示例使用迁移ID为InitialCreate迁移后的所有迁移创建脚本.请参见文档如果您使用的是核心CLI工具,

The above example creates a script for all migrations after the InitialCreate migration, using the migration ID. See the documentation And if you're using core CLI tools,

dotnet ef migrations script 20180904195021_InitialCreate

始终遵循文档

更多推荐

在Entity Framework Core C#中获取用于特定迁移的SQL文件

本文发布于:2023-11-14 03:12:26,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1586058.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:文件   Framework   Entity   SQL   Core

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!