Dotnet Core 2 EF code first, database migrations on cloud foundry

.net-core cloudfoundry deployment ef-migrations entity-framework-core

Question

I use in my a project (using .Net core 2, EF core 2.1) according to this tutorial the code first approach. Everything works and now I would like to deploy my application on the cloud foundry, but the problem is, that there is no dotnet cli to run command lines like dotnet ef database update. So my question is, how should I deploy my project?

1
1
1/10/2018 8:38:53 AM

Accepted Answer

Just use in Startup, this will apply migrations to your database when your app starts running:

public void Configure(IApplicationBuilder app, IHostingEnvironment env)
{
                using (var serviceScope = app.ApplicationServices.GetService<IServiceScopeFactory>().CreateScope())
                {
                    var context = serviceScope.ServiceProvider.GetRequiredService<YourDbContext>();
                    context.Database.Migrate();
                }
}
4
1/10/2018 1:25:10 PM


Related Questions





Related

Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow