I have the need to regenerate my Entity Model using code. I don’t wan’t to go and right click and update model from database every time there is a change.
So i started looking at EdmGen and EdmGen2
I use EdmGen2 to pregenerate my Model Views for me:
using (System.Diagnostics.Process process = new System.Diagnostics.Process())
{
process.StartInfo.FileName = @"C:\EdmGen2.exe";
process.StartInfo.Arguments = @"/ViewGen cs ""C:\Project\EntityFramework\Model\ApplicationEntityModel.edmx""";
process.StartInfo.WorkingDirectory = @"C:\Project\EntityFramework\Model";
process.Start();
process.WaitForExit();
}
This works perfectly.
No i am trying to regenerate my Entity Model:
using (System.Diagnostics.Process process = new System.Diagnostics.Process())
{
process.StartInfo.FileName = @"C:\EdmGen2.exe";
process.StartInfo.Arguments = String.Format(@"/ModelGen ""{0}"" ""System.Data.SqlClient"" ""ApplicationEntityModel""", ConnectionString);
process.StartInfo.WorkingDirectory = @"C:\Project\EntityFramework\Model";
process.Start();
process.WaitForExit();
}
This only generates the .edmx file. Can’t specify namespaces so this is not working for me.
Is there any tool or template that i can use to completely regenerate my Entity Model', this includes the.edmxanddesigner.cs`?
I got the source code for the EntityStoreSchemaGenerator and was able to code it up.
You can add these filters and such to limit which tables you want. There is also this crazy pluralizer thing to figure out when to add/remove an “S” from the end of your entity collections. It was failing for the case of a word that ended in Status, it though the singular was Statu (I always laughed at that), but i was able to tell it that the plural of Status is Statuses (even if that is not officially correct) and that the singular of Statuses is Status.
The code is here:
http://social.msdn.microsoft.com/Forums/en-US/adodotnetentityframework/thread/30b10ed3-b705-458d-ae1f-19d595bceb39/
I found the code to a class that would merge all the files into an edmx.
http://fusioncrm.googlecode.com/svn-history/r5/trunk/Fusion.Data.Generation/ModelGenerator.cs
I wrote a consoleapp that runs all this for a client based on a “gold” database, I also hated running this from the designer because it always was slightly different for some reason. This way seems to always generate the same file and as such is clearer what changed when doing check-ins to version control.