EF Core至Mysql表绑定

时间:2018-11-26 01:33:43

标签: c# mysql .net-core ef-core-2.1

我在MySQL中有下表 enter image description here

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

var apiKeys = _appContext.apikey.ToList();

我收到此错误

  

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; }
}

我在Postgresql数据库上使用了它,然后才移到MySQL。这与从db中的tinyint到类中的bool有关系吗?

我正在使用MySql.Data.EntityFrameworkCore 8.0.13

1 个答案:

答案 0 :(得分:1)

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

  • Pomelo driver支持从布尔到整数的映射,
  • 第二个选项将使用value converters,它与其他驱动程序一起使用。

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

相关问题