2

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 Answer 1

2

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?

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.