Exception during DbContext.SaveChanges()
Posted: Wed 13 Jan 2016 21:52
Hello, I have a problem with a query, using Devart.Data.MySql 8.4.543.0. I have this method:
and calling it gives me an System.Data.Entity.Infrastructure.DbUpdateException while calling SaveChanges(). Same thing happens if I use RemoveRange(). I added the exception detail at the end.
The selection of the records to delete works well. Am I doing something wrong, or is this a bug?
The table suppliers_areas is very simple, just this:
MySQl is quite old, 5.0.67, but it is not in my power to change that, so I'll have to get along with it.
Code: Select all
public void RemoveSupplierArea(long _suppliersID, string _symbolOfArea)
{
byte area_id = this.GetAreaBySymbol(_symbolOfArea).id;
var sup_a = from t in Entity.suppliers_areas
where (t.areas_id == area_id) && (t.suppliers_id == _suppliersID)
select t;
List<suppliers_areas> sal = sup_a.ToList();
foreach(suppliers_areas sa in sal)
{
Entity.suppliers_areas.Remove(sa);
}
Entity.SaveChanges();
}
The selection of the records to delete works well. Am I doing something wrong, or is this a bug?
The table suppliers_areas is very simple, just this:
Code: Select all
CREATE TABLE `suppliers_areas` (
`suppliers_id` INT(10) UNSIGNED NOT NULL,
`areas_id` TINYINT(3) UNSIGNED NOT NULL,
UNIQUE INDEX `suppliers_id` (`suppliers_id`, `areas_id`)
)
COLLATE='utf8_unicode_ci'
ENGINE=MyISAM
;
Code: Select all
System.Data.Entity.Infrastructure.DbUpdateException was unhandled by user code
HResult=-2146233087
Message=An error occurred while updating the entries. See the inner exception for details.
Source=EntityFramework
StackTrace:
bei System.Data.Entity.Internal.InternalContext.SaveChanges()
bei System.Data.Entity.Internal.LazyInternalContext.SaveChanges()
bei System.Data.Entity.DbContext.SaveChanges()
bei WipsModelManager.WipsModelManager.RemoveSupplierArea(Int64 _suppliersID, String _symbolOfArea) in C:\Users\Administrator\Documents\Visual Studio 2015\Projects\WinWipsProject\WipsModelManager\WipsModelManager.cs:Zeile 372.
bei WipsUnitTests.UnitTest1.DeleteSuppliersArea() in C:\Users\Administrator\Documents\Visual Studio 2015\Projects\WinWipsProject\WipsUnitTests\UnitTest1.cs:Zeile 41.
InnerException:
HResult=-2146233087
Message=An error occurred while updating the entries. See the inner exception for details.
Source=EntityFramework
StackTrace:
bei System.Data.Entity.Core.Mapping.Update.Internal.UpdateTranslator.Update()
bei System.Data.Entity.Core.EntityClient.Internal.EntityAdapter.<Update>b__2(UpdateTranslator ut)
bei System.Data.Entity.Core.EntityClient.Internal.EntityAdapter.Update[T](T noChangesResult, Func`2 updateFunction)
bei System.Data.Entity.Core.EntityClient.Internal.EntityAdapter.Update()
bei System.Data.Entity.Core.Objects.ObjectContext.<SaveChangesToStore>b__35()
bei System.Data.Entity.Core.Objects.ObjectContext.ExecuteInTransaction[T](Func`1 func, IDbExecutionStrategy executionStrategy, Boolean startLocalTransaction, Boolean releaseConnectionOnSuccess)
bei System.Data.Entity.Core.Objects.ObjectContext.SaveChangesToStore(SaveOptions options, IDbExecutionStrategy executionStrategy, Boolean startLocalTransaction)
bei System.Data.Entity.Core.Objects.ObjectContext.<>c__DisplayClass2a.<SaveChangesInternal>b__27()
bei System.Data.Entity.Infrastructure.DefaultExecutionStrategy.Execute[TResult](Func`1 operation)
bei System.Data.Entity.Core.Objects.ObjectContext.SaveChangesInternal(SaveOptions options, Boolean executeInExistingTransaction)
bei System.Data.Entity.Core.Objects.ObjectContext.SaveChanges(SaveOptions options)
bei System.Data.Entity.Internal.InternalContext.SaveChanges()
InnerException:
Code=1064
ErrorCode=-2147467259
HResult=-2147467259
Message=You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '(SELECT
suppliers_areas.suppliers_id,
suppliers_areas.areas_id
FROM wips.suppli' at line 1
Source=Devart.Data.MySql
SqlState=42000
StackTrace:
bei Devart.Data.MySql.bi.a()
bei Devart.Data.MySql.bi.i()
bei Devart.Data.MySql.af.a(ab[]& A_0, Int32& A_1, Boolean A_2)
bei Devart.Data.MySql.af.a(Byte[] A_0, Int32 A_1, Boolean A_2, String A_3)
bei Devart.Data.MySql.h.e()
bei Devart.Data.MySql.h.m()
bei Devart.Data.MySql.MySqlCommand.InternalExecute(CommandBehavior behavior, IDisposable stmt, Int32 startRecord, Int32 maxRecords)
bei Devart.Common.DbCommandBase.InternalExecute(CommandBehavior behavior, IDisposable stmt, Int32 startRecord, Int32 maxRecords, Boolean nonQuery)
bei Devart.Common.DbCommandBase.ExecuteDbDataReader(CommandBehavior behavior, Boolean nonQuery)
bei Devart.Common.DbCommandBase.ExecuteDbDataReader(CommandBehavior behavior)
bei Devart.Common.DbCommandBase.ExecuteNonQuery()
bei Devart.Data.MySql.Entity.ab.g()
bei System.Data.Entity.Infrastructure.Interception.DbCommandDispatcher.<NonQuery>b__0(DbCommand t, DbCommandInterceptionContext`1 c)
bei System.Data.Entity.Infrastructure.Interception.InternalDispatcher`1.Dispatch[TTarget,TInterceptionContext,TResult](TTarget target, Func`3 operation, TInterceptionContext interceptionContext, Action`3 executing, Action`3 executed)
bei System.Data.Entity.Infrastructure.Interception.DbCommandDispatcher.NonQuery(DbCommand command, DbCommandInterceptionContext interceptionContext)
bei System.Data.Entity.Internal.InterceptableDbCommand.ExecuteNonQuery()
bei System.Data.Entity.Core.Mapping.Update.Internal.DynamicUpdateCommand.Execute(Dictionary`2 identifierValues, List`1 generatedValues)
bei System.Data.Entity.Core.Mapping.Update.Internal.UpdateTranslator.Update()
InnerException: