Platinum Partner
dotnet,how-to,microsoft,tools,vb.net,visual studio,.net & windows,c-sharp,data-access,entity-framework

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.

image

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 SSDLToSQL10GOFixed.tt file to the
C:\Program Files (x86)\Microsoft Visual Studio 11.0\Common7\IDE\Extensions\Microsoft\Entity Framework Tools\DBGen folder
(for VS 2012) 
or to 
C:\Program Files (x86)\Microsoft Visual Studio 10.0\Common7\IDE\Extensions\Microsoft\Entity Framework Tools\DBGen 
(for VS 2010).

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

image

4: Generate the script.

Published at DZone with permission of {{ articles[0].authors[0].realName }}, DZone MVB. (source)

Opinions expressed by DZone contributors are their own.

{{ tag }}, {{tag}},

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}
{{ parent.authors[0].realName || parent.author}}

{{ parent.authors[0].tagline || parent.tagline }}

{{ parent.views }} ViewsClicks
Tweet

{{parent.nComments}}