How and where to call Database.EnsureCreated and Database.Migrate?

后端 未结 5 2086
栀梦
栀梦 2020-11-28 04:49

I have a ASP.NET MVC 6 application, and i need to call the Database.EnsureCreated and Database.Migrate methods.

But where should I call the

5条回答
  •  余生分开走
    2020-11-28 05:25

    With the information that James P and Bassam Alugili provided, what I ended up doing was to add these lines of code to the Configure method in the Startup class (Startup.cs):

    using (var scope = 
      app.ApplicationServices.CreateScope())
    using (var context = scope.ServiceProvider.GetService())
        context.Database.Migrate();
    

提交回复
热议问题