Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Generate SQL for SQLite database from Entity Framework Model

Is it possible to generate a SQLite database from the model with entity framework? I created a SQLite connection and created a model, but when I click "Generate database from model" I get the following, which looks like MS SQL and makes errors if executed with SQLite (Just the beginning of the file):

-- --------------------------------------------------
-- Entity Designer DDL Script for SQL Server 2005, 2008, and Azure
-- --------------------------------------------------
-- Date Created: 11/25/2010 00:26:41
-- Generated from EDMX file: G:\Foo\Bar\Model1.edmx
-- --------------------------------------------------

SET QUOTED_IDENTIFIER OFF;
GO
USE [foobar.sqlite];
GO
IF SCHEMA_ID(N'dbo') IS NULL EXECUTE(N'CREATE SCHEMA [dbo]');
GO
...

My connection string looks like the following, so I definitely chose the right database type:

'metadata=res://*/Model1.csdl|res://*/Model1.ssdl|res://*/Model1.msl;provider=System.Data.SQLite;provider connection string="data source=G:\foo\bar\baz"'

Shouldn't it work this way?

EDIT:

Since nobody seem to know an answer I'll make it easier: Is it possible to generate SQL code with EF for any database other than the MICROSOFT SQL SERVER?

like image 625
codymanix Avatar asked Nov 24 '10 23:11

codymanix


1 Answers

I was looking for a solution to this, when I stumbled upon this link: http://code.msdn.microsoft.com/Demo-of-ADONET-POCO-with-140ad3ad

Place the SSDLToSQLite3.tt file in C:\Program Files (x86)\Microsoft Visual Studio 10.0\Common7\IDE\Extensions\Microsoft\Entity Framework Tools\DBGen and you should be able to choose this as the DDL Generation Template in the Entity Designer.

Once you do that, the model will create SQL suited for SQLite.

like image 186
toxvaerd Avatar answered Oct 26 '22 01:10

toxvaerd