title: Entity Framework 5 + MySQL.Data 6.6.4.0 causes NullReferenceException on data insert
body: <p>I am using Entity Framework with MySQL and it's giving me a NullReferenceException every time I try to insert data. </p>
  
  <ul>
  <li>I can insert data directly by creating a command but when I use Entity Framework it bombs out.</li>
  <li>Entity Framework will select from tables or update tables so perhaps this is something to do with the primary key</li>
  </ul>
  
  <p>The following exception is thrown from the SaveChanges() method.</p>
  
  <pre><code>
  failed: System.NullReferenceException : Object reference not set to an instance of an object.
      at MySql.Data.Entity.ListFragment.WriteSql(StringBuilder sql)
      at MySql.Data.Entity.SelectStatement.WriteSql(StringBuilder sql)
      at MySql.Data.Entity.InsertStatement.WriteSql(StringBuilder sql)
      at MySql.Data.Entity.SqlFragment.ToString()
      at MySql.Data.Entity.InsertGenerator.GenerateSQL(DbCommandTree tree)
      at MySql.Data.MySqlClient.MySqlProviderServices.CreateDbCommandDefinition(DbProviderManifest providerManifest, DbCommandTree commandTree)
      at System.Data.Common.DbProviderServices.CreateCommandDefinition(DbCommandTree commandTree)
      at System.Data.Common.DbProviderServices.CreateCommand(DbCommandTree commandTree)
      at System.Data.Mapping.Update.Internal.UpdateTranslator.CreateCommand(DbModificationCommandTree commandTree)
      at System.Data.Mapping.Update.Internal.DynamicUpdateCommand.CreateCommand(UpdateTranslator translator, Dictionary`2 identifierValues)
      at System.Data.Mapping.Update.Internal.DynamicUpdateCommand.Execute(UpdateTranslator translator, EntityConnection connection, Dictionary`2 identifierValues, List`1 generatedValues)
      at System.Data.Mapping.Update.Internal.UpdateTranslator.Update(IEntityStateManager stateManager, IEntityAdapter adapter)
      at System.Data.EntityClient.EntityAdapter.Update(IEntityStateManager entityCache)
      at System.Data.Objects.ObjectContext.SaveChanges(SaveOptions options)
      at System.Data.Objects.ObjectContext.SaveChanges()
  </code></pre>
  
  <p>EF 5</p>
  
  <pre><code>public decimal CreateAlertNotification2(ulong alertServiceId, Alerting.alert_service_notification_type notificationType, string recipientName, string recipientEndpoint)
          {
              using (risk_fleetEntities dbContext = new risk_fleetEntities())
              {
                  var newNotification = new alert_service_notification();
                  newNotification.sys_alert_service_id = alertServiceId;
                  newNotification.name = recipientName;
                  newNotification.notification_type = Enum.GetName(typeof(Alerting.alert_service_notification_type), notificationType);
                  newNotification.recipient = recipientEndpoint;
                  dbContext.alert_service_notification.AddObject(newNotification);
                  dbContext.SaveChanges();
  
                  return newNotification.id;
              }
          }
  </code></pre>
  
  <p>MySQL 5</p>
  
  <pre><code>
  CREATE TABLE `alert_service_notification` (
    `id` bigint(20) unsigned AUTO_INCREMENT PRIMARY KEY, 
    `sys_alert_service_id` bigint(20) unsigned NOT NULL,
    `notification_type` ENUM("SMS", "Email"),
    `name` CHAR(50),
    `recipient` CHAR(50),
    FOREIGN KEY (`sys_alert_service_id`) REFERENCES `alert_service`(`id`) 
  );</code></pre>