سؤال

I have an Azure website configured to deploy from Visual Studio Online (hosted TFS). I'm evaluating the move from Database First model to Code First from Existing Database model.

Currently, As I check-in code to Visual Studio Online, it is deployed to Azure website. How to configure this process to run EF Migrations on the remote (live or test) Azure SQL database when I check-in code to Visual Studio Online.

هل كانت مفيدة؟

المحلول

AFAIK, you need to use the publish profile option to achieve this.

You have to download the publish profile settings file for the website, Import the file in Visual Studio, configure the Execute Code First migrations option and then specify the profile file path in Build Definition used for Continuous deployment.

You can check below post for reference.

http://blogs.msdn.com/b/webdev/archive/2014/04/09/ef-code-first-migrations-deployment-to-an-azure-cloud-service.aspx

نصائح أخرى

I know it is a old post, but I could't find a good answer, so after figure out how to solve it I'm sharing a solution. I work in a project with DDD and N-tiers level. So, it means that the EF isn't in the same project as WebApi, therefore has no option to run migration during the publish wizard. To solve it I have ran update-database directly from package manager console.

Steps:

  1. Acquire the ADO connection string (https://azure.microsoft.com/en-us/documentation/articles/sql-database-connectivity-issues/#connections-to-azure-sql-database)

  2. From package manager console run: Update-database -StartUpProjectName NAMEPROJECTWITHEF -ConnectionString "connection string obtained from item one" -ConnectionProviderName "System.Data.SqlClient"

That's all!

Best Regards, thiago

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top