Fixing the Entity Framework designer “Generate Database from Model” T4 template

The Entity Framework Designer include a reverse engineer feature called “Generate Database from Model” that enables a “Model first” workflow, and also enable you to persist any model modification in a new database.


The T4 template used for this feature supports both SQL Server and SQL Server Compact, but unfortunately lacks consistency in it’s use of the GO keyword. GO is used after each statement, except FOREIGN KEY constraint creation statements. Apart for being inconsistent, this also prevents SQL Server Compact Toolbox from executing the script, without a number of manual edits.

I have proposed a fix on Codeplex for the next version of the designer, but it will not happen until version 7 (if ever).

So in the meantime, I have updated the template to fix this, you can start using it today as replacement for the current one as follows:

1: Download my updated T4 file from here. (The same file is used in both Visual Studio 2010 and 2012)

2: Copy the downloaded file to the
C:Program Files (x86)Microsoft Visual Studio 11.0Common7IDEExtensionsMicrosoftEntity Framework ToolsDBGen folder
(for VS 2012)
or to
C:Program Files (x86)Microsoft Visual Studio 10.0Common7IDEExtensionsMicrosoftEntity Framework ToolsDBGen
(for VS 2010).

3: With the Entity Framework designer open, go to properties, and select the new file as the DDL Generation template:


4: Generate the script.

Write a Comment

Your email address will not be published. Required fields are marked *