Where().Delete of an object causes a syntax exception

Discussion of open issues, suggestions and bugs regarding Entity Framework support in ADO.NET Data providers
Post Reply
dgxhubbard
Posts: 42
Joined: Fri 14 Aug 2015 20:58

Where().Delete of an object causes a syntax exception

Post by dgxhubbard » Wed 30 Sep 2015 18:19

We use sqlite and sql server. We have an object Gage with a key property Gage_RID. We are using entity framework 6.1.3 and entity framework extensions 6.1.0.133. We have the code below to delete a gage (gageId are the interger keys of the objects to delete). A delete using a where clause fails on sqlite and works on sql server. If we create a temporary gage and attach and remove that works. We have code in to show the sql statement that executes, but the statement does not appear in the output. The exception message is also shown below. Without the sql statement we can't see the syntax. How can we get the delete with a where clause to work.

We would appreciate any help you can provide.


Exception Message:

SQLite error
near "[main]": syntax error

CODE:
using ( var context = new GtContext() )
{
context.Database.Log = s => System.Diagnostics.Debug.WriteLine( s );

for ( int i = 0; i < gageIds.Count; i++ )
{
var gageId = gageIds [ i ];

// works on sqlite
/*
var gage = new Gage() { Gage_RID = gageId };

context.Gages.Attach( gage );
context.Gages.Remove( gage );
*/

// works on sql server fails on sqlite
context.Gages.Where( g => g.Gage_RID == gageId ).Delete();
}
}


Debug Output:
Exception thrown: 'Microsoft.CSharp.RuntimeBinder.RuntimeBinderException' in Microsoft.CSharp.dll
Exception thrown: 'Microsoft.CSharp.RuntimeBinder.RuntimeBinderException' in Microsoft.CSharp.dll
Exception thrown: 'Microsoft.CSharp.RuntimeBinder.RuntimeBinderException' in Microsoft.CSharp.dll
Exception thrown: 'Microsoft.CSharp.RuntimeBinder.RuntimeBinderException' in Microsoft.CSharp.dll
Exception thrown: 'Microsoft.CSharp.RuntimeBinder.RuntimeBinderException' in Microsoft.CSharp.dll
Exception thrown: 'Microsoft.CSharp.RuntimeBinder.RuntimeBinderException' in Microsoft.CSharp.dll
Exception thrown: 'Microsoft.CSharp.RuntimeBinder.RuntimeBinderException' in Microsoft.CSharp.dll
Exception thrown: 'Microsoft.CSharp.RuntimeBinder.RuntimeBinderException' in Microsoft.CSharp.dll
'Gt.Lite.exe' (CLR v4.0.30319: Gt.Lite.exe): Loaded 'DynamicClasses'.
Exception thrown: 'Devart.Data.SQLite.SQLiteException' in Devart.Data.SQLite.dll
Exception thrown: 'Devart.Data.SQLite.SQLiteException' in Devart.Data.SQLite.dll
Exception thrown: 'Devart.Data.SQLite.SQLiteException' in Devart.Data.dll
Exception thrown: 'Devart.Data.SQLite.SQLiteException' in Devart.Data.dll
Exception thrown: 'System.AggregateException' in mscorlib.dll

Shalex
Site Admin
Posts: 8247
Joined: Thu 14 Aug 2008 12:44

Re: Where().Delete of an object causes a syntax exception

Post by Shalex » Fri 02 Oct 2015 10:45

dgxhubbard wrote:We are using entity framework 6.1.3 and entity framework extensions 6.1.0.133.
You are using EntityFramework.Extended, aren't you? Looks like this library was designed for SQL Server only. Please contact a publisher of this library for more information about its functionality and supported database servers.

JIC: enable the dbMonitor tool to trace the database activity, this helps to identify the reason why particular queries fail to execute.

Post Reply