Basic ASP.NET application using Entity Framework

by Jagadish Pulakhandam on 4/23/2012 11:54:38 AM
Rated 0 from 0 votes
Brief: Demonstrates on connecting/fetching SQL Server data using Entity Framework and ASP.NET
Posted to: Programming Entity Framework (Basics) - Examples and Videos
Add to DiggAdd to del.icio.usAdd to FURLAdd to RedditAdd to YahooAdd to BlinklistAdd to GoogleAdd to ma.gnoliaAdd to ShadowsAdd to Technorati

Attached Sample/Video demonstrates the following:
  • How to connect to SQL Server using Entity Framework
  • How to create (basic) Entity Data Model (entities) using Entity Framework Designer (and wizard)
  • How to configure/use EntityDataSource to work with Entity Data Model
  • How to bind GridView to EntityDataSource

NOTE: uses "Northwind" database (you have to modify connection string or connection parameters according to your environment).

Source Code:

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="WebForm1.aspx.cs" Inherits="Sample01.WebForm1" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "">
<head runat="server">
    <form id="form1" runat="server">
        <asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False"
                <asp:BoundField DataField="OrderID" HeaderText="OrderID" ReadOnly="True"
                    SortExpression="OrderID" />
                <asp:BoundField DataField="CustomerID" HeaderText="CustomerID" ReadOnly="True"
                    SortExpression="CustomerID" />
                <asp:BoundField DataField="EmployeeID" HeaderText="EmployeeID" ReadOnly="True"
                    SortExpression="EmployeeID" />
                <asp:BoundField DataField="OrderDate" HeaderText="OrderDate" ReadOnly="True"
                    SortExpression="OrderDate" />
                <asp:BoundField DataField="Freight" HeaderText="Freight" ReadOnly="True"
                    SortExpression="Freight" />
                <asp:BoundField DataField="ShipCity" HeaderText="ShipCity" ReadOnly="True"
                    SortExpression="ShipCity" />
        <asp:EntityDataSource ID="EntityDataSource1" runat="server"
            DefaultContainerName="NorthwindEntities" EnableFlattening="False"
            Select="it.[OrderID], it.[CustomerID], it.[EmployeeID], it.[OrderDate], it.[Freight], it.[ShipCity]">


<?xml version="1.0" encoding="utf-8"?>
  For more information on how to configure your ASP.NET application, please visit
    <compilation debug="true" targetFramework="4.0">
        <add assembly="System.Data.Entity, Version=, Culture=neutral, PublicKeyToken=b77a5c561934e089" />
    <add name="NorthwindEntities" connectionString="metadata=res://*/NorthwindModel.csdl|res://*/NorthwindModel.ssdl|res://*/NorthwindModel.msl;provider=System.Data.SqlClient;provider connection string="Data Source=.\sql2k8;Initial Catalog=Northwind;User ID=sa;Password=sql2008;MultipleActiveResultSets=True"" providerName="System.Data.EntityClient" />

Join the .NET Code Central Community and join the discussion!
Signing-up is FREE and quick. Do it now, we want to hear your opinion

Rated 0 from 0 votes ( login  to rate)
DotnetKicks DotnetKicksDe DotNetShoutout

Attachments / Source Code
You need to Login or Join for FREE to download the following

Video/Screen Recording (may not have audio narration/annotations)
You need to Login or Join for FREE to download the following