多个CodeFirst迁移 [英] Multiple CodeFirst Migration

查看:122
本文介绍了多个CodeFirst迁移的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的本地计算机上,从Visual Studio,我在桌面myTable上进行了几次数据库迁移(因为第一次不是我想要的)。 

 201610202156479_myTable_migration_1.cs 
201610202156479_myTable_migration_2.cs
201610202156479_myTable_migration_3.cs
201610202156479_myTable_migration_4.cs

201610202156479_myTable_migration_1.cs:已添加4 new int columns

201610202156479_myTable_migration_2.cs:在Visual Studio中,将4个int列更改为可为空,即



< pre class ="prettyprint"> public int? intMyNewCol1 {get;组; }

201610202156479_myTable_migration_3.cs:从4个新的int列创建外键到另一个表

201610202156479_myTable_migration_4.cs:removed  4个新的int列,并添加了4个新的varchar列



我希望上次迁移(4个新的varchar列)成为迁移到生产系统的列。



在检查数据库迁移到TFS时,是否需要签入上述所有4次迁移?

我们是否需要对生产数据库进行所有4次迁移?


感谢你。


解决方案

你好aujong,


如果您想迁移到生产系统。我建议你可以参考Jon Smith的文章,你需要比较EF / SQL数据库。


https://www.simple-talk.com/dotnet/net-framework/deploying-an-entity-framework-database-into -production /


祝你好运,


Cole Wu


On my local machine, from Visual Studio, I did a database migration a few times (because the first wasn’t what I wanted) on table myTable. 

201610202156479_myTable_migration_1.cs
201610202156479_myTable_migration_2.cs
201610202156479_myTable_migration_3.cs
201610202156479_myTable_migration_4.cs

201610202156479_myTable_migration_1.cs: added 4 new int columns
201610202156479_myTable_migration_2.cs: in Visual Studio, changed the 4 int columns to be nullable, ie

public int? intMyNewCol1 { get; set; }

201610202156479_myTable_migration_3.cs: created foreign key from the 4 new int columns to another table
201610202156479_myTable_migration_4.cs: removed the 4 new int columns, and added 4 new varchar columns

I want the last migration (4 new varchar columns) to be the one migrated to Production system.

When checking in the database migration to TFS, do I need to check in all 4 migrations above ?
Do we need to do all 4 migrations to the Production database ?

THank you.

解决方案

Hi aujong,

If you wan to migrate to production system. I would suggest that you could refer Jon Smith's article, which you need to comparing EF/SQL databases.

https://www.simple-talk.com/dotnet/net-framework/deploying-an-entity-framework-database-into-production/

Best regards,

Cole Wu


这篇关于多个CodeFirst迁移的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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