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.

Step 3. Add “Ado.NET entity data model” inside the project. 
Select “EF Designer from the database”.

Set the connection string.



Select the database objects from the wizard.

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

Step 4. StudentModel.edmx contains two .tt extension files, namely:
” StudentModel.Context.tt” and “StudentModel.tt”
” StudentModel.Context.tt” : It contains dbContext.
“StudentModel.tt”: 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.

Step 7. On Add button, click insert record into Student table of DB by using DbContext.
Join the conversation! Your thoughts help the community grow.
Sign in to leave a comment
It is the same account you read, post and publish with — and you will come straight back to this page.

kalu singh raoPosted Jul 21, 2016, 2:01 AM
Useful for mvc with EF developers
Vignesh ManiPosted Jul 20, 2016, 11:13 AM
Good one