I'm having the following issue when accessing a SQLite database using LINQ. Abreviated code looks like this:
...
using System.Linq
using System.Data.Linq
using System.Data.Linq.Mapping
using System.Data.SQLite
...
DataContext sqltContext= new DataContext(sqltConnection);
featureTable = sqltContext.GetTable<FeatureModel>();
count= featureTable.Count(); // count == 1
The following line fails with error: "SQL logic error or missing database\r\nunknown error"
//currentFeature = featureTable.First();
But iterator works fine:
foreach (var feature in featureTable)
{
currentFeature = feature;
break;
}
In both cases, I'm getting the following error in debug output:
SQLite error (1): near ".": syntax error
What would cause this error? I'm hoping someone has seen this issue before and can point me in the right direction. But I will probably end up stepping through the System.Data.SQLite code in the debugger at some point.
EDIT: based on comment below from GeorgeT, I added sqltContext.Log = Console.Out;
. Based on the logging output, it appears that LINQ is generating a SELECT TOP
command, which isn't compatible with SQLite. The solution to this would seem to be to avoid the First
or FirstOrDefault
methods, or else use something like DBLinq