Code First versus Database First?

10

I'm used to creating projects in ASP.NET MVC with Entity Framework Database First. From a modeling, the database and the system are created.

However, I see a lot of programmers prefer Code First, where the database depends on the system.

What are the differences between the two?
I say in a practical sense, what are the pros and cons of each approach?
What changes in a project's architecture and how to develop the system?

    
asked by anonymous 10.11.2014 / 21:51

1 answer

12

Differences

  • Code First: The code is written first. The database is generated from the code;
  • Database First: The database is written first. The application code is generated from the database.

Pros and Cons

Code First

Pros

  • Can work independently of database technology;
  • Data validations are not strict to a technology;
  • Can build and destroy databases generated in moments, through Migrations;
  • Ideal for new applications;

Cons

  • Does not mesh well with an existing database;
  • Depends on a good ORM, such as the Entity Framework and NHibernate, for example;
  • Requires constant optimization because data abstraction for some banks does not always perform well;
  • Validation in database is limited. Database generation by application is never 100%;
  • Poor database security.

Database First

Pros

  • Ideal for performance and existing schemas;
  • Application can be made on top of a database that already exists;
  • Better-adjusted bank security;

Cons

  • Generation of environments is limited; Complex to determine incremental changes of both the database and the application;
  • Fully dependent on bank technology;
  • Limitation of bank providers that can generate the application (ODBC helps, but does not completely solve the problem);
  • Data validation generated for the limited application;

What changes in the architecture of a project and in the way the system is developed?

I think the previous items answer this question well. It all depends on the reality in which the new system is built, with a few additions.

In Code First , the database tracks the growth of the system. In Database First, the entire system must be generated at one time, and every incremental implementation must be manual.

In contrast, a Code First system is green for database security and performance. Most problems are solved by good practices, but there's always something to be desired, such as a huge or quirky table that requires extra optimization.

    
10.11.2014 / 22:10