Archive for April, 2011

Generate Entity-Framework DDL-Script for SQLite

April 17, 2011

By default the Entity Framework designer for Visual Studio only generates DDL Scripts for Microsoft SQL Server (CE).

However you can change the template file (.tt) which is used to generate the SQL statements. Just click on empty space in the designer and take a look in the property sheet window.

The default template is called SSDLToSQL10.tt and resides in a subfolder of the Visual Studio program files directory.

For one of my projects I needed the generated SQL to be compatible with SQLite, so I modified the original file for SQLite and created a new version, which you can download below.

After downloading the files and putting them in the correct directories, you should be able to select them inside the EF designer.

Keep in mind that I can’t give any guarantees that this files will work as you expect. I wrote them specifically for my project and I’m just sharing them in the hopes that they are useful for anyone.

Download the following zip file: SQLiteGen.zip

You will find 2 files in the zip file:

Put the SSDLToSQLite.tt file in the directory
.\Microsoft Visual Studio 10.0\Common7\IDE\Extensions\Microsoft\Entity Framework Tools\DBGen\

Put the GenerateSQL.Utility.ttinclude file in the directory
.\Microsoft Visual Studio 10.0\Common7\IDE\Extensions\Microsoft\Entity Framework Tools\Templates\Includes\

You are done! Smiley Now you should be able to select the new template in the Visual Studio designer and enjoy the newly SQLite compatible SQL script.