5

I have a situation where I need to treat TINYINT in a MySQL database as a numeric value and not as TRUE / FALSE.

From what I understand, the MySQL .Net Connector use to map TINYINT as Byte. Unfortunately for me it seems that this is no longer the case and TINYINT is now mapped to Boolean. I need to may TINYINT to Byte like it used to be. I know that the connection string parameter 'Treat Tiny As Boolean=False' is supposed to handle this problem. For some reason this doesn't seem to work when using the Entity Framework. Any ideas?

mlindegarde
  • 395
  • 5
  • 19
  • 1
    Have you tried forcing EF to treat it as the type you want? This may include manually editing the edmx. I've had to do this before butnot with MySql. – Dustin Davis Jul 11 '11 at 22:33
  • I did try forcing the change which didn't work. I also tried editing the edmx; however, I may not have changed it everywhere it needed to be changed. I couldn't find where to edit the edmx file to change the type in the database. – mlindegarde Jul 12 '11 at 15:36

1 Answers1

3

Using the research I had done and DustinDavis's comment I was finally able to come up with a solution to the problem. The trick is to add the 'Treat Tiny As Boolean=False' to the connection string and then to edit the edmx file in bot the "SSDL content" section and the "CSDL content" section.

In the SSDL where you find "bool", replace it with "tinyint" and in the CSDL where you find "Boolean" replace it with "SByte". You can also use "int" and "Int32" if you want; however I believe that MySQL is actually giving you an "SByte". In my situation I was reading data that was entered into the DB via an Access front end which uses -1 / 0 for True / False. This is why I needed the SByte.

mlindegarde
  • 395
  • 5
  • 19
  • 1
    What a pain. Thats why I don't use EF anymore. Just wait until you update the model, you'll lose your changes. – Dustin Davis Jul 12 '11 at 17:14
  • Yeah, that occurred to me. Thankfully it's a fairly simply find a replace option at this point. Maybe I should have gone with NHibernate... – mlindegarde Jul 12 '11 at 20:13