





















































You can create the ADO.NET Entity Data Model in one of the two ways:
We will first take a look at how we can design an Entity Data Model using the ADO.NET Entity Data Model Designer which is a Visual Studio wizard that is enabled after you install ADO.NET Entity Framework and its tools. It provides a graphical interface that you can use to generate an Entity Data Model.
Here are the tables of the 'Payroll' database that we will use to generate the data model:
To create an entity data model using the ADO.NET Entity Data Model Designer, follow these simple steps:
Note that you can also use the Empty model template to create the Entity Data Model yourself.
If you select the Empty Data Model template and click on next, the following screen appears:
As you can see from the above figure, you can use this template to create the Entity Data Model yourself. You can create the Entity Types and their relationships manually by dragging items from the toolbox. We will not use this template in our discussion here. So, let's get to the next step.
We will use a dot to specify the database server name. This implies that we will be using the database server of the localhost, which is the current system in use.
<connectionStrings> <add name="PayrollEntities" connectionString="metadata=res:// *; provider=System.Data.SqlClient;provider connection string=" Data Source=.;Initial Catalog=Payroll;User ID=sa;Password=joydip1@3; MultipleActiveResultSets=True"" providerName="System.Data.EntityClient" /> </connectionStrings>
Note the Entity Connection String generated automatically. This connection string will be saved in the ConnectionStrings section of your application's web.config file. This is how it will look like:
Here is the output displayed in the Output Window while the Entity Data Model is being generated:
Your Entity Data Model has been generated and saved in a file named PayrollModel.edmx. We are done creating our first Entity Data Model using the ADO.NET Entity Data Model Designer tool.
When you open the Payroll Entity Data Model that we just created in the designer view, it will appear as shown in the following figure:
Note how the Entity Types in the above model are related to one another. These relationships have been generated automatically by the Entity Data Model Designer based on the relationships between the tables of the Payroll database.
In the next section, we will learn how we can create an Entity Data Model using the EdmGen.exe command line tool.
We will now take a look at how to create a data model using the Entity Data Model generation tool called EdmGen.
The EdmGen.exe command line tool can be used to do one or more of the following:
The EdmGen.exe command line tool generates the Entity Data Model as a set of three files: .csdl, .msl, and .ssdl. If you have used the ADO.NET Entity Data Model Designer to generate your Entity Data Model, the .edmx file generated will contain the CSDL, MSL, and the SSDL sections. You will have a single .edmx file that bundles all of these sections into it. On the other hand, if you use the EdmGen.exe tool to generate the Entity Data Model, you would find three distinctly separate files with .csdl, .msl or .ssdl extensions.
Here is a list of the major options of the EdmGen.exe command line tool:
Option | Description |
/help | Use this option to display help on all the possible options of this tool. The short form is /? |
/language:CSharp | Use this option to generate code using C# language |
/language:VB | Use this option to generate code using VB language |
/provider:<string> | Use this option to specify the name of the ADO.NET data provider that you would like to use. |
/connectionstring:
<connection string> |
Use this option to specify the connection string to be used to connect to the database |
/namespace:<string> | Use this option to specify the name of the namespace |
/mode:FullGeneration | Use this option to generate your CSDL, MSL, and SSDL objects from the database schema |
/mode:EntityClassGeneration | Use this option to generate your entity classes from a given CSDL file |
/mode:FromSsdlGeneration | Use this option to generate MSL, CSDL, and Entity Classes from a given SSDL file |
/mode:ValidateArtifacts | Use this option to validate the CSDL, SSDL, and MSL files |
/mode:ViewGeneration | Use this option to generate mapping views from the CSDL, SSDL, and MSL files |