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 from database technology;
- Data validations are not strict to a technology;
- Can build and destroy databases generated in instants, through Migrations;
- Ideal for new applications;
Cons
- Not well connected to an existing database;
- It depends on a good ORM, like the Entity Framework and Nhibernate, for example;
- Requires constant optimization, because the abstraction of data for some databases does not always have a good performance;
- Database validation is limited. Database generation by the application is never 100%;
- Poor database security.
Database First
Pros
- Ideal for existing performance and schematics;
- Application can be made on top of a database that already exists;
- Better adjusted seat level security;
Cons
- Environment generation is limited; Complex to determine incremental changes of both database and application;
- Totally dependent on bank technology;
- Limiting database providers that can generate the application (ODBC helps, but does not completely solve the problem);
- Data validation generated for limited application;
What changes in the architecture of a project and the way to develop the system?
I believe that the previous items answer this question well. It all depends on the reality in which the new system is built, with a few more addenda.
In the Code First, the database tracks the system’s growth. In the Database First, the whole system needs to be generated at once, and every incremental implementation needs to be manual.
On the other hand, a system Code First is green as to the security and performance of the database. Most problems are solved by good practice, but still something leaves something to be desired, like a huge or peculiar table that requires extra optimization.
What is missing in the answer provided?
– Leonel Sanches da Silva
The answer is great, but it’s not yet clear to me how it affects the development of the system in a team.. What about the application of system modeling and dbas? and maintenance afterwards?
– Andre Figueiredo
In the Code First modeling begins in Models, the bank is generated from the system, and the DBA has only paper afterward that the system code has already been written. The idea of the Code First is one day to be able to dispense with the role of DBA, since having a system implemented using best practices results in an already optimized database.
– Leonel Sanches da Silva
Got it. But doesn’t that tend to make the database too application-dependent? If another application appears that uses the same bank, it is possible to have both with Code First without there being a risk of a change in the Model from one affecting the other through the bank?
– Andre Figueiredo
There are no "two applications Code First with the same bank". As I told you, if the bank already exists, the second application is necessarily Database First.
– Leonel Sanches da Silva