How to create an ADO.NET Entity Data Model (EDM) in ASP.NET MVC

watch_later Sunday, December 8, 2019

Introduction


This article gives an explanation about how to create an ado.net entity data model (EDM) in asp.net MVC application using entity framework as well as also explains what is entity framework, what is entity data model (EDM), what is .edmx file and how to create .edmx file using entity framework data model in visual studio.


ADO.NET Entity Data Model (EDM)

Many of the developers and beginners who are working with the entity framework will have at least heard talk about the (EDM) entity data model and .edmx file, but I noticed still many of them not have an idea about the entity data model and also didn't know how to create an entity data model in asp.net MVC application, so in this article I'll explain what is entity data model, how to create entity data model in asp.net MVC application as well as basic information about the latest version and basic features of the entity framework and 

Requirement 


1) Explain what is entity framework?
2) What is the (EDM) entity data model?
3) Explain how to create an (EDM)  entity data model in asp.net MVC application?

Implementation


Entity framework


The entity framework is written in c# and it is an open-source object-relational mapper (ORM) framework and supported by Microsoft. The first release of the entity framework is on 11 August 2008. The ORM (object-relational mapper) takes care of creating a connection with the database, executing commands as well as simplifies the mapping between the objects in your application to the tables, columns, and procedures of a relational database.

Entity data model (EDM)


The entity data model (EDM) is a set of concepts that describe data structures as well as that describes entities and the relationships between them.

So, let's see how to create an entity data model or create a .edmx file based on the existing database step by step.

Step 1: Open visual studio.

Step 2: Click on File >> New >> Website.

Step 3: Create a simple asp.net MVC application.

Step 4: Right-click on the name of the project from solution explorer as shown in the screen below and select Add >> New Item.

Visual studio Add New Item

Step 5: While clicks on New Item one popup wizard will open in the screen where you have to select the ADO.NET Entity Data Model option and enter the appropriate name of the entity data model, make sure that the extension should be .edmx and then click on Next button.

ADO.NET Entity Data Model (EDM)

Step 6: While you click on the Next button system will launch the entity data model wizard where you have to select Generate from database option and click on the Next button as shown in the screen below.

Entity data model wizard

Step 7: In the Next wizard you have to choose your database connection where you can choose a database connection from given dropdown selection or you can also create a new database connection.

Database connection

As you can see on the screen above there are two radio selections that are there, which indicates where you want to include or exclude sensitive data from the connection string such as user, password and etc that you can choose as per your needs.

You can also see there one checkbox selection also there in the connection wizard that indicates whether you want to add created database connection string in the web.config file or not. you have to mark that checkbox field as checked if you want to add connection string in the web.config file and then finally click on the Next button.

Step 8: Now you have to select database objects and settings and you have to select tables, view or stored procedure by clicking on the available checkbox selection and click on Finish.

Database objects and settings

While you will open the web.config file then you can see created database connection string as shown in the code below.
  <entityFramework>
    <defaultConnectionFactory type="System.Data.Entity.Infrastructure.LocalDbConnectionFactory, EntityFramework">
      <parameters>
        <parameter value="v13.0" />
      </parameters>
    </defaultConnectionFactory>
  </entityFramework>
  <connectionStrings>
    <add name="Codingvila_ExmplesEntities" connectionString="metadata=res://*/AngularJS_Cascading_DropdownModel.csdl|res://*/AngularJS_Cascading_DropdownModel.ssdl|res://*/AngularJS_Cascading_DropdownModel.msl;provider=System.Data.SqlClient;provider connection string=&quot;data source=DESKTOP-P1PHIU6\SQLEXPRESS;initial catalog=Codingvila_Exmples;integrated security=True;MultipleActiveResultSets=True;App=EntityFramework&quot;" providerName="System.Data.EntityClient" />
  </connectionStrings>
Step 9: Finally, Open entity data model (EDM) designer by double-clicking on the.edmx file that shows all the entities for the selected tables and the relationships between them, as shown in the screen below.

Entity Data Model

Step 10: Done.

Summary


In this article, we learned how to create an ado.net entity data model (EDM) in asp.net MVC application as well as basic information about the entity framework.

Codingvila provides articles and blogs on web and software development for beginners as well as free Academic projects for final year students in Asp.Net, MVC, C#, Vb.Net, SQL Server, Angular Js, Android, PHP, Java, Python, Desktop Software Application and etc.



sentiment_satisfied Emoticon