EF6+MySQL - Error inserting 2 related objects in a single SaveChanges

entity-framework entity-framework-6 mysql


I am using EF6 and MySql and attepting to insert two new, related objects Client and Quote (where Quote has a Client) in a single call to save changes. This should map to an insert to the the client table and an insert to the quote table. Code is:

        var client = new Client();
        var quote = new Quote();
        quote.Client = client;


Exception is:

Additional information: An error occurred while updating the entries. See the inner exception for details.

   at System.Data.Entity.Internal.InternalContext.SaveChanges()
   at System.Data.Entity.Internal.LazyInternalContext.SaveChanges()
   at System.Data.Entity.DbContext.SaveChanges()
  at MyTestClass... 

Inner Exception is:

{"The specified value is not an instance of a valid constant type.\r\nParameter name: type"}

   at System.Data.Entity.Core.Mapping.Update.Internal.UpdateTranslator.Update()
   at System.Data.Entity.Core.EntityClient.Internal.EntityAdapter.<Update>b__2(UpdateTranslator ut)
   at System.Data.Entity.Core.EntityClient.Internal.EntityAdapter.Update[T](T noChangesResult, Func`2 updateFunction, Boolean throwOnClosedConnection)
   at System.Data.Entity.Core.EntityClient.Internal.EntityAdapter.Update(Boolean throwOnClosedConnection)
   at System.Data.Entity.Core.Objects.ObjectContext.<SaveChangesToStore>b__33()
   at System.Data.Entity.Core.Objects.ObjectContext.ExecuteInTransaction[T](Func`1 func, IDbExecutionStrategy executionStrategy, Boolean startLocalTransaction, Boolean releaseConnectionOnSuccess)
   at System.Data.Entity.Core.Objects.ObjectContext.SaveChangesToStore(SaveOptions options, IDbExecutionStrategy executionStrategy)
   at System.Data.Entity.Core.Objects.ObjectContext.<>c__DisplayClass28.<SaveChanges>b__25()
   at System.Data.Entity.Infrastructure.DefaultExecutionStrategy.Execute[TResult](Func`1 operation)
   at System.Data.Entity.Core.Objects.ObjectContext.SaveChanges(SaveOptions options)
   at System.Data.Entity.Internal.InternalContext.SaveChanges()

Entity classes:

public class Client
    public long Id { get; set; }

public class Quote

    public long Id { get; set; }

    public long ClientId { get; set; }

    public virtual Client Client { get; set; }


  • EF6
  • MySql.Data.dll v6.8.3
  • MySql.Data.Entity.EF6.dll v6.8.3

If I add a db.SaveChanges() after the db.Client.Add(client) line, it will work ok but I want to do a SavChanges as late as possible to to group database calls. Any ideas what could be going wrong?

3/4/2014 6:26:36 AM

Accepted Answer

Problem was due to signed/unsigned bigints as described here.

5/23/2017 10:33:22 AM

Popular Answer

I cannot reproduce this, more details on my test case are available in the http://forums.mysql.com/read.php?38,608603,608603#msg-608603 (where you also posted the question).


Related Questions


Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow