Create Records with Linq to SQLite via DbLinq

我们两清 提交于 2019-12-07 21:56:54

问题


I have (after some significant effort) gotten DbLinq working with the latest build of Mono on OS X.

Has anybody successfulyl created database entities via DbLinq/Sqlite?

For example, I have the following table:

CREATE TABLE UserType (
    id integer primary key,
    description text )

I have generated my *.cs file and am using the following code to attempt to create a new UserType entry:

UserType newUserType = new UserType();
newUserType.id = null // Attempting to get SQLite to increment
newUserType.description = "Administrator";

db.UserType.InsertOnSubmit(newUserType);

db.SubmitChanges();

The call to SubmitChanges is throwing an exception about invalid syntax specifically related to @ (I'm guessing in a parameterized query to do the insert). It looks like the code being generated is SQL Server specific. Is there a fix or flag I'm missing, or is inserting records through DbLinq to SQLite not supported?


回答1:


Turns out that when using DbLinq, you need to modify the DB Connection string so Mono's System.Data.Linq knows which DB provider to use when generating its SQL code.

Old:

SqliteConnection("Data Source=MyDatabase.sqlite");

New:

SqliteConnection("DbLinqProvider=Sqlite;Data Source=MyDatabase.sqlite");

It's as simple as that.



来源:https://stackoverflow.com/questions/1477729/create-records-with-linq-to-sqlite-via-dblinq

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!