Question

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?

Was it helpful?

Solution

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top