title: EF6+MySQL - Error inserting 2 related objects in a single SaveChanges
body: <p>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:</p>
  
  <pre><code>        var client = new Client();
          db.Client.Add(client);            
          var quote = new Quote();
          quote.Client = client;
          db.Quote.Add(quote);
  
          db.SaveChanges();
  </code></pre>
  
  <p>Exception is:</p>
  
  <pre><code>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... 
  </code></pre>
  
  <p>Inner Exception is:</p>
  
  <pre><code>{"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.&lt;Update&gt;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.&lt;SaveChangesToStore&gt;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.&lt;&gt;c__DisplayClass28.&lt;SaveChanges&gt;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()
  </code></pre>
  
  <p>Entity classes:</p>
  
  <pre><code>public class Client
  {
      //AUTO_INCREMENT
      [Key]
      public long Id { get; set; }
      ....
  }
  
  public class Quote
  {
  
      //AUTO_INCREMENT
      [Column("id")]
      [Key]
      public long Id { get; set; }
  
      [Column("client")]
      [ForeignKey("Client")]
      public long ClientId { get; set; }
  
      public virtual Client Client { get; set; }
      ...
  }
  </code></pre>
  
  <p>Libraries:</p>
  
  <ul>
  <li>EF6</li>
  <li>MySql.Data.dll v6.8.3</li>
  <li>MySql.Data.Entity.EF6.dll v6.8.3</li>
  </ul>
  
  <p>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?</p>