kkost
kkost

Reputation: 3730

Having troubles with TINYINT or BIT types mapping using MySql.Data.EntityFrameworkCore package

I using DB first approach and I trying to create EF models based on existing DB.
I trying to represent boolean type from my column.

First I tried to set is as TINYINT(1) type, then I generating EF model and I see byte type for this column. I tried many approaches to set it to 0 without success. I tried simple assignment =0 to this variable, then I tried to use Convert.ToByte(false) method both of them were without success.

My next step was changing TINYINT(1) to BIT(1) type. Then EF generated short type for my column. I can't assign 0 value via this short type as well.

What is my mistake?

Upvotes: 0

Views: 1308

Answers (2)

kkost
kkost

Reputation: 3730

So, I changed the default value to NULL in MySQL and then EF generated nullable short? type for me. Strange things, but this time mapping works correctly.

Upvotes: 0

Bradley Grainger
Bradley Grainger

Reputation: 28162

It sounds like you're encountering MySQL bug 92987. (See also bug 93028 which is similar.)

Since Oracle hasn't even confirmed those issues, let alone indicated any priority for fixing them, you may want to try switching to Pomelo.EntityFrameworkCore.MySql, an alternate MySQL EF.Core implementation; many people have reported that it's a lot more reliable (e.g., here and here).

Upvotes: 3

Related Questions