LINQ到SQL使用SQLite:近语法错误"选取[插入时 [英] LINQ-to-SQL with SQLite: syntax error near "SELECT" when inserting

查看:303
本文介绍了LINQ到SQL使用SQLite:近语法错误"选取[插入时的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直使用 System.Data.SQLite 我的应用程序供应商。当我尝试创建一个新的对象,并将其插入到数据库中,但是,我得到一个SQL 语法错误附近的选择



基本上我的代码如下所示:

  //设备是连接到我的数据库
一个DataContext表<商店和GT;商店= supplies.Stores;
// ...
商店newStore =新店();
//商店都有一个ID(PK自动增量),姓名,号码和EntitySet的<&用法GT;
newStore.Name =新店
newStore.Number = 0;
// ...
stores.InsertOnSubmit(newStore);
supplies.SubmitChanges();



但传遍了一些方法。



这是一个常见/新手问题?如果是这样,我究竟做错了什么?
。如果没有,在那里/我应该怎么调试呢?我是相当新的LINQ到SQL



更新:错误之前生成的最后一个查询的日志输出是这样的:

  INSERT INTO [存储]([编号],[名])
值(@ P0,@ P1)

选择CONVERT(智力,SCOPE_IDENTITY())AS [值]
- @ P0:输入的Int32(大小= 0; PREC = 0;规模= 0)[0]
- @ P1:输入字符串(大小= 0; PREC = 0;规模= 0)[新店]
- 上下文:sqlProvider的(SQL2008)型号:AttributedMetaModel体形:3.5.30729.4926


解决方案

有这里的一篇文章有​​关如何显示生成可能会给你的SQL什么SQLite不喜欢更好的主意: http://msdn.microsoft.com /en-us/library/bb386961.aspx



编辑日志:从sqlProvider的(SQL2008)的一部分,它看起来像它试图用2008年的SqlServer语法而不是SQLite的语法,这可以解释为什么它认为语法是无效的。



编辑再作进一步的信息:有关SQLite和LINQ的信息这个问题:的 http://stackoverflow.com/questions/250071/linq-with-sqlite-linqtosql


I have been using the System.Data.SQLite provider for my application. When I try to create a new object and insert it into the database, however, I get a SQL syntax error near "SELECT".

Basically my code looks like:

//supplies is a DataContext connected to my DB
Table<Store> stores = supplies.Stores;
//...
Store newStore = new Store();
// A Store has an Id (pk autoincrement), Name, Number, and EntitySet<Usages>
newStore.Name = "New Store";
newStore.Number = 0;
//...
stores.InsertOnSubmit(newStore);
supplies.SubmitChanges();

but spread throughout some methods.

Is this a common/newbie problem? If so, what am I doing wrong? If not, where/how should I debug this? I am rather new at LINQ-to-SQL.

UPDATE: The log output of the last query generated before the error is this:

INSERT INTO [Stores]([Number], [Name])
VALUES (@p0, @p1)

SELECT CONVERT(Int,SCOPE_IDENTITY()) AS [value]
-- @p0: Input Int32 (Size = 0; Prec = 0; Scale = 0) [0]
-- @p1: Input String (Size = 0; Prec = 0; Scale = 0) [New Store]
-- Context: SqlProvider(Sql2008) Model: AttributedMetaModel Build: 3.5.30729.4926

解决方案

There's an article here about how to show the SQL being generated which might give a better idea of what SQLite doesn't like: http://msdn.microsoft.com/en-us/library/bb386961.aspx

EDIT for log: From the SqlProvider(Sql2008) part, it looks like it's trying to use SqlServer 2008 syntax instead of SQLite syntax which would explain why it thinks the syntax is invalid.

EDIT again for further info: See this question for info on SQLite and Linq: http://stackoverflow.com/questions/250071/linq-with-sqlite-linqtosql

这篇关于LINQ到SQL使用SQLite:近语法错误&QUOT;选取[插入时的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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