Bug #45175 Wrong SqlType for unsigned smallint when generating Entity Framework Model
Submitted: 28 May 2009 23:16 Modified: 10 Aug 2009 15:27
Reporter: Broken Pipe Email Updates:
Status: Duplicate Impact on me:
None 
Category:Connector / NET Severity:S2 (Serious)
Version:6.0.3 OS:Microsoft Windows (Vista X64)
Assigned to: CPU Architecture:Any

[28 May 2009 23:16] Broken Pipe
Description:
System:
DB MySQL 5.1.32-community 
Net Connector 6.0.3
Visual Studio 2008 SP1
Vista x64
==========================

When creating Entity Model with Entity Framework from DB that contains unsigned smallint columns the model create csdl, ssdl and classes with "short" type but at runtime the entity object contains ushort type.

I haven't checked other unsinged types dunno if the fail to.

How to repeat:
Create simple DB in MySQL with smallint unsinged pk column..

CREATE TABLE `bar` (
  `foo` smallint(5) unsigned NOT NULL,
  PRIMARY KEY (`foo`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
insert  into `bar`(`foo`) values (1);

Create Entity Model for this DB in Visual Studio

            testEntities te = new testEntities();
            var row = te.bar.First();
            te.Detach(row);
            te.Attach(row);

Exception: The type of the key field 'foo' is expected to be 'System.Int16', but the value provided is actually of type 'System.UInt16'.
[28 May 2009 23:24] Broken Pipe
Looks like it's not exactly MySQL bug, EF doesn't support unsigned int types, but still the fix is needed to NET connector to report this columns as normal signed int
[24 Jul 2009 6:53] Tonci Grgin
Hey Broken Pipe and thanks for your report.

Now,        testEntities te = new testEntities();
            var row = te.bar.First(); <<
this row doesn't hold water for me... There is no "bar" offered (however there's "foo" but it can't go "First()").

So please revise your test case and attach something I can work with, will you?
[26 Jul 2009 16:01] Broken Pipe
Have you generated EntityModel?

here is the screenshot of the generated project

http://img263.imageshack.us/img263/537/mysqluin.png
[27 Jul 2009 6:30] Tonci Grgin
Sure I did but let me take a wild guess and say it would have been much more helpful if you've attached your test case instead of image, right?

Please do the following two things:
  o update c/NET to latest version
  o attach your test case so I can try reproducing
[29 Jul 2009 7:30] Broken Pipe
Slightly modified, removed connection string in app.config

Attachment: Mysql_Ent_uint.rar (application/x-compressed, text), 5.40 KiB.

[29 Jul 2009 7:33] Broken Pipe
Attached project file (i have removed connection string in app.config, add your own)
[29 Jul 2009 7:44] Tonci Grgin
Thanks. Even thou connection string can make a world of difference sometimes, I'll check.
[29 Jul 2009 10:03] Tonci Grgin
Well, would be nice to have a name and not to call you "Broken"...

Now, can you please attach test case again, this time with connection string and all (ie. full App.Config used)? I am also wondering why there are no references to MySQL.Data and MySQL.Data.Entity libraries in your project.
[29 Jul 2009 14:50] Broken Pipe
This time with app.config with settings

Attachment: Mysql_Ent_uint_with_config.rar (application/x-compressed, text), 13.10 KiB.

[29 Jul 2009 14:56] Broken Pipe
1) There is no reference to Mysql.Data because i don't refer it anywhere in the code.
DB provider is referred in app.config "provider=MySql.Data.MySqlClient", EF creates connection using Provider Factory, and MySQL is registed as a provider in machine.config file in NET install dir. From machine.config EF finds assembly and load it.

2) Don't forget to edit app.config and change connection settings for you MySQL server
[29 Jul 2009 15:02] Broken Pipe
About my name, you can call me 破裂的導管
-)
[7 Aug 2009 13:00] Tonci Grgin
Thanks Broken (破裂的導管) :-)

Will look into this next week.
[10 Aug 2009 15:27] Reggie Burnett
This is a duplicate of bug #45077