I’m just starting to dive into ASP.net MVC3. I come from a Django background. One of the things I love about Django, is the add-on called “South”. It lets me modify my Models in code, and then I run a command, it figures out what has changed, and it updates the database accordingly.
If I add, remove, or rename a field with the “code-first” approach in EF4, what happens? Does it just add or remove the field, and that’s it? What if I want to do something like add a new field, and then perhaps run a Linq-to-SQL query to populate the new field, and then remove the old field? And I want a record of this so that when I go to deploy the change on my production server, it will run those 3 commands in sequence.
Is there something like that? Or how do people tackle situations like this? (It is pretty common…)
Edit: Found some links.
- https://softwareengineering.stackexchange.com/questions/76082/is-entity-framework-code-first-a-bit-meaningless-useless-in-production-and-what
- http://blogs.msdn.com/b/efdesign/archive/2010/10/22/code-first-database-evolution-aka-migrations.aspx
- Using EF4 Code First: How can I change the Model without losing data
- Deploying database changes with EF 4.1
- https://github.com/dradovic/MigSharp
- http://blogs.msdn.com/b/adonet/archive/2011/09/21/code-first-migrations-alpha-3-with-magic-walkthrough-automatic-migrations.aspx (Woo!)
Here’s an excellent tutorial from Microsoft MVP David Hayden:
http://www.davidhayden.me/blog/asp.net-mvc-4-and-entity-framework-database-migrations
Not sure about 4.2 – but I installed the latest EF (4.3.1) and it worked like a charm.
Pretty impressive – and I’m a Rails guy 😛