Bug #70888 NullReferenceException when try to save entity with TINYINT or BIGINT as PK

Submitted: 12 Nov 2013 11:21 Modified: 14 Dec 2013 0:43
Reporter: Der Meister Email Updates:
Status: Closed Impact on me:
None 
Category:Connector / NET Severity:S1 (Critical)
Version:6.7.4 OS:Windows (7 x64)
Assigned to: Fernando Gonzalez.Sanchez CPU Architecture:Any
Tags: BIGINT, exception, NullReferenceException, Tinyint, UNSIGNED

[12 Nov 2013 11:21] Der Meister
Description:
I use MySql.Data.Entities 6.7.4 and try to save an entity into a table with bigint auto-incremented primary key. Connector/Net throws an exception:

System.NullReferenceException: Object reference not set to an instance of an object
   in MySql.Data.Entity.ListFragment.WriteSql(StringBuilder sql)
   in MySql.Data.Entity.SelectStatement.WriteSql(StringBuilder sql)
   in MySql.Data.Entity.InsertStatement.WriteSql(StringBuilder sql)
   in MySql.Data.Entity.SqlFragment.ToString()
   in MySql.Data.Entity.InsertGenerator.GenerateSQL(DbCommandTree tree)
   in MySql.Data.MySqlClient.MySqlProviderServices.CreateDbCommandDefinition(DbProviderManifest providerManifest, DbCommandTree commandTree)
   in System.Data.Common.DbProviderServices.CreateCommandDefinition(DbCommandTree commandTree)
   in System.Data.Common.DbProviderServices.CreateCommand(DbCommandTree commandTree)
   in System.Data.Mapping.Update.Internal.UpdateTranslator.CreateCommand(DbModificationCommandTree commandTree)
   in System.Data.Mapping.Update.Internal.DynamicUpdateCommand.CreateCommand(UpdateTranslator translator, Dictionary`2 identifierValues)
   in System.Data.Mapping.Update.Internal.DynamicUpdateCommand.Execute(UpdateTranslator translator, EntityConnection connection, Dictionary`2 identifierValues, List`1 generatedValues)
   in System.Data.Mapping.Update.Internal.UpdateTranslator.Update(IEntityStateManager stateManager, IEntityAdapter adapter)
   in System.Data.EntityClient.EntityAdapter.Update(IEntityStateManager entityCache)
   in System.Data.Objects.ObjectContext.SaveChanges(SaveOptions options)
   in System.Data.Entity.Internal.InternalContext.SaveChanges()
   in System.Data.Entity.Internal.LazyInternalContext.SaveChanges()
   in System.Data.Entity.DbContext.SaveChanges()

MySql.Data 6.5.4 does not have this bug. I copied sample from SO (http://stackoverflow.com/a/16254132/991267). Oware reproduced the issue in Connector 6.6.5.

How to repeat:
Sample table:

create table person(
    Id tinyint unsigned primary key auto_increment,
    Name varchar(30)
);

Sample code:

var context = new Entities();
Person p;
p = new Person();
p.Name = "Oware";
context.Persons.Add(p);
context.SaveChanges();
[12 Nov 2013 11:23] Der Meister
Possibly linked bug: http://bugs.mysql.com/bug.php?id=70602
[4 Dec 2013 21:04] Fernando Gonzalez.Sanchez
Posted by developer:
 

This fix for this bug will appear in Connector/NET 6.6.7, 6.7.5 and 6.8.2.

With the fix, there is no longer a null reference exception, and the save changes operation is completed correctly.
[14 Dec 2013 0:43] Daniel So
Added the following entry into the Connector/Net 6.6.7, 6.7.5. and 6.8.2 changelogs:

"Connector/Net threw a NullReferenceException when trying to save an entity into a table with a tinyint or bigint auto-incremented primary key."

Portions of this website are copyright © 2001, 2002 The PHP Group

Page generated in 0.055 sec. using MySQL 8.4.7-u6-cloud

Timestamp references displayed by the system are UTC.
Content reproduced on this site is the property of the respective copyright holders.
It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.