Deploy Entity Framework Code First

…衆ロ難τιáo~ 提交于 2019-12-20 12:04:04

问题


I guess I should have thought of this before I started my project but I have successfully built and tested a mini application using the code-first approach and I am ready to deploy it to a production web server.

I have moved the folder to my staging server and everything works well. I am just curious if there is a suggested deployment strategy?

If I make a change to the application I don't want to lose all the data if the application is restarted.

Should I just generate the DB scripts from the code-first project and then move it to my server that way?

Any tips and guide links would be useful.

Thanks.


回答1:


Actually database initializer is only for development. Deploying such code to production is the best way to get some troubles. Code-first currently doesn't have any approach for database evolution so you must manually build change scripts to your database after new version. The easiest approach is using Database tools in VS Studio 2010 Premium and Ultimate. If you will have a database with the old schema and a database with the new schema and VS will prepare change script for you.




回答2:


Here are the steps I follow.

  1. Comment out any Initialization strategy I'm using.
  2. Generate the database scripts for schema + data for all the tables EXCEPT the EdmMetadata table and run them on the web server. (Of course, if it's a production server, BE CAREFUL about this step. In my case, during development, the data in production and development are identical.)
  3. Commit my solution to subversion which then triggers TeamCity to build, test, and deploy to the web server (of course, you will have your own method for this step, but somehow deploy the website to the web server).
  4. You're all done!

The Initializer and the EdmMetadata tables are needed for development only.



来源:https://stackoverflow.com/questions/5573868/deploy-entity-framework-code-first

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