I have to create a new project and (as usual) is with an existing SQL Server database.
I used to use EF Code First connecting with my database, opening my EDMX model designer and then right click –> Add Code Generation Item. (http://weblogs.asp.net/jgalloway/archive/2011/02/24/generating-ef-code-first-model-classes-from-an-existing-database.aspx) Easy.
But now I’ve discovered there’s something called EF Power Tools that allows me to do Reverse Engineer Code First (cool name!) and get the same (http://msdn.microsoft.com/en-us/data/jj200620)
Do you know the difference between the two options? Which one is better?
Thanks in advance.
(Sorry if this question was previously asked but I didn’t find it.)
The difference is that the edmx approach is not code first, but database first with
DbContextAPI. You will always use the database as the source of model changes.EF Power Tools produce a truly code first model with
DbContext: from then on you will change the class model first and modify the database accordingly (e.g. by EF migrations).Neither is “better”.
DbContextAPI is easier to work with thanObjectContext, but both approaches use the former. It’s up to you to choose whether you want to work database first or code first. It’s a matter of personal preference and it may depend on who maintains the database structure. With database first it is easier to respond to changes someone else imposes on the database structure.