1

I have the application developed in ASPNET MVC 6, I used the entity framework, I already have the migration created which is already prepared to introduce values ​​in the database.

What I intend is that when starting the application it does the update-database, is it possible? If yes how to do.

That is, I don't want to do the update-database before starting the application.

1 Answers1

1

For .Net6, to run migrations on app start, you can add code in the program.cs

using (var scope = app.Services.CreateScope())
{
    var services = scope.ServiceProvider;

    var context = services.GetRequiredService<MyDBContext>();    
    context.Database.Migrate();
}
.
.
.
app.Run()

If it's more on seeding the data, you can refer this thread How to seed data in .NET Core 6 with Entity Framework?

WisdomSeeker
  • 854
  • 6
  • 8