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 中以编程方式使用迁移?


- 在哪里可以找到使用中的C#/XML文档注释的好例子? 2022-01-01
- Web Api 中的 Swagger .netcore 3.1,使用 swagger UI 设置日期时间格式 2022-01-01
- 带有服务/守护程序应用程序的 Microsoft Graph CSharp SDK 和 OneDrive for Business - 配额方面返回 null 2022-01-01
- 良好实践:如何重用 .csproj 和 .sln 文件来为 CI 创建 2022-01-01
- C#MongoDB使用Builders查找派生对象 2022-09-04
- MoreLinq maxBy vs LINQ max + where 2022-01-01
- 输入按键事件处理程序 2022-01-01
- WebMatrix WebSecurity PasswordSalt 2022-01-01
- 如何用自己压缩一个 IEnumerable 2022-01-01
- C# 中多线程网络服务器的模式 2022-01-01