Bug #95533 dotnet core 2.1 doesn't support bool type property
Submitted: 27 May 2019 4:47 Modified: 5 Jul 2019 3:33
Reporter: Mirolimjon Majidov Email Updates:
Status: Verified Impact on me:
Category:Connector / NET Severity:S3 (Non-critical)
Version:8.0.16 OS:Microsoft Windows
Assigned to: CPU Architecture:Any
Tags: BOOL, EF Core, MySQL

[27 May 2019 4:47] Mirolimjon Majidov
Hi, I have problem with using bool property in entity after updating .net core v2.0 to new version. It's working will till .net core 2.0 version and with SQL server:

  Message=The binary operator Equal is not defined for the types 'System.Boolean' and 'System.Int16'.
   at Microsoft.EntityFrameworkCore.Metadata.Internal.ClrAccessorFactory`1.Create(PropertyInfo propertyInfo, IPropertyBase propertyBase)
   at Microsoft.EntityFrameworkCore.Internal.NonCapturingLazyInitializer.EnsureInitialized[TParam,TValue](TValue& target, TParam param, Func`2 valueFactory)
   at Microsoft.EntityFrameworkCore.ChangeTracking.Internal.InternalEntityEntry.ReadPropertyValue(IPropertyBase propertyBase)
   at Microsoft.EntityFrameworkCore.ChangeTracking.Internal.ChangeDetector.DetectChanges(InternalEntityEntry entry)
   at Microsoft.EntityFrameworkCore.ChangeTracking.Internal.ChangeDetector.DetectChanges(IStateManager stateManager)
   at Microsoft.EntityFrameworkCore.DbContext.SaveChanges(Boolean acceptAllChangesOnSuccess)
   at EFCoreWithMySQL.Program.Main(String[] args) in C:\Users\mirolim\Desktop\EFCoreWithMySQL\EFCoreWithMySQL\Program.cs:line 17

How to repeat:
You can reproduce it with sample app:

Create console app with dotnet core 2.1 and install 'MySql.Data.EntityFrameworkCore 8.0.16'. Than create "AppContext" and "User" files: 

Add this code to AppContext file:
public class AppContext : DbContext
        public DbSet<User> Users { get; set; }

        public AppContext()

        protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
            optionsBuilder.UseMySQL("server=localhost; database=appdb; user=root;");

Code of User file: 

public class User
        public int Id { get; set; }
        public string Name { get; set; }
        public int Age { get; set; }
        public bool Status { get; set; }

Code of Program file:

class Program
        static void Main(string[] args)
            using (AppContext db = new AppContext())
                User user1 = new User { Name = "Tom", Age = 33 };
                User user2 = new User { Name = "Alice", Age = 26 };

                Console.WriteLine("Saved all users");

                var users = db.Users.ToList();
                Console.WriteLine("List of users:");
                foreach (User u in users)
                    Console.WriteLine($"{u.Id}.{u.Name} - {u.Age}");

Suggested fix:
New version of dotnet  core (> 2.0) doesn't support bool type property in entity.  It's working will when we use  .net core 2.0 or SQL server.
[27 May 2019 10:01] MySQL Verification Team
Hello Mirolimjon Majidov,

Thank you for the report and test.
Verified as described with VS 2019, C/NET 8.0.16 on Win10.

[28 May 2019 4:02] Bradley Grainger
Possible duplicate of bug #92987 or bug #93028.
[6 Jun 2019 14:36] Paul Voelker
I seem to be running into this as well.  Though the issue for me is materializing when I try to generate a migration when using 'HasData' on a table with a boolean (bit) column.  I tried upgrading to .NET Core 2.2 with the latest EF Core.  Problem still seems to exists.

Is sticking with .NET Core 2.0 still the only viable workaround for this?
[6 Jun 2019 14:49] Paul Voelker
Just tried downgrading to .NET Core 2.0.  Still see the issue.

Do I need to downgrade to .NET Core 1.X?
[10 Jun 2019 17:21] Bradley Grainger
There is an alternative OSS EF.Core library for EFCore 2.2: https://www.nuget.org/packages/Pomelo.EntityFrameworkCore.MySql

It might be worth trying that as a workaround in the meantime until Oracle can resolve this?
[5 Jul 2019 3:33] Mirolimjon Majidov
This problem has not fixed yet, but If you have a problem with this issue you can use property type or another NuGet:
1. Attaching property type to property of an entity. Example:

public class User
        public int Id { get; set; }
        public string Name { get; set; }
        public int Age { get; set; }

        [Column(TypeName = "bit")]
        public bool Status { get; set; }

2. Or you can use Pomelo.EntityFrameworkCore.MySql without any problem.