繁体   English   中英

EF Core至Mysql表绑定

[英]EF Core to Mysql table binding

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

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

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 db一起工作过,然后才移到MySQL。 这与从tinyint(在数据库中)到bool(在类中)有关吗?

我正在使用MySql.Data.EntityFrameworkCore 8.0.13

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

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

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM