4

I'm a beginner to MVC, as well as EF. I've decided to understand things more clearly in order to perform well using these technologies.

Now, i've started reading about EF, and knew that there're Model-first, Database-first and Code-first techniques.

I really want to start with the one that will be most beneficial to me since i'm going to develop using MVC, and then get back to the other two and compare between each of them.

My only question is, which technique should i start with and use?

Rafael Adel
  • 7,673
  • 25
  • 77
  • 118

2 Answers2

2

For us, we base this on whether or not the database already exists. In many cases, we have pre-existing databases, so we use database-first. Moving forward, we've preferred to create the database and then build the model from it, as we're more experienced in doing it that way. I did code-first once and I found it to be a pain, but you do have finer control and gain a better understanding of what EF is doing behind the scenes.

Sorry I couldn't provide a better answer.

Mike C.
  • 3,024
  • 2
  • 21
  • 18
2

If i am building a new website i would use Code First definitely because Code First is:

  1. The Future of the technology (Entity Framework), all of Microsoft's effort is on developing this new tech. (I didn't come up with this my self, i read it in an article by one of Microsoft's guys, sorry i don't remember who).
  2. It was built for DDD (Domain-Driven-Development) developers which is side by side with TDD/BDD is becoming the standard (strong word) or the right way to build software systems.
  3. And as its name suggests you can start coding right ahead (which i love to do) and worry about fine persistence details later on which is what you should be doing.

I would only go for Database First if i am forced to work with an existing database.

Model First was one step forward towards Code First, so if i were you i wouldn't go backwards.

NOTE: Check out this question over here to get a better comparison Entity Framework Code First vs Model/Database First

Community
  • 1
  • 1
Ibrahim Najjar
  • 19,178
  • 4
  • 69
  • 95
  • I'm curious why working with an existing database - the default situation in most real world corporate environments - is "a step backwards". I have had to cancel contracts twice over this issue where a contractor decided that trying to nuke existing database schemas and data for the glory of "code first" was the only correct way to work. If I specify that we have data already in the contract and hundreds of tables and provide the database schema and EF... why would violating the contract and using code first be so... important. *End Rage*. (No data was lost, we read contractor code carefully.) – Godeke Mar 01 '13 at 15:25
  • 1
    @Godeke, Well i didn't say that the Database First approach was a step backwards, neither using Model First when working is an existing database because that db is probably designed by very good database professionals, what i meant is that if i am going to develop a new system i would go for Code First since this is the way software development is heading, otherwise if the system if already there i will go for db first or model first for sure. – Ibrahim Najjar Mar 01 '13 at 17:01