EF Core至Mysql表绑定

Jro*_*row 1 c# mysql .net-core ef-core-2.1

我在MySQL中有下表 在此处输入图片说明

当我在某些中间件中运行以下代码时

var apiKeys = _appContext.apikey.ToList();
Run Code Online (Sandbox Code Playgroud)

我得到这个错误

System.InvalidOperationException:类型'System.Int16'和'System.Boolean'之间没有定义强制运算符。

这是我的ApiKey类

public class ApiKey
{
    public string apikeyid { get; set; }
    public string uid { get; set; }
    public string apikey { get; set; }
    public bool isactive { get; set;}
    public bool ispaid { get; set; }
    public bool ismod { get; set; }
    public bool isadmin { get; set; }
}
Run Code Online (Sandbox Code Playgroud)

我曾与Postgresql db一起工作过,然后才移到MySQL。这与从tinyint(在数据库中)到bool(在类中)有关吗?

我正在使用 MySql.Data.EntityFrameworkCore 8.0.13

小智 8

评论中已经回答了2个可能的选项。

  • Pomelo驱动程序支持bool到int的映射,
  • 第二种选择是使用与其他驱动程序一起使用的值转换器。

    entity.Property(p => p.isActive).HasConversion <int>();