In this article, you will learn how to Fetch, Insert, Update, and Delete Data using the "Database First Model Approach" and the ADO.NET Entity Framework 3.5 and Visual Studio 2008.
What is Entity Framework?
- Entity Framework is an Object/Relational Mapping (O/RM) framework.
- It is an enhancement to ADO.NET that gives developers an automated mechanism for accessing & storing the data in a database and working with the results in addition to Data Reader and DataSet.
- An Entity Framework Model (ERM) defines a schema of entities and their relationships with one another.
- Entities are not the same as objects.
- Entities define the schema of an object, but not its behavior.
- So, an entity is something like the schema of a table in your database, except that it describes the schema of your business objects.
- Entity Framework 3.5 supports the Database First model.
DATABASE FIRST MODEL
- You need to create a table for implementing the Database First model.
- I have used the employee table for this tutorial.
- You can use the following employee table script to create a table.
- USE[Test]
- GO
- SET ANSI_NULLS ON
- GO
- SET QUOTED_IDENTIFIER ON
- GO
- SET ANSI_PADDING ON
- GO
- CREATE TABLE[dbo]. [Employee](
- [id][int] IDENTITY(1, 1) NOT NULL,
- [name][varchar](50) NULL,
- [address][varchar](50) NULL,
- CONSTRAINT[PK_Employee] PRIMARY KEY CLUSTERED(
- [id] ASC
- ) WITH(PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON[PRIMARY]
- ) ON[PRIMARY]
- GO
- SET ANSI_PADDING OFF
- GO
- SET IDENTITY_INSERT[dbo]. [Employee] ON
- INSERT[dbo]. [Employee]([id], [name], [address]) VALUES(1, N 'Employee One', N 'Address One')
- INSERT[dbo]. [Employee]([id], [name], [address]) VALUES(2, N 'Employee Tow', N 'Address Two')
- INSERT[dbo]. [Employee]([id], [name], [address]) VALUES(3, N 'Employee Three', N 'Address Three')
- SET IDENTITY_INSERT[dbo]. [Employee] OFF
GENERATING MODEL FROM DATABASE
-
Create a new "Employee" Web site in Visual Studio 2008.
-
In the Solution Explorer, right-click on the project and choose "Add New Item".

-
It will open an "Add New Item" dialog box. Choose the "ADO.NET Entity Data Model" and change the default name from "Model.edmx" to "Employee.edmx". Then click on the "Add" button.

-
After clicking on the Add button, this will open the "Entity Data Model Wizard".

-
In the wizard choose "Generate from database" and click on the "Next" button.
-
Here you have two options. One is you can choose the existing SQL connection and another option is you can create your own SQL connection.

-
For a new connection, click on the "New Connection" button. It will open the "Connection properties" window. Fill in all the details and click on the "OK" button. The new connection will be shown in the Entity Data Model Wizard.

-
Click on "Yes, include the sensitive data in the connection string." and click on the "Next" button.

-
Choose the required tables and name the Model Namespace as "EmployeeModel".
-
Click on the "Finish" button. The model will be generated and opened in the EDM Designer.






Kalyani BharadPosted Dec 13, 2014, 5:54 AM
hello i m using web api ,entity framework 6 with asp.net web forms so can u give me any source code or any useful link which help me to perform CRUD operation using this..
Shivom BhattPosted Dec 12, 2014, 7:32 AM
Its really great and helpful! thanks alot
karthi keyanPosted Nov 19, 2014, 12:19 AM
does not work
Shrish ShrivastavaPosted Apr 24, 2013, 1:07 AM
its great !
Anil KumarPosted Jan 24, 2013, 4:00 AM
nice explaination