Sunday, 27 January 2013

Adding ADO.NET Entity Framework 5 support in asp.net



Adding ADO.NET Entity Framework 5 support in asp.net

Step 1) Click Add new item-> Select ADO.NET Entity Data Model

Adding ADO.NET Entity Framework 5 support in asp.net C#-VB.NET-WPF
Select ADO.NET Entity Framework Data Model Template
                                         

Step 2)  Select "Generate From Database" (Because Model is from Existing Database).

Adding ADO.NET Entity Framework 5 support in asp.net C#-VB.NET-WPF
Select Generate From Database



Step 3)  Choose SQL Server Data Provider


Adding ADO.NET Entity Framework 5 support in asp.net C#-VB.NET-WPF


Select SQL Server DataSource

Step 4) Provide SQL Server Instance and Database Name and Connection Information

Adding ADO.NET Entity Framework 5 support in asp.net C#-VB.NET-WPF
Provide SQL Server Instance and Database


Step 5) ADO.NET Entity Framework Connection String is  Stored in the App.config/Web.config

Adding ADO.NET Entity Framework 5 support in asp.net C#-VB.NET-WPF
Entity Framework Connection String stored in app/web.config

Step 6) Select Tables you want

Adding ADO.NET Entity Framework 5 support in asp.net C#-VB.NET-WPF
Select Tables from AdventureWorks 

Step 7) Generates Model1.edmx file as shown below.

Adding ADO.NET Entity Framework 5 support in asp.net  edmx file

 

 Step 8) Model1.edmx

                  It has 4 files  

  •    Model1.Context.tt
    Model1.Designer.cs
    Model1.edmx.diagram
    Model1.tt 

    Model1.Context.tt  has  has DBContext Derived Class AdventureWorks2012Entities Specified in Step 5
    Model1.tt has Entities Related to Selected Tables.


    DBContext and Table Related Entities by default added  to Same namespace.




    Note: How to Access/Consume Entity Framework in C#,ASP.NET,Silverlight,WPF,Windows Form, Pls see other articles in this Website.