0

Possible Duplicate:
EF 4.1 Code-first vs Model/Database-first

i made some research, but answers did not satisfy me. I started my own asp.net mvc application with entity framework, to work with database. I started by making a db, than i create model from that database. Well i know thats called "model-first". I know the second way, of doing it from school (code first). My lecturer told me today, that model-first method is rly outdated. Well is that true? Or maybe: does code-first have any advantage? Whats the real difference, which one is better, in your opinion?

Community
  • 1
  • 1
olq
  • 151
  • 1
  • 2
  • 9

3 Answers3

0

Specifically with EF code first refers to the code and model first refers to the database.

which is better really depends on the project. If the db is treated as the core of the application, or you are using db specific features, than a model first approach makes sense.

If the domain model is treated as the core of the application, leaving the db to be just a form of persistent storage, than a code first approach is practical.

as a side note: this concept is usually referred to as model first (the domain/code) and db first (the db schema). with EF this is somewhat confusing as model refers to the db schema, not the domain model and code refers to the code.

Jason Meckley
  • 7,589
  • 1
  • 24
  • 45
  • 1
    No, Model first and Code-first are not the same thing. Both Model First and Database first use an .edmx file, while code-first does not. – Erik Funkenbusch Jan 12 '12 at 18:08
  • looks like the difference is the concept vs. the implementation. with EF they refer to the domain as code and the model as the db. conceptually the model is the code and the db is the db. I'll update my answer in terms of EF definitions. – Jason Meckley Jan 12 '12 at 18:13
  • 2
    No, that's incorrect. In code-first, the model is defined via fluent code mapping. In Model-first, the model is defined via XML mapping (as it is in database first). The only difference between database first and model first is where you start. In database first, you define your data model in the database, then reverse engineer it to xml (.edmx file). In Model first, you define your data model in the designer (or hand coded xml if you're hard core) and then generate the database from the xml. In both cases, Entity classes are generated from XML. Code First has entity classes created first. – Erik Funkenbusch Jan 12 '12 at 18:20
  • @MystereMan I think you are referring specifically to EF where I am talking about ORM conceptually, not a specific implementation or framework. – Jason Meckley Jan 12 '12 at 18:41
  • Code-first is a specific way to develop a database model in Entity Framework, so yes. That's what I and the question asker are talking about. General concept answers do not answer the question here. – Erik Funkenbusch Jan 12 '12 at 18:48
0

DB first is not outdated at all. In fact, for many corporate projects that's the way to go.

If you are building something for yourself from scratch, code first will probably be a better approach.

AD.Net
  • 13,352
  • 2
  • 28
  • 47
0

Entity Framework provides: 1)Database first, 2)Model first and 3) Code first. 1 & 2 Creates the edmx file Database first: Entity Data Model(edmx:StorageModels) is created from an existing database. Model first: Conceptual Data Model(edmx:ConceptualModels) is created with designer and mappings specified. Database will be generated from this. Code first: Create your .NET classes(no .edmx file). Database will be generated from this.

'Old school' would be using ADO.NET DataSet/DataTable.

Fastest data access is using DataReader and writing your own data access. No framework will be faster than using a DataReader to populate your own POCOs.

Steven Licht
  • 760
  • 4
  • 5