Entity Data Model

The Entity Data Model or EDM is a graphical tools used to build entity framework based applications. This is none of the best features of entity framework. This article describes how to create .edmx file? Summary of the article:

  • What is Entity Data Model (EDM)?
  • What is .edmx File?
  • Configuration/Creation of Entity Data Model (EDM)

What is Entity Data Model (EDM)?
Entity Data Model or EDM refers to a set of concepts that describe data structure, regardless of its stored form. It is a bridge between application and data storage and helps us to work at a conceptual level rather than the actual schema. It uses three key concepts to describe data structure (entity type, association type and property).

By using Entity Data Model we can create a conceptual model from an existing database and then graphically visualize and edit our conceptual model. Or, at first we can graphically create a conceptual model, and then generate the database that supports the model. In either case, we can automatically update your model when the underlying database changes and automatically generate object-layer code for our application. We can customize database generation and object-layer code generation.

What is .edmx File?
ADO.NET Entity Data Model is integrated with Visual Studio. EDM works with an .edmx file. Its full meaning is Entity Data Model XML. It is an XML file. It defines a conceptual model, a storage model, and the mapping among these models. It contains all the mapping details of how objects map with SQL tables
From the visual studio when we run the Entity Data Model Wizard, an .edmx file is created and added to our solution. After finishing the task of wizard, this file is automatically opened in the Entity Designer. We can also open it in the Entity Designer by double-clicking it in Solution Explorer. This .emdx file is the combination of three metadata file:

  • CSDL (Conceptual Schema Definition Language) -is the conceptual abstraction which is exposed to the application.
  • SSDL (Storage Schema Definition Language) -defines the mapping with our RDBMS data structure.
  • MSL (Mapping Schema Language) -connects the CSDL and SSDL.

Configuration/Creation of Entity Data Model (EMD)
The steps to create ADO.NET Entity Data Model are given bellow:

Step-1:  Create a new project using Visual Studio.

Step-2:  Write click on your project and click add new item.

Step-3:  Select ADO.NET Entity Data Model and click Add. You can rename it according to your choice.

Entity Data Model Wizard

Step-4:  Entity Data Model Wizard will be open. Select Generate form database and click next.

Entity Data Model Wizard

Step-5:  Click on New Connection. Connection properties window will be open.

Entity Data Model

Step-6:  Select Microsoft SQL Server (SqlClient) as Data source. Provide your server name, user name, and password. Select your database name and click ok.

Entity Data Model

Step-7:  Entity Data Model Wizard will be like that.

Entity Data Model

Step-8:  Select Yes or No to include or exclude sensitive data in your connection string. Click next.

Step-9:  Choose your database objects.  You can change your Model Namespace or you may remain it as it is. Click finish.

Entity Data Model

Step-10: Entity Data Model file or .edmx file will be saved in your project. You will find it in Solution Explorer.

Entity Data Model

Step-11: Double click the Entity Data Model file or .emx file to open the model in the Entity Data Model designer.

Entity Data Model

Following code will be automatically generated in your web.config file.

<connectionStrings>

<add name="TestDBEntities" connectionString="metadata=res://*/Model.csdl|res://*/Model.ssdl|res://*/Model.msl;provider=System.Data.SqlClient;provider connection string=&quot;Data Source=localhost;Initial Catalog=TestDB;User ID=sa;Password=sa123;MultipleActiveResultSets=True&quot;" providerName="System.Data.EntityClient" />
</connectionStrings>

So this way you can create ADO.NET Entity Data Model in your project.

Comments

  1. By Jonson

    Reply

Leave a Reply

Your email address will not be published. Required fields are marked *