I am building a solution with the following Projects:
Main.Data
- Class Library projectMain.API
- Asp.NET MVC WebApi - references Main.DataMain
- Asp.NET MVC 4 web application - references Main.APII have a MyContext : DbContext
class located inside Main.Data
project.
I have also successfully issues enable-migrations
console command on Main.Data
project, and I am successfully using LocalDB as an SQL server for my data and for upgrade-database
migrations.
The problem starts when I am trying to publish Main
project to Windows Azure website.
The Publish Profile that is automatically created using Import from a Windows Azure web site
does not seems to recognize that I am using Entity Framework Code First solution, and so I can't enable Execute Code First Migrations
as I would like to.
Instead, I can only enable Update database
scripts.
I am using Visual Studio 2012 with Entity Framework 5.0.0 (Since the beginning of the project).
Just to verify, I have tried to add a temporary MyContext
class inside the Main
Project and to enable-migrations
on the Main
project, and after that my Publish Profile automatically detected Entity Framework Code-First.
That is, of-course, not a solution (or is it?)
Here are some relevant threads:
I am looking for a clean stable solution. Do I have to put my Context class inside the Main Project?
Thanks in advance
Run the Add-Migration InitialCreate command in Package Manager Console. This creates a migration to create the existing schema. Comment out all code in the Up method of the newly created migration. This will allow us to 'apply' the migration to the local database without trying to recreate all the tables etc.
Step 1 − Before running the application you need to enable migration. Step 2 − Open Package Manager Console from Tools → NuGet Package Manger → Package Manger Console. Step 3 − Migration is already enabled, now add migration in your application by executing the following command.
I can now enable Execute Code First Migrations
when I create a publish profile.
Here is what I did to achieve it:
Main/Web.config
I changed the name of the connection string to the FQN of the context class: Main.Data.MyContext
.Main
project to Main.Data
Project (which was not needed until now).This does the job for me.
If anyone got a better or more educating answer, I would be happy to hear it.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With