实体框架4.3迁移移动现有数据 [英] Entity Framework 4.3 Migrations move existing data

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

问题描述

我使用EF Code First 4.3迁移来更新我的数据库方案。现在我有以下情况:表A需要删除,表B必须创建,表A的数据必须与表B一起复制(以及一些其他数据)。我无法访问 DbContext DbMigration 类中,我的问题是如何实现这个?

I'm using EF Code First 4.3 Migrations to update my database scheme. Now I have the following situation: table A needs to be removed, table B must be created and the data of table A must be copied (along with some other data) to table B. I do not have access to the DbContext in the DbMigration class, my question is how to implement this?

推荐答案

在迁移向上方法中,您可以使用 Sql 方法定义所需的任何SQL,如果您使用显式迁移,您可以在创建表B并删除表A之间放置数据迁移代码。

In migration Up method of your migration you can use Sql method to define any SQL you need so if you use explicit migration you can put data migration code between creating Table B and removing Table A.

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

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