Introduction to the ADO.NET Entity Framework using ASP.NET
(Page 1 of 5 )
This is an introductory article focusing on developing ASP.NET applications using the ADO.NET Entity Framework. In this article, we will make a detailed step-by-step examination of how to develop applications using the ADO.NET Entity Framework together with ASP.NET.
This article is based on the following configuration:
To make this article simple, I created a table structure which you can examine by clicking on the link.
The entire source code for this article is available in the form of two free downloadable zip files, which you can download here and here. The solution was developed using Microsoft Visual Studio 2008 Team Edition (with SP1), with Microsoft SQL Server 2008 Developer Edition on Microsoft Windows Server 2003 Standard Edition (with SP2). I didn't really test it in any other environment. I request that you post in the discussion area if you have any problems in execution.
Creating a simple application with ADO.NET Entity Framework
Let us start with a new solution:
Open Start || Programs || Microsoft Visual Studio 2008
Go to File || New Project
In the "New Project" dialog, select "Web" in "Project Types" and select "ASP.NET Web Application" in templates.
Provide "Sample01" as the name and press "OK."
Right click on project and click on Add || New Item
In the "Add New Item" dialog, select "ADO.NET Entity Data Model" as the template, provide "NWModel.edmx" as the name, and finally click on "OK."

Immediately, you will be provided with the "Entity Data Model Wizard." Select "Generate from database" to create a model and click "Next."
Provide database connectivity information and hit "Next."
Select "Emp," "Dept" in the list of tables, provide "NorthwindModel" as the namespace, hit "Finish."

Once the wizard completes, the Entity Designer looks like the following:

To make all the three entity mapping files (.csdl, .msl, .ssdl) copied to "bin" folder, configure as shown below:

Drag a button (btnEmpList) and GridView on to "Default.aspx"
Modify the code behind so that it looks like the following:
Partial Public Class _Default
Inherits System.Web.UI.Page
Protected Sub btnEmpList_Click(ByVal sender As Object, ByVal e As EventArgs) Handles btnEmpList.Click
Dim ctxt As New NorthwindEntities
Me.GridView1.DataSource = From oEmp In ctxt.Emp _
Select New With {.ID = oEmp.Empno, .Name = oEmp.Ename, .Salary = oEmp.Sal, .Dept = oEmp.Dept.Dname}
Me.GridView1.DataBind()
End Sub
End Class
Next: CRUD operations using ADO.NET Entity Framework: Screen Design >>
More ASP.NET Articles
More By Jagadish Chaterjee