I would be eternally grateful if someone would help me with this issue. This
is something that I’ve been banging my head against for a while now. In my
current project, we need to support .Net 3.5.1. This obviously means I cannot
use SQLite EF6 support, but LINQ is still supposed to be supported. But, try
as I may, I cannot get linq to actually use the linq-to-sql module. Some
queries execute correctly, but the system is still using the SQLServer 2008
linq-to-sql implementation that is the default for .Net 3.5.1
If I switch to .Net 4.5, everything works correctly, but with .Net 3.5 some
stuff just doesn’t work.
Here is my connection code. Nothing very complicated:
System.Data.SQLite.SQLiteConnection connection = new
System.Data.SQLite.SQLiteConnection(“Data Source=AgentData.s3db”);
DataContext context = new DataContext(connection);
And when I execute a linq command like this everything works fine and the
SQLite DB is queried correctly:
var propertiesTable = context.GetTable<Property>();
var PropertiesSet = from a in propertiesTable
where a. Name == propertyName
orderby a.Name
select a;
foreach (var property in PropertiesSet)
{
Trace(property.Value);
}
However, when I execute certain code things just don’t work and throw
exceptions. Especially when dealing with auto number columns.
I managed to figure out by dumping the linq log that the reason is that the
SQLite Linq-to-SQL code is just not getting invoked. Here is the log output:
TRACE LINQ-SQL: SELECT [t0].[PropertyId], [t0].[Name], [t0].[Value]
FROM [Properties] AS [t0]
WHERE [t0].[Name] = @p0
ORDER BY [t0].[Name]
TRACE LINQ-SQL: -- @p0: Input String (Size = 0; Prec = 0; Scale = 0)
[DatabaseVersion]
TRACE LINQ-SQL: -- Context: SqlProvider(Sql2008) Model: AttributedMetaModel
Build: 3.5.30729.6404
Notice the "SqlProvider(Sql2008)” I believe this means that the linq-to-sql
module that is getting invoked is the sqlserver 2008 translator, not the sqlite
translator. The code that generated this particular output (above) actually
works fine because that particular SQL statement will run correctly in SQLite.
But for other things, the SQL code generated by the translator is not SQLite
compatible (for example if it uses the TOP keyword or a whole slew of other
incompatibilities).
I know I have everything installed correctly because I am actually getting
updates to my SQLite DB file. But the app just throws exceptions wherever the
SQL that gets generated isn’t SQLite compatible.
Any idea how to force the Connection to use the correct Linq-to-SQL
implementation? Is there some configuration that I am missing that makes this
work?
Thanks for any help anyone can lend!
Sean
_______________________________________________
sqlite-users mailing list
[email protected]
http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users