TechBubbles Microsoft Technology BLOG

ASP.NET 3.5 Entity Framework

Introduction

This post explains how to create a Model from the database using ASP.NET Entity Framework. Using Entity Framework you can define the flexible mapping to existing relational schema.

Here I have created a new console application to explain the ASP.NET Entity Framework. You need to install the VS 2008 SP1 to work with the ASP.NET Entity Framework.

 

1. Right click the Project and Create a Data Model for database by selecting

   Add  New item option. It looks like the following screenshot.

EntityFramework

 

2.  It prompts you to select the option for Model from dialogue box

Entity23

 

3. Specify the Database Connection and it generates the Entity Framework 

    connection string which will save in the web.config file.

EntityConnection

 

The metadata section in the connection string specifies how to interact the objects with the database. csdl describes the model. ssdl describes the database model and msl describes the mapping between model and database model. Next part in the connection string is database provider here we are using SQL provider and last part is connection string for the provider.

 

4. Choose the database objects to build the model.

DBModel 

 

From the above dialogue box we can choose desired tables, views and stored procedures.

 

5. Now Entity Frame work generates the default model and entities in the    

    Project.

model 

Navigation properties in the above model describes mapping between the models.

 

6. Establish the object context to interact with entities.

codesnippet

 

7. We can see the results by executing the project

Console

 

Conclusion

What we have done is we have taken a existing database to generate the Entity Framework model then we used object context to show the data from the database.

About the author

Kalyan Bandarupalli

My name is kalyan, I am a software architect and builds the applications using Microsoft .NET technologies. Here I am trying to share what I feel and what I think with whoever comes along wandering to Internet home of mine.I hope that this page and its contents will speak for me and that is the reason I am not going to say anything specially about my self here.

3 Comments

TechBubbles Microsoft Technology BLOG

Follow me

Archives

Tag Cloud