EF 4.3代码第一次迁移 - 每次迁移的种子 [英] EF 4.3 Code First Migrations - Seed per migration

查看:92
本文介绍了EF 4.3代码第一次迁移 - 每次迁移的种子的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

最近开始使用Code First Migrations,并希望在每个 Up 方法中种子数据。



这是可能吗? >

即可。


  1. 创建数据库表

  2. 填写数据

下载:


  1. 删除加入表中的数据

  2. 删除表


解决方案

p>是的,这是可能的,但是您必须通过执行SQL命令来执行此操作。在向上中使用 Sql 方法迁移执行 INSERT DELETE SQL命令。


have recently started using Code First Migrations and was wanting to seed data in each Up method.

is this possible?

Ie.

  1. Create database table
  2. Fill with data

for Drop:

  1. Delete data from joining table
  2. delete table

解决方案

Yes it is possible but you must do it through executing SQL commands. Use Sql method in both Up and Down methods of your migration to execute INSERT and DELETE SQL commands.

这篇关于EF 4.3代码第一次迁移 - 每次迁移的种子的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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