A Simple Step to Entity Framework Database First Approach

Introduction

 
In the previous article, we learned about the code-first approach of the Entity Framework. A Simple Step to Entity Framework: Code First Approach.
 
Now we are discussing the database first approach.
 
This approach uses the development scenario of our database is already developed and we have an existing database and we need to go directly to the coding part. So we can directly create the EDMX for the existing database and we have the option to update the data model when the database schema is changed.
 
A quick start
 
Create an application.
 
asp web form
 
Add a new item to the project.
 
add new item
 
Add an ADO.NET Entity Data Model.
 
ado dot net
 
Select the option Generate from Database and click on the Next button.
 
generate form database
 
Click on the New Connection button.
 
new connection
 
Enter the credentials of the database server and select the database name in this wizard.
 
select database
 
Our connection details will show in the next wizard. Click on the Next button.
 
connection string
 
In this wizard, we have the option to select the tables, views, Stored Procedures, and functions. Click on the Finish button.
 
select table
 
Now our EDMX s created.
 
model
 
Right-click on the diagram; we can see many options for managing the EDMX.
 
nevigation properties
 
Here one of the options is Update Model from Database, it is for updating the model when we have changed in the database schema.
 
update model
 

Conclusion

 
In this article, we learned the basic details of the Database First Approach of the Entity Framework.


Similar Articles