Search Wiki:
EdmGen2 is a command-line tool for the Microsoft ADO.NET Entity Framework. The tool can be used as a replacement for the EdmGen.exe tool that ships with the .Net framework 3.5 SP1. EdmGen.exe can only read and write the CSDL, SSDL & MSL file formats. However, EdmGen2.exe can read and write the EDMX file format used by the Visual Studio design tools. Additionally, EdmGen2.exe can translate between EDMX and CSDL, SSDL & MSL formats, and the source code can act as examples on using the tooling APIs defined in the System.Data.Entity.Design assembly.

Additionaly, EdmGen2.exe contains some experimental functionality not found in EdmGen.exe. Ankit Malpani, an intern with Microsoft Research in summer of 2008, and James Terwilliger, a Post Doc researcher with MSR, updated EdmGen2.exe with the ability to identify inheritance relatationships in relational database schema. You can access this functionality by using the "RetrofitModel" option. The RetrofitModel option connects to a database instance and constructs an EDM model (csdl, msl, ssdl, and edmx files) that includes inheritance. The tool uses data mining techniques to identify TPT and TPH patterns in the database instance, as well as vertical partitioning, and constructs a suitable model and mapping. To use the tool, launch EdmGen2 with the following arguments:

    /RetrofitModel "connection string" "provider" "entitiy name"

For instance, the following will connect to a local AdventureWorks database, and create files and an EDM instance named AVWorks:

    EdmGen2 /RetrofitModel "Server=(local);Integrated Security=true;Initial Catalog=AdventureWorks;" "System.Data.SqlClient" "AVWorks"

In the previous version (version 1.0.20090401), the RetrofitModel option would bring up a dialog that would allow the user to choose the tables to include in the model. With version 1.0.20091019, the ConceptualEdmGen dll now has two additional public methods that can set the list of tables without bringing up a dialog – one that pulls the list of tables from a file, and one where the list of tables is fed directly to the method as a list of strings.

The EdmGen2 code as it appears in the package uses the “from file” option, where it looks for a file called “Tables.txt” in the current directory, and if found, feeds its contents to the dll to set the list of tables. So for instance, if the following were the contents of the file “Tables.txt”:


EdmGen2 would generate (for the RetrofitModel option) a model for all of the tables in the HumanResources schema for AdventureWorks. For both methods, an empty list will result in all tables in the database being added to the model. The table selection UI will still appear if neither table selection method is called.
Last edited Oct 19 2009 at 9:18 PM  by MikeKaufman, version 17
RogerJ wrote  Jun 21 2008 at 4:53 PM  
I think your description would be clearer if your second sentence read: "It can be used as a replacement for the original EdmGen.exe tool, which ships with the .Net Framework 3.5 and only reads and writes CSDL, SSDL and MSL files (not EDMX files).


MikeKaufman wrote  Jun 26 2008 at 9:26 PM  
Thanks Roger. I updated the description a bit. I hope it is more clear.

void wrote  Nov 25 2008 at 1:09 PM  
You probably want to modify the code so it allows for data provider to report warnings. Don't exit if all you get when generating is EdmSchemaErrorSeverity.Warning. I'm using Npgsql as provider and had to modify your code to skip warnings. This is a great tool, thanks.

GT wrote  May 27 2009 at 7:48 PM  
Does not support namespaces, a.k.a. useless! , I have spent 4 hours writing a script, and then found that I cannot use namespaces, so again, what is the point of the tool?

JPollack wrote  Oct 30 2009 at 3:38 PM  
Thanks "void" for the comment. I was stuck at the same problem.
I wrote a method called "HasErrors" for the EdmGen2 class.

private static Boolean HasErrors(IEnumerable<EdmSchemaError> errors)
if (errors == null)
return false;

Boolean errorFound = false;

foreach (EdmSchemaError error in errors)
if (error.Severity == EdmSchemaErrorSeverity.Warning) continue;

errorFound = true;
return errorFound;

Find line number 150 and add a line "if (HasErrors(ssdlErrors))" before "return" so the result would be:
// write out errors
if ((ssdlErrors != null && ssdlErrors.Count > 0))
System.Console.WriteLine("Error/warning(s) occurred during generation:");

if (HasErrors(ssdlErrors))

Compile and run and that is IT!

A hint for NPgSQL users by If you got flooded by the warnings as I did (almost 2k lines) at the CMD window, direct the output to a file like this:
edmgen2.exe /ModelGen <connection string> <provider name> <model name> >> output.txt

You will find the "output.txt" from the same directory as the edmgen2.exe with all the content. Also it is faster then writing warnings on the screen.

SergioC wrote  Aug 5 2013 at 11:30 AM  
Doesn't work. Not generate views and XXXModel.Designer.cs

Page view tracker