Database First Approach In Entity Framework

Database first approach applies, when we create a database first or if we have an existing database.


Steps of using database first approach in Entity framework

Step 1. Create a database or use an existing database in the DB first approach:


We have “SchoolDB”, which contains one table Student.

Step 2. Create Window Form Project.

Window Form Project

Step 3. Add “Ado.NET entity data model” inside the project. entity data model

Select “EF Designer from the database”.

EF Designer from database

Set the connection string.




Select the database objects from the wizard.

Database objects

After finishing this wizard, we will get .edmx (StudentModel.edmx) file inside our project.


Step 4. StudentModel.edmx contains two .tt extension files, namely:
”” and “”
”” : It contains dbContext.
“”: It contains models or entity class.

Step 5. Now, if we expand the StudentModel.edmx, we get following:


SchoolDBEntity1 is the DbContext exists inside StudentModel.context.cs.

Step 6. Create UI for inserting the data into Student table by using DbContext.

Create UI

Step 7. On Add button, click insert record into Student table of DB by using DbContext.