DEV Community

Lincoln Tran
Lincoln Tran

Posted on

3

Asp.Net : Code first or Database first ?

In database related programming, we can hear about 2 key words "code first - database first" when we start to design backend architecture. So, what is code/database first? Is it important in coding ?

The answer is yes, it helps you easily control model database and manages owner resource better.

Code-first

We will not create the tables under the database first, but rely on the classes/models on C# to create the database. Net supports Entity Framework Core - is an Object/Relational Mapping (O/RM) framework. It is an enhancement to ADO.NET that gives developers an automated mechanism for accessing & storing the data in the database.
The neweset EF core version is 7.0. Find out more in: https://learn.microsoft.com/en-us/ef/core/what-is-new/

In the code-first approach, EF Core API creates the database and tables using migration based on the conventions and configuration provided in your domain classes. It creates the database based on the parameter passed in the base constructor of your context class- using DB context.

Database-first

Otherwise, we already have tables under the database and we just need to create C# classes to map those tables. We also use EF build a data object model and the complete application for you with very little code.

Example:

Image description

In short, the code-database first technique in backend system design is extremely necessary for users. You will understand what system architecture you need and what is important in backend design.

Heroku

Simplify your DevOps and maximize your time.

Since 2007, Heroku has been the go-to platform for developers as it monitors uptime, performance, and infrastructure concerns, allowing you to focus on writing code.

Learn More

Top comments (2)

Collapse
 
lincoln profile image
Lincoln Tran

This is my first blog, if there are any mistakes please comment, I will improve it better.

Collapse
 
ryan3691211 profile image
ryan3691211

Wow! it great.

Billboard image

The Next Generation Developer Platform

Coherence is the first Platform-as-a-Service you can control. Unlike "black-box" platforms that are opinionated about the infra you can deploy, Coherence is powered by CNC, the open-source IaC framework, which offers limitless customization.

Learn more

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay