生成SQL从实体框架模型SQLite数据库 [英] Generate SQL for SQLite database from Entity Framework Model

查看:842
本文介绍了生成SQL从实体框架模型SQLite数据库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否有可能生成的模型与实体框架SQLite数据库?我创建了一个SQLite的连接,并创建了一个模型,但是当我点击生成模型数据库我得到的下面,它看起来像MS SQL,如果使用SQLite(文件刚开始的时候)执行使得错误:

   -  ------------------------------------ --------------
 - 实体设计DDL脚本对于SQL Server 2005,2008,和天青
 -  ------------------------------------------------ - 
 - 创建日期:11/25/2010 0时26分41秒
 - 从生成EDMX文件:G:\富\酒吧\ Model1.edmx
 -  ------------------------------------------------ - 

SET QUOTED_IDENTIFIER OFF;
走
使用[foobar.sqlite]
走
如果SCHEMA_ID(N'dbo')为空EXECUTE(值为N'create SCHEMA [DBO]');
走
...
 

我的连接字符串看起来像下面,所以我肯定选择了正确的数据库类型:

<$p$p><$c$c>'metadata=res://*/Model1.csdl|res://*/Model1.ssdl|res://*/Model1.msl;provider=System.Data.SQLite;provider连接字符串=数据源= G:\富\酒吧\巴兹'

难道不应该以这种方式工作?

编辑:

由于没有人似乎知道答案,我会更容易?是否有可能生成SQL code与EF比对MICROSOFT SQL SERVER以外的任何数据库

解决方案

我一直在寻找一个解决方案,这一点,当我偶然发现此链接:<一href="http://$c$c.msdn.microsoft.com/Demo-of-ADONET-POCO-with-140ad3ad">http://$c$c.msdn.microsoft.com/Demo-of-ADONET-POCO-with-140ad3ad

将在C SSDLToSQLite3.tt文件:\程序文件(x86)\微软的Visual Studio 10.0 \ Common7 \ IDE \扩展\微软\实体框架TOOLS \ DBGEN,你应该能够选择这个作为DDL生成模板在实体设计。

一旦你这样做,该模型将创建SQL适合SQLite的。

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?

解决方案

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.

这篇关于生成SQL从实体框架模型SQLite数据库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆