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 new experimental functionality not found in EdmGen.exe. James Terwilliger, a Post Doc researcher with Microsoft Research, recently updated EdmGen2.exe with some functionality to identify inheritance relatationships from a 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"


Last edited Apr 1 2009 at 4:09 PM  by MikeKaufman, version 10
Comments
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).

--rj

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;
break;
}
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:");
WriteErrors(ssdlErrors);

if (HasErrors(ssdlErrors))
return;
}

Compile and run and that is IT!

A hint for NPgSQL users by PgFoundry.org. 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

Updating...
Page view tracker