Bug #99419 Breaking the natural use of boolean type
Submitted: 2 May 2020 15:55 Modified: 17 Jul 2020 18:20
Reporter: Diego Toro Email Updates:
Status: Closed Impact on me:
None 
Category:Connector / NET Severity:S1 (Critical)
Version:8.0.20 OS:Windows
Assigned to: CPU Architecture:Any
Tags: bit, Entity Framework Core, Tinyint

[2 May 2020 15:55] Diego Toro
Description:
The idea for using TINYINT(1) in table is can checking true/false (boolean type) value in C# code when is scaffolding from table, but the genetared code now is mapped to byte type breaking the natural use of boolean type.

Enviroment:
MySql engine: 8.0.17
.Net Core:  3.1.3
EF Core: 3.1.3
MySql Connector: 8.0.20

How to repeat:
creation database:
CREATE DATABASE ef_core_test
	CHARACTER SET utf8mb4
	COLLATE utf8mb4_0900_ai_ci;

Creation table for testing:
CREATE TABLE test_type_table (
  id INT(11) NOT NULL AUTO_INCREMENT,
  bit_type BIT(1) DEFAULT b'1',
  tinyint_type TINYINT(1) DEFAULT 1,
  varchar_type VARCHAR(255) DEFAULT NULL,
  PRIMARY KEY (id)
)
ENGINE = INNODB,
CHARACTER SET utf8mb4,
COLLATE utf8mb4_0900_ai_ci;

scaffolding command:
dotnet ef dbcontext scaffold "server=localhost;port=3306;user=root;password=Abc123;database=ef_core_test;TreatTinyAsBoolean=true" MySql.Data.EntityFrameworkCore -o ef_core_test -f

C# genetared class 
public partial class TestTypeTable
    {
        public int Id { get; set; }
        public short? BitType { get; set; }
        public byte? TinyintType { get; set; }
        public string VarcharType { get; set; }
    }

Suggested fix:
Expeted result:
public partial class TestTypeTable
    {
        public int Id { get; set; }
        public bool? BitType { get; set; }
        public bol? TinyintType { get; set; }
        public string VarcharType { get; set; }
    }
[2 May 2020 17:09] Diego Toro
Fix data to reproduce:

table script:

CREATE TABLE test_type_table (
  id INT(11) NOT NULL AUTO_INCREMENT,
  bit_type BIT(1) DEFAULT b'1',
  tinyint_type TINYINT(1) DEFAULT 1,
  varchar_type VARCHAR(255) DEFAULT NULL,
  PRIMARY KEY (id)
)
ENGINE = INNODB,
CHARACTER SET utf8mb4,
COLLATE utf8mb4_0900_ai_ci;

C# class genetared
 public partial class TestTypeTable
    {
        public int Id { get; set; }
        public short? BitType { get; set; }
        public byte? TinyintType { get; set; }
        public string VarcharType { get; set; }
    }

Expeted result:
  public partial class TestTypeTable
    {
        public int Id { get; set; }
        public bool? BitType { get; set; }
        public bool? TinyintType { get; set; }
        public string VarcharType { get; set; }
    }
[5 May 2020 15:00] MySQL Verification Team
Thank you for the bug report.
[5 May 2020 22:30] MySQL Verification Team
https://bugs.mysql.com/bug.php?id=94687 marked as duplicate of this one.
[6 May 2020 3:46] Diego Toro
Hi Miguel,

This issue is reported in other uses case, but is not attended, I supplied a simple test case for reproducing it. What is Oracle position about this issue? is it going to be fixed?

thanks
[6 May 2020 8:36] MySQL Verification Team
Hello Diego Toro,

Please allow me to respond here.
Thank you for your interest, your bug has been verified by us already and now it is on developments radar. Please be informed that we cannot give any ETA etc on bug fixes as it is against our policy and hence request you to wait as once Development fixes this issue then you would be notified here. Thank you for your interest in MySQL.

regards,
Umesh
[17 Jul 2020 18:20] Christine Cole
Posted by developer:
 
Fixed as of the upcoming MySQL Connector/NET 8.0.22 release, and here's the proposed changelog entry from the documentation team:

The mapping from the TINYINT and BIT data types to BOOLEAN was not
performed as expected when scaffolding was used.

Thank you for the bug report.