实体框架代码优先迁移

编程入门 行业动态 更新时间:2024-10-25 08:17:42
本文介绍了实体框架代码优先迁移的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

一段时间以来,我们一直在使用Entity Framework代码优先迁移技术。一切正常,但是由于我们对实体架构进行的更改,我们的Migrations文件夹变得越来越大,包含大量迁移文件。我很好奇,有没有一种方法可以在实体发生变化时仅更新一个或特定数量的文件,以使我们的Migrations文件夹看起来不那么混乱。另外,我不想删除表并重新创建它,因为我将丢失所有已保存的数据。

We are using Entity Framework code first migration technique for a while now. Everything works good however our Migrations folder has been growing big with numerous migration files because of changes we are making on entity schema. I was curious, is there a way we can update just one or specific number of files whenever there is change in entity so that our Migrations folder would look less messy. Also, i don't want to drop the table and recreate it since i will be loosing all the saved data.

推荐答案

您可以简单地将所有迁移合并到一个新文件中(如果您不关心保留每个迁移)。

You could simply merge all of your migrations into a new file (if you aren't concerned with keeping every migration).

要这样做,只需删除文件夹中当前的每个迁移,然后重新运行enable-migrations命令,然后再运行add-migration命令即可。

To do so, simply delete every migration currently in the folder, and rerun the enable-migrations command and then the add-migration command like so.

Enable-Migrations add-migration InitialCreate

更多推荐

实体框架代码优先迁移

本文发布于:2023-07-27 12:05:17,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1222345.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:实体   框架   代码

发布评论

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

>www.elefans.com

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