Description:
Connector/Net is mapping Entity Framework PrimitiveTypeKind.Byte to "tinyint". This is incorrect because tinyint is a signed type and Byte is an unsigned type. The correct mapping is "utinyint".
Additionally, Connector/Net does not map PrimitiveTypeKind.SByte at all.
How to repeat:
Create a simple Code-First type with a Byte for a field:
public class Dog
{
[Key]
public virtual byte Oops { get; set; }
}
public class DogDBContext : DbContext
{
public DbSet<Dog> Dogs { get; set; }
}
Upon first loading the type, the following exception is generated:
System.Data.MappingException occurred
Message=Schema specified is not valid. Errors:
(7,12) : error 2019: Member Mapping specified is not valid. The type 'Edm.Byte[Nullable=False,DefaultValue=]' of member 'Oops' in type 'MySql.Data.Entity.ModelFirst.Tests.Dog' is not compatible with 'MySql.tinyint[Nullable=False,DefaultValue=]' of member 'Oops' in type 'CodeFirstDatabaseSchema.Dog'.
Source=System.Data.Entity
StackTrace:
at System.Data.Mapping.StorageMappingItemCollection.Init(EdmItemCollection edmCollection, StoreItemCollection storeCollection, IEnumerable`1 xmlReaders, List`1 filePaths, Boolean throwOnError)
at System.Data.Mapping.StorageMappingItemCollection..ctor(EdmItemCollection edmCollection, StoreItemCollection storeCollection, IEnumerable`1 xmlReaders)
at System.Data.Entity.ModelConfiguration.Edm.Db.Mapping.DbDatabaseMappingExtensions.ToStorageMappingItemCollection(DbDatabaseMapping databaseMapping, EdmItemCollection itemCollection, StoreItemCollection storeItemCollection)
at System.Data.Entity.ModelConfiguration.Edm.Db.Mapping.DbDatabaseMappingExtensions.ToMetadataWorkspace(DbDatabaseMapping databaseMapping, Action`1 storeAction)
at System.Data.Entity.Internal.CodeFirstCachedMetadataWorkspace..ctor(DbDatabaseMapping databaseMapping)
at System.Data.Entity.Infrastructure.DbCompiledModel..ctor(DbModel model)
at System.Data.Entity.Infrastructure.DbModel.Compile()
at System.Data.Entity.Internal.LazyInternalContext.CreateModel(LazyInternalContext internalContext)
at System.Data.Entity.Internal.RetryLazy`2.GetValue(TInput input)
at System.Data.Entity.Internal.LazyInternalContext.InitializeContext()
at System.Data.Entity.Internal.InternalContext.Initialize()
at System.Data.Entity.Internal.InternalContext.ExecuteSqlCommand(String sql, Object[] parameters)
at System.Data.Entity.Database.ExecuteSqlCommand(String sql, Object[] parameters)
at D:\Users\optimiz3\Documents\MySql\connectornet\trunk\Tests\MySql.Data.Entity.ModelFirst.Tests\CodeFirstTests.cs:line 69
InnerException:
Suggested fix:
ProviderManifest.cs lines 128-130 need to be changed as follows:
Old:
case PrimitiveTypeKind.Byte:
return TypeUsage.CreateDefaultTypeUsage(StoreTypeNameToStorePrimitiveType["tinyint"]); // ERROR
Fixed:
case PrimitiveTypeKind.SByte:
return TypeUsage.CreateDefaultTypeUsage(StoreTypeNameToStorePrimitiveType["tinyint"]);
case PrimitiveTypeKind.Byte:
return TypeUsage.CreateDefaultTypeUsage(StoreTypeNameToStorePrimitiveType["utinyint"]);
Description: Connector/Net is mapping Entity Framework PrimitiveTypeKind.Byte to "tinyint". This is incorrect because tinyint is a signed type and Byte is an unsigned type. The correct mapping is "utinyint". Additionally, Connector/Net does not map PrimitiveTypeKind.SByte at all. How to repeat: Create a simple Code-First type with a Byte for a field: public class Dog { [Key] public virtual byte Oops { get; set; } } public class DogDBContext : DbContext { public DbSet<Dog> Dogs { get; set; } } Upon first loading the type, the following exception is generated: System.Data.MappingException occurred Message=Schema specified is not valid. Errors: (7,12) : error 2019: Member Mapping specified is not valid. The type 'Edm.Byte[Nullable=False,DefaultValue=]' of member 'Oops' in type 'MySql.Data.Entity.ModelFirst.Tests.Dog' is not compatible with 'MySql.tinyint[Nullable=False,DefaultValue=]' of member 'Oops' in type 'CodeFirstDatabaseSchema.Dog'. Source=System.Data.Entity StackTrace: at System.Data.Mapping.StorageMappingItemCollection.Init(EdmItemCollection edmCollection, StoreItemCollection storeCollection, IEnumerable`1 xmlReaders, List`1 filePaths, Boolean throwOnError) at System.Data.Mapping.StorageMappingItemCollection..ctor(EdmItemCollection edmCollection, StoreItemCollection storeCollection, IEnumerable`1 xmlReaders) at System.Data.Entity.ModelConfiguration.Edm.Db.Mapping.DbDatabaseMappingExtensions.ToStorageMappingItemCollection(DbDatabaseMapping databaseMapping, EdmItemCollection itemCollection, StoreItemCollection storeItemCollection) at System.Data.Entity.ModelConfiguration.Edm.Db.Mapping.DbDatabaseMappingExtensions.ToMetadataWorkspace(DbDatabaseMapping databaseMapping, Action`1 storeAction) at System.Data.Entity.Internal.CodeFirstCachedMetadataWorkspace..ctor(DbDatabaseMapping databaseMapping) at System.Data.Entity.Infrastructure.DbCompiledModel..ctor(DbModel model) at System.Data.Entity.Infrastructure.DbModel.Compile() at System.Data.Entity.Internal.LazyInternalContext.CreateModel(LazyInternalContext internalContext) at System.Data.Entity.Internal.RetryLazy`2.GetValue(TInput input) at System.Data.Entity.Internal.LazyInternalContext.InitializeContext() at System.Data.Entity.Internal.InternalContext.Initialize() at System.Data.Entity.Internal.InternalContext.ExecuteSqlCommand(String sql, Object[] parameters) at System.Data.Entity.Database.ExecuteSqlCommand(String sql, Object[] parameters) at D:\Users\optimiz3\Documents\MySql\connectornet\trunk\Tests\MySql.Data.Entity.ModelFirst.Tests\CodeFirstTests.cs:line 69 InnerException: Suggested fix: ProviderManifest.cs lines 128-130 need to be changed as follows: Old: case PrimitiveTypeKind.Byte: return TypeUsage.CreateDefaultTypeUsage(StoreTypeNameToStorePrimitiveType["tinyint"]); // ERROR Fixed: case PrimitiveTypeKind.SByte: return TypeUsage.CreateDefaultTypeUsage(StoreTypeNameToStorePrimitiveType["tinyint"]); case PrimitiveTypeKind.Byte: return TypeUsage.CreateDefaultTypeUsage(StoreTypeNameToStorePrimitiveType["utinyint"]);