create sales order management data model using edmgen exe tool

In this article we will learn how to create an Entity Data Model using the command line utility - EdmGen.exe. The EdmGen.exe command tool is used not only for creating an entity data model but also to validate an entity data model and create object classes from the Conceptual schema definition language file.

The EdmGen.exe command line tool generates the Entity Data Model which contains three files.

.csdl - Conceptual schema definition language - this is also called as Conceptual layer
.msl - Mapping schema definition Language - mapping layer
.ssdl - Storage schema definition Language - storage layer

In the previous article we have shown how to create Entity Data Model using ADO.NET Entity Data Model Designer. If we create Entity Data Model using ADO.NET Entity Data Model Designer, the single .edmx file contains the .csdl, .msl and .ssdl.

If we create Entity Data Model using EdmGen.exe, the files .csdl, .msl and .ssdl are created separately.

The main command line switches we will use with EdmGen.exe command line tool are:

/mode:ViewGeneration
If we use the above switch with EdmGen.exe command line, it precompiles queries into a source file.

/mode:FullGeneration
Creates cSDL,MSL and SSDL files from the database.
It also creates classes and precompile queries for each entity.


/mode:ValidateArtifacts
Validates an Entity Data Model.


/language:Csharp
/language:VB
The above two swiches are for creating code in chosen languages.

/mode:FromSsdlGeneration
Generates .MSL, CSDL and Entity Classes from the SSDL file

/mode:EntityClassGeneration
As name indicates this switch generates classes from the CSDL file.

/provider:
Specifies the name of the ADO.NET data provider.

/connectionstring:
specifies the connection string to be used to connect to the database

/namespace:
Specify the namespace

To create the Entity Data Model for our SalesOrderManagement database, type the following in a command window. In the below code, I have used /mode:fullgeneration switch. We need to pass the connectionstring and the project parameter. The name given to the project parameter is used to create all the files. As the switch indicates it will generate full Entity data model for the database.

edmgen /mode:fullgeneration /c:"Data Source=.;Initial Catalog= SalesOrderManagement;User ID=sa; Password=XXXX;" /p:SoModel

We have seen how to create an Entity Data Model using the command line utility - EdmGen.exe. Having created the Entity data model, we can query the model using the following ways.

LINQ to Entities
Entity SQL
Using methods - LINQ methods
Using methods - Entity framework's ObjectQuery class
Querying using EntityFramework's EntityClient API.


Click here to know how to query Entity data model.