The last week I have been deep diving into Entity Framework and Code-First. For an old-school database programmer who started the career in Oracle SQL plus, and continued to Microsoft SQL Server Management Studio the transmission has not been easy 🙂
The concept is similar, but the definition of the database is very close to the code. You define your table as classes (model) and set up the columns as properties and relationship in navigation properties. This is easy to understand, but the difficult part is to find all the tweaks to be able to set the proper multiplicity (1:1 and 1:m,) default values for columns, and last but not least audit triggers on columns like CreatedOn, CreatedBy, UpdatedOn and UpdatedBy. However, these topics are covered for my next few posts.
After experimenting the last week with Entity Framework Code-First, I suddenly had about 10-15 different migrations/Versions in my solution. That was not ideal and I wanted to find a way to reset the migration history and make the current version of my domain model as the initial migration for the project.
This can be achieved by the following commands in the “Package Manager Console” in Visual Studio 2012:
update-database -targetmigration:"0" -force -verbose add-migration Initial update-database
Now, I have a clean “Models” and “Migration” folder…Quite nice!