Geeks With Blogs

Paul's Petrov Whiteboard [BizTalk, Enterprise Application Integration, Business Process Automation, SOA, .NET]

EF Code First Migrations is a great way to manage data model changes in .Net application. When publishing to Azure you can enable migration by checking the box: Execute Code First Migrations on the Publish Settings wizard. This will force migrations run on each application start which may not be OK for some. If there’s seed data in Configuration.cs which is common in dev/testing this will cause it to run on each application restart. To avoid this you can resort to Update-Database command.  In order to deploy migrations to the database of choice use connection string parameter. In the Package Manager Console select project with migrations and run following command:

Update-Database -ConnectionString "{Azure Database Connection String}" -ConnectionProviderName "System.Data.SqlClient"

If you want it scripted outside of the Visual Studio, you can call EF command tool migrate.exe from PowerShell script. Something like this:

& ".\migrate.exe" DataAccess.dll /startUpConfigurationFile=DataAccess.dll.config /connectionString=$ConnectionString  /connectionProviderName="System.Data.SqlClient"

Posted on Friday, November 20, 2015 4:37 AM .Net , Azure , Continuous Integration , Entity Framework | Back to top

Comments on this post: Applying Entity Framework Code First Migrations to Azure Database

# re: Applying Entity Framework Code First Migrations to Azure Database
Requesting Gravatar...
Thank you taking the time to write down these instructions. This has saved me so much time and worked perfectly.
Left by Scott Crichton on Mar 01, 2017 10:50 PM

Your comment:
 (will show your gravatar)

Copyright © Paul Petrov | Powered by: