Creating Entity Data Model using Wizard

Updated on 08 Apr 2011,
Published on 24 Mar 2011

The ADO.Net Entity Data Model provides the functionality to add or remove the tables or views onto the data model surface that generates classes mapped to the database objects. These classes are called entity classes. The entity class object maps to a record, whereas the properties of an entity class map to the individual columns in a record. The entity classes represents 1:1 mapping of database objects because entity data model supports only 1:1 mapping relationships. You can map an entity class to an individual table or view for adding 1:1 mapping between the objects. You cannot map single entity class to multiple tables instead you can map an entity class to a single view that joins multiple tables. In addition to entity classes, it also generates Data ObjectContext for performing database updates.

Steps to Create Entity Data Model Classes

First of all you must know how to add an Entity Data Model in a web application.

1. Right click on App_Code folder and then select new item from Add menu. It will open Add New Item dialog box.

2. Select Data tab from under the Visual C# or Visual Basics tabs in left side of dialog box. Then select ADO.Net Entity Data Model from the right side and type a suitable name for the file e.g. Northwind. It will create a file with .edmx extension.

The above steps will create an Entity data model .edmx file in the web application that will enable you to design the data model using specific wizard. When you will choose the ADO.Net template, it will navigate to next step of wizard asking to choose the model contents such as Generate from Database.

Note: In this tutorial we have used the Northwind SQL database to generate the entity data model.

3. Select the "Generate from Database" option and click Next. It will prompt to specify the data connections. You can select any predefined connection string name from the drop down list or otherwise add a new connection by clicking the "New connection" button. When you will specify the data connection it will automatically generate an Entity connection string for the Data Model. You can specify the Entity Connection name at the bottom of wizard dialog box.

4. After completing the step 3, click next. It will fetch and display the data objects of the connected database. You can select the data objects that you want to include into your Entity Data Model in this step. To understand the functionality we have selected the Category and Products table of the underlying Northwind database. After selecting the table objects click on finish to generate the Entity Data Model file and its associated code for entity classes.

Continue to next tutorial: Connect and Select Data using C# LINQ to Entities Data Model to learn how to communicate with database.

1 Responses to "Creating Entity Data Model using Wizard"
Nice, if it works ... e.g. http://social.msdn.microsoft.com/Forums/hu-HU/adodotnetentityframework/thread/994a2190-6f22-4a37-a638-11e947b1ed79 Sometimes I get the wizard working but oft the Wizard just freezes (1% CPU usage only ...) --hfrmobile
Leave a Comment
* required
* required
* will not be published
* optional
* hint: http://www.example.com
  • Subscribe via Email
  • HIRE EzineASP.Net Developers