How to use migration programmatically in EntityFramework Codefirst?(如何在 EntityFramework Codefirst 中以编程方式使用迁移?)
问题描述
我正在使用 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 中以编程方式使用迁移?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:如何在 EntityFramework Codefirst 中以编程方式使用迁移?


基础教程推荐
- 经典 Asp 中的 ResolveUrl/Url.Content 等效项 2022-01-01
- 错误“此流不支持搜索操作"在 C# 中 2022-01-01
- 如何动态获取文本框中datagridview列的总和 2022-01-01
- 全局 ASAX - 获取服务器名称 2022-01-01
- JSON.NET 中基于属性的类型解析 2022-01-01
- 在 VS2010 中的 Post Build 事件中将 bin 文件复制到物 2022-01-01
- 首先创建代码,多对多,关联表中的附加字段 2022-01-01
- 将事件 TextChanged 分配给表单中的所有文本框 2022-01-01
- 是否可以在 asp classic 和 asp.net 之间共享会话状态 2022-01-01
- 从 VS 2017 .NET Core 项目的发布目录中排除文件 2022-01-01