Launching a DNX Database (EF7) Migration to Azure

I ran an MVC project with ASP.NET 4.6 and EF7 locally, and everything works fine. I started dnx. ef The primary commands for creating the database tables, and everything went fine. The application is working.

With Azure I have one problem, I cannot start dnx. ef, so my SQL database is empty. I debugged Startup.cs and the connection string was restored correctly, but there are no tables there.

I used the Publish option in Visual Studio 2015 to deploy to my Azure Web App.

How can I run this command in my web application? Is there any other way to create a database?

thanks

+7
azure database-migration entity-framework-core dnx
source share
1 answer

The EF team seems to have eliminated the infamous database initializers and offers a more universal method for version 7.

Just use these methods in the pipeline before any call to the database,

yourDbContext.Database.EnsureCreated(); 

to create a database if it does not exist, and

 yourDbContext.Database.Migrate(); 

to apply migration (if you use this function later). Both of the above methods also have an asynchronous version.

In my solution, I created a static class that I use to initialize the database and populate it with some data. I call the Seed method from the Configure method in the Startup class when a condition is met.

+10
source share

All Articles