如何在实体框架核心中的运行时上创建迁移 [英] How to Create Migration on Runtime in Entity Framework Core
问题描述
是否有任何可能的方法可以在efcore中的运行时上创建迁移.
Is there any possible way to create migration on runtime in efcore.
context.Database.Migrate();
在此代码之前,我需要一个代码,当我启动我的应用程序时,应在postgresql数据库表和ef模型之间创建有关diff的迁移.
Before this code, I need a code that, when I started my app, should create a migration about diff between postgresql database tables and ef models.
有什么办法吗?
PM> enable-migrations
PM> add-migration initial
PM> update-database
我不想使用这些.我想在运行时执行这些代码的工作.我希望我能清楚地解释自己.
I dont want to use these ones. I want to make these code's jobs on runtime. I hope I could explain myself clearly.
推荐答案
注意,您需要在调用Add-Migration之后重新编译应用程序.在应用运行时很难做到这一点.
Note, you need to re-compile the app after calling Add-Migration. It's very difficult to do this while the app is running.
已通读已关闭的自动迁移问题替代解决方案.
Have a read through the closed Automatic Migrations issue for some alternative solutions.
这篇关于如何在实体框架核心中的运行时上创建迁移的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!