3

I have just watched the MSDN video about the new 'Code First to Existing Database' functionality in EF6.1

http://channel9.msdn.com/Blogs/EF/Code-First-to-Existing-Database-EF6-1-Onwards-

However, being new to EF, this appears to be generating POCO Model classes from a DB, which is exactly what I thought 'Database First' does (and I understood 'DB First' to be the opposite of 'Code First')

What's the difference? They are both 'database first'!

7
  • There is an excellent explanation already, no need to duplicate the answers here. Code-first vs Model/Database-first
    – mason
    Commented Mar 27, 2014 at 17:41
  • No - this is a different question. 'Code first to existing database' is new functionality in EF 6.1
    – Anthony
    Commented Mar 27, 2014 at 17:42
  • Code first with existing database isn't new. see this blog from Scott Guthrie
    – Habib
    Commented Mar 27, 2014 at 17:43
  • 1
    All that's new in EF 6.1 is new tooling for reverse engineering entity classes from a database. The capability was there before. There's just a point and click way to do it now.
    – JC Ford
    Commented Mar 27, 2014 at 17:46
  • 1
    @Anthony - The functionality has existed for a long time in the Entity Framework Power Tools, but has in 6.1 been integrated into the EF tooling itself. Commented Mar 27, 2014 at 17:46

1 Answer 1

10

Code First is sort of a misnomer... What it should really be called is "Code Based Model" vs "XML Based Model".

Code first creates an in-memory model based on attributes on classes and/or fluent mappings in code.

Database and Model first create an in-memory model based on a .EDMX file, which is then used to generate classes.

ie. Code first uses the code as its model. Database and Model first use the EDMX file as it's model. Code First to existing database just generates code first classes (attributes and/or fluent mapping), while database first generates an EDMX file which then generates classes via T4 templates.

4
  • Code First is only a misnomer when you're starting from an existing database. Starting a new project, creating entity classes and letting EF generate the database for you is what is meant by "code first" and it's not a misnomer.
    – JC Ford
    Commented Mar 27, 2014 at 17:47
  • @JC. - You've always been able to start with the database. In fact, I've never used the database generation part of code first, yet code first is all I use. Just because you can start with code first doesn't mean that it accurately describes what it is. Commented Mar 27, 2014 at 17:49
  • Visual Studio lacked built-in tooling to create "code-first" classes from a database until now, but that's neither here nor there. Code-First was so named for the process of writing plain classes and having a database generated from them.
    – JC Ford
    Commented Mar 27, 2014 at 17:53
  • @JC - It was named code first because there already existed "database first" and "model first" names, and it was chosen to fit in with that approach. EF Power Tools have existed for years, maintained by the EF team that did this. So saying the tools didn't exist isn't true. Commented Mar 27, 2014 at 18:13

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.