实体框架代码优先迁移 [英] Entity Framework Code First Migration

查看:129
本文介绍了实体框架代码优先迁移的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

一段时间以来,我们一直在使用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

这篇关于实体框架代码优先迁移的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆