Entity Framework Core (EF Core) is a modern Object-Relational Mapper (ORM) that enables .NET developers to work with databases using C# objects instead of writing raw SQL for every operation. One of the widely used workflows in EF Core—especially in enterprise and legacy systems—is the Database First approach.
In the Database First approach, the database already exists, and EF Core generates C# entity classes and DbContext directly from that database. This approach is ideal when working with existing databases, legacy systems, or database-driven environments where the schema is managed by DBAs.
This article explains the Database First approach in EF Core in a fully descriptive manner, covering concepts, workflow, tools, generated code, advantages, limitations, and best practices.

What Is the Database First Approach?
The Database First approach means:
The database is created first
Tables, columns, keys, and relationships already exist
EF Core generates entity classes and DbContext from the database
The database remains the primary source of truth
In this approach, code adapts to the database, not the other way around.
When and Why Database First Is Used
The Database First approach is commonly used in the following situations:
Existing or Legacy Databases: Many organizations already have large databases that cannot be redesigned.
Database Managed by DBAs: Schema changes are controlled centrally, not by application developers.
Large Enterprise Systems: Multiple applications may depend on the same database.
Stored Procedures and Views: Database First works well when business logic exists inside the database.
Reporting and Analytics Systems: Where database structure is complex and optimized for querying.
How the Database First Workflow Works
The Database First workflow follows these steps:
Create or identify an existing database
Install EF Core database provider and tools
Generate models and DbContext from the database (scaffolding)
Use generated entities in the application
Re-scaffold when database schema changes
EF Core automatically maps database objects to C# code.
Step 1: Existing Database Structure
In Database First, the database already contains:
Tables
Columns
Primary keys
Foreign keys
Indexes
Constraints
Views (optional)
Example database objects:
StudentstableCoursestableEnrollmentstable
EF Core reads this schema to generate code.
Step 2: Installing Required EF Core Packages
To work with Database First, the following packages are typically required:
Microsoft.EntityFrameworkCoreMicrosoft.EntityFrameworkCore.SqlServerMicrosoft.EntityFrameworkCore.Tools
These packages enable:
Database connection
Reverse engineering (scaffolding)
Model generation
DbContext creation
Step 3: Scaffolding the Database
Scaffolding is the process of generating C# classes from an existing database.
A single command reads:
Table definitions
Column data types
Relationships
Constraints
And produces:
Entity classes
DbContext class
This process is automatic and saves a significant amount of development time.
What EF Core Generates in Database First
After scaffolding, EF Core creates two main components:
1. Entity Classes
Each database table becomes a C# class.
Example (Generated Entity):
public partial class Student
{
public int StudentId { get; set; }
public string FullName { get; set; }
public int? Age { get; set; }
public virtual ICollection<Enrollment> Enrollments { get; set; }
}Key characteristics:
Property names map to column names
Nullable columns become nullable properties
Navigation properties represent relationships
Classes are marked as
partialfor extensibility
2. DbContext Class
The DbContext represents the database session.
Example:
public partial class SchoolDbContext : DbContext
{
public virtual DbSet<Student> Students { get; set; }
public virtual DbSet<Course> Courses { get; set; }
}Responsibilities of DbContext:
Database connection management
Entity tracking
Query execution
Relationship handling
Transaction management
Handling Relationships in Database First
EF Core automatically detects relationships using:

Join the conversation! Your thoughts help the community grow.