Entity Framework Migrations with Multiple Web Config Transforms

孤人 提交于 2019-12-08 19:49:40

问题


I have created an ASP.NET MVC 4 project in Visual Studio 2010 using Entity Framework 5 with migrations enabled. I have multiple web config files for different environments (Debug, Staging, Release) which will specify different database connectionStrings depending on the environment. How do I handle migrations using the Update-Database command from the Package Manager Console with the multiple config files? Each time I run this command, it defaults to the main Web.config connection string. Thanks for any help in advance.


回答1:


In order to try and keep things as simple as possible, the way I worked around running migrations on my remote staging and production servers, is to run the following command from the package console (data source and user/pass would change depending on which server I wanted to run the migrations against):

Update-Database -Verbose -ConnectionString "Data Source=ServerName;Initial Catalog=db;User Id=user;Password=pass;" -ConnectionProviderName "System.Data.SqlClient"

This has worked for me so far in case anyone else is looking. Thanks everyone for the comments.




回答2:


To migrate to different envrionment, you should use Web config transform tool, I don't think it's the responsibility of Entity Framework Migrations.




回答3:


http://msdn.microsoft.com/en-us/data/jj618307.aspx

EF Code First Migrations comes with a migrate tool which allows you to run the 'update' commands via command prompt.

I'm not really sure how your set up, but we did something similar where we deploy code through our CI server (Jenkins). I then added a post deployment step to run the update-database via command line.

What's great about it is you can specify connection strings too.

Again, it all depends how this fits into your process, you could even use Nant to execute this for you.

Hope this helps.



来源:https://stackoverflow.com/questions/14896821/entity-framework-migrations-with-multiple-web-config-transforms

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!