From the Entity Framework Model, generate SQL for a SQLite database.

.net entity-framework orm sqlite sql-server

Question

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?

1
11
11/26/2010 5:13:40 PM

Popular Answer

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.

11
6/14/2011 11:20:30 AM


Related Questions





Related

Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow