0

At the moment I'm using .edmx file & database first approach to develop my application. But whenever a changes occur in the database, .edmx file needs to be updated, which seems a bit too much. Once I heard that we can use code first approach but use an existing database at the same time which will relive me from updating the .edmx manually. I've followed this tutorial from microsoft.

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

At the bottom of this tutorial, I found this:

What if My Database Changes?

The Code First to Database wizard is designed to generate a starting point set of classes that you can then tweak and modify. If your database schema changes you can either manually edit the classes or perform another reverse engineer to overwrite the classes.

But I couldn't understand the point. Does it mean I need to delete all the previous classes & create again? I tried to create another model with the same name, expecting the file to overwrite the existing one, but that was not possible.

Is there any other workaround?

Badhon Jain
  • 806
  • 5
  • 20
  • 34
  • `reverse engineer to overwrite the classes.` mean it will delete all previous classes & re-create, but it will be done automatically, with this approach, it's almost database-first. `Code-first`, as it's called, mean you prefer coding first. – NeedAnswers Nov 19 '14 at 09:18
  • How the changes in database will be mapped? If I recompile the code or do I need to do something? Can you please explain a bit more? – Badhon Jain Nov 19 '14 at 09:22
  • 1
    My advice: don't use Code First for an existing database, unless you have real good reason and determine to achieve it. Code-First approach means you make the schema changes by coding in your POCO classes which represent database entities first, then .Net will automatically make the real changes in the database. Database-First is vice versa, you made the changes in the database, and using wizard to recreate EDMX. Please take a look here : http://stackoverflow.com/questions/5446316/code-first-vs-model-database-first – NeedAnswers Nov 19 '14 at 09:28
  • so it seems the hype about code first isn't that worthy! If I'm comfortable with the database first approach, then no reason to leave it, right? any performance issue? – Badhon Jain Nov 19 '14 at 09:41
  • 1
    yes, there are opinions that CODE FIRST is faster, but for normal-scale project, I don't see much differences between those two – NeedAnswers Nov 19 '14 at 13:25
  • If you would like to go in a safe way, first create your classes from db to Code First. Then if you db schema changes then create a test project and generate your classes over there, then you can simply compare old & new classes and merge them. You can use compare tools like "BeyondCompare" to merge changes pretty quick. – Teoman shipahi Jul 14 '15 at 13:43

0 Answers0