问题描述
我正在使用 EF Code First 的项目中工作.我正在尝试使用迁移功能.我不想使用包控制台管理器.如何以编程方式执行添加迁移"和更新数据库"?
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
推荐答案
你有几个选择.您可以在代码中使用 dbmigrator 类:http://romiller.com/2012/02/09/running-scripting-migrations-from-code/
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/
或者您可以使用 migrate.exe,它可以方便地在构建步骤等中运行它们.https://msdn.microsoft.com/en-us/data/jj618307.aspx
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 中以编程方式使用迁移?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!