views:

229

answers:

2

I'm having trouble trying to use the 'Auto-Sync' feature of DBML with SQLite. I have a class in my data model that contains a primary key (id). This key is defined as "INTEGER PRIMARY KEY", which SQLite maps to the rowid of the row. To support this, I have set "Auto Generated Value" to 'True' and "Auto-Sync" to 'OnInsert'.

The problem is, when I commit a new entry to the database, the SELECT string used by the LINQ to SQL classes is not supported by SQLite:

SELECT CONVERT(BigInt,SCOPE_IDENTITY()) AS [value]

Instead, SQLite has the last_insert_rowid() function, which I cannot seem to point to.

Does anyone know how to remedy this? Possibly by changing the statement used to select the last row ID or some other trick I'm missing?

EDIT There appears to be some traffic on the provider's website, but no resolutions.

EDIT Since I seem to have confused the question, here's how I've set up my application. Hopefully it helps shed some light on my thought process, and maybe an underlying issue.

  • Add new "LINQ to SQL Classes" file to my solution
  • Model my database in the designer, named DataModel
  • Open a database using a System.Data.SQLite.SQLiteConnection
  • Initialize the DataModel instance using this connection
+1  A: 

You are adding a "Linq-to-SQL" data model to your project, but you're using it against SQLite - that'll never work of course! Linq-to-SQL only ever supports SQL Server (always has, always will), and thus its SQL statements that it generates are SQL Server T-SQL Statements - nothing else.

If you want to use the Entity Framework with SQLite, you need to use "ADO.NET Entity Data Model" (file with the .EDMX extension) as your data model.

alt text

Only that will support third-party database drivers like SQLite and others!

marc_s
Thanks for the answer... and bummer. I didn't realize that LINQ to SQL was so tightly coupled to SQL server. Unfortunately, I don't have an option to create the ADO.NET Entity Data Model (DevStudio Standard). The LINQ to SQL works great for simple queries and inserts, but seems to fail for this case only, so far.
jheddings
A: 

Devart implementation of LINQ to SQLite does not contain this problem. The autoincrememnt column is treated correctly.

Devart