如何在EntityFramework Codefirst中以编程方式使用迁移? [英] How to use migration programmatically in EntityFramework Codefirst?

查看:95
本文介绍了如何在EntityFramework Codefirst中以编程方式使用迁移?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在一个使用EF Code First的项目中工作。我正在尝试使用迁移功能。我不想使用包控制台管理器。如何以编程方式执行添加迁移和更新数据库?

 添加迁移TestMigration01 -force 

update-database


解决方案

你有几个选择。您可以在代码中使用dbmigrator类: http:/ /romiller.com/2012/02/09/running-scripting-migrations-from-code/



或者你可以使用migrate.exe这是方便的用于在构建步骤等中运行它们。
https:// msdn .microsoft.com / en-us / data / jj618307.aspx


I'm working in a project that uses EF Code First. I'm trying to use migration features. I don't want to use Package Console Manager. How can I execute the "Add-Migration" and "Update-Database" programmatically?

add-migration TestMigration01 -force

update-database

解决方案

You have a couple of choices. You can use the dbmigrator class from within your code: http://romiller.com/2012/02/09/running-scripting-migrations-from-code/

Or you can use migrate.exe which is handy for running them in a build step, etc. https://msdn.microsoft.com/en-us/data/jj618307.aspx

这篇关于如何在EntityFramework Codefirst中以编程方式使用迁移?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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