Entity Framework
The Microsoft ADO.NET Entity Framework is an Object/Relational Mapping (ORM) framework that enables developers to work with relational data as domain-specific objects, eliminating the need for most of the data access plumbing code that developers usually need to write.
The following Image will explain Entity Framework architecture.
Image 1.
O/RM
ORM is a tool for storing data from domain objects to relational database like Microsoft SQL Server, in an automated way, without much programming. O/RM includes three main parts: Domain class objects, Relational database objects and Mapping information on how domain objects map to relational database objects (tables, views and Stored Procedures). ORM allows us to keep our database design separate from our domain class design.
Model First Approach step-by-step
Model first is the domain modelling approach in Entity Framework. It enables you to create a model's Entities, relationships and inheritance hierarchies on the design surface of an empty model (.edmx file) by using entity designer and then create the database from it.
Now open Visual Studio then select "File" -> "New" -> "Project...".
Image 2.
Image 3.
Now right-click on the Model Folder then select "Add" -> "ADO.NET Entity Data Model".
Image 4.
Image 5.
Select Empty model.
Image 6.
Now right-click then select "Add New" -> "Entity...".
Image 7.
Provide a name then select a Data Type and Set Key.
Image 8.
Click OK.
Image 9.
Now add more columns to your Entity.
Image 10.
It will add a new property or column to your entity. Now you can set the data type and other properties of this newly added column as in the following.
Image 11.
Now add all the columns (properties) that you want. After this our ADO.NET Entity Data Model Will look as in the following.
Image 12.
Now to generate the database from this model. So right-click in your edmx as in the following.
Image 13.
Image 14.
This will give the following Message then click Yes.
Image 15.
This will show the connection string in the next step as in the following.
Image 16.
Click Next. That will generate a DB Script.
Image 17.
Image 18.
Image 19.
After the command is executed successfully check your database.
Image 20.
Now generate a class. So click on Models then select School.edmx then right-click on School.tt then select Run Custom Tool.
Image 21.
Image 22.
Now to create CRUD operations. So right-click on Controller then select Add -> Controller.
Image 23.
It will CRUD Views also as in the following.
Image 24.
Now run your application.
Add New Student.
Image 25.
Showing All Students Records.
Image 26.
Edit any Student record.
Image 27.
Showing details of Student.
Image 28.
Delete any Student record.
Image 29.
Now see your database.
Image 30.
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.

Surya KantPosted Oct 31, 2015, 10:05 PM
good one brother...
Rahul Kumar SaxenaPosted Oct 18, 2015, 12:08 PM
Welcome Shridhar Sharma
Rahul Kumar SaxenaPosted Oct 7, 2015, 2:03 PM
Thank u Shridhar Sharma
Shridhar SharmaPosted Oct 7, 2015, 10:53 AM
nice share sir..congrats for Article of The Day :)
Rahul Kumar SaxenaPosted Aug 18, 2015, 1:16 AM
Thank u sreenivasa k
sreenivasa kPosted Aug 17, 2015, 6:35 PM
good
Rahul Kumar SaxenaPosted Apr 23, 2015, 2:13 PM
Thanks Karthik Muthu Karuppan
Karthik Muthu KaruppanPosted Apr 23, 2015, 11:25 AM
good
Rahul Kumar SaxenaPosted Apr 21, 2015, 6:08 AM
Thanks Jitendra Kumar...
Jitendra KumarPosted Apr 21, 2015, 5:40 AM
Nice Article.
Rahul Kumar SaxenaPosted Apr 20, 2015, 10:04 PM
Thanks Abhishek Jaiswal...
Abhishek JaiswalPosted Apr 20, 2015, 3:44 PM
Very well explained and informative. :)
Rahul Kumar SaxenaPosted Apr 20, 2015, 12:51 PM
Thanks Manoj Kulkarni...
Rahul Kumar SaxenaPosted Apr 20, 2015, 12:50 PM
Thanks Sibeesh Venu...
Manoj KulkarniPosted Apr 20, 2015, 11:13 AM
Nice article. Thank you for sharing the information
Sibeesh VenuPosted Apr 20, 2015, 6:39 AM
good one.
Rahul Kumar SaxenaPosted Apr 20, 2015, 2:58 AM
Thanks Anil Kumar...
Anil KumarPosted Apr 20, 2015, 1:54 AM
Rahul Saxena Like the edmx picture :) Nice explaination!
Rahul Kumar SaxenaPosted Apr 19, 2015, 10:08 PM
Thanks Santhakumar Munuswamy
Santhakumar MunuswamyPosted Apr 19, 2015, 3:57 PM
Thanks for nice article
Santhakumar MunuswamyPosted Apr 19, 2015, 3:57 PM
Great work.