Entity Framework – Generate Model & Mapping Files Using edmgen


As always we will take to the command line and start building out a simple Entity Framework application.


What is entity framework?


The Entity Framework is a set of technologies in ADO.NET that support the development of data-oriented software applications. Architects and developers of data-oriented applications have typically struggled with the need to achieve two very different objectives. They must model the entities, relationships, and logic of the business problems they are solving, and they must also work with the data engines used to store and retrieve the data. The data may span multiple storage systems, each with its own protocols; even applications that work with a single storage system must balance the requirements of the storage system against the requirements of writing efficient and maintainable application code.

The Entity Framework enables developers to work with data in the form of domain-specific objects and properties, such as customers and customer addresses, without having to concern themselves with the underlying database tables and columns where this data is stored. With the Entity Framework, developers can work at a higher level of abstraction when they deal with data, and can create and maintain data-oriented applications with less code than in traditional applications. Because the Entity Framework is a component of the .NET Framework, Entity Framework applications can run on any computer on which the .NET Framework (starting with version 3.5 SP1) is installed.


Create Model

Let us create the model. Again, the model is an abstract model of the entities and the relationships between the entities ( Foreign Keys ).


Visual Studio

Of course, we can do so via Visual Studio.

But, that is too easy and we might miss some of the little things.



What is edmgen?

Edmgen are actually two words intermingled, edm and gen.

edm stands for Entity Data Model and gen is generation.

It is a command line tool.


Where is edmgen located?

Depending on the version of .Net you are running, you will need to target a different folder.

It is easy enough to open up a command shell and find edmgen.exe



where /R c:\windows\microsoft.net edmgen.exe




Issue Sample edmgen


set "_dirBin=C:\Windows\Microsoft.NET\Framework64\v4.0.30319\"
set "_appName=edmgen.exe"
set _appNameFull=%_dirBin%\%_appName%

set "_appMode=FullGeneration"

set "_language=csharp"
set "_project=dbdiag"

rem set "_csIS=Data Source=.\v2014;Database=DBDiag;Application Name=diagConsole;  Integrated Security=SSPI;"
set "_csSN=Data Source=.\v2014;Database=DBDiag;Application Name=diagConsole; uid=edmgen; pwd=62aprAcEcRaq;"
set "_cs=%_csSN%"

%_appNameFull% /mode:%_appMode% /connectionstring:"%_cs%" /language:%_language% /project:%_project%




  1. Loading database information
    • App connects to database
    • And, determines the list of database objects available to the DB account in use
  2. Generates
    • Generates ssdl
    • Generates msl
    • Generates csdl



This is obviously only the first step.

We have generated the model files.

In follow-up posts, we will review the generated files, discuss how to use and integrate into our main application, update the generated files to include new DB Objects or inherit DB changes, and target different Db environment, i.e. QA and Prod.


One thought on “Entity Framework – Generate Model & Mapping Files Using edmgen

Leave a Reply

Please log in using one of these methods to post your comment:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s