c# - EF Core 到 Mysql 表绑定(bind)

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

我在 MySQL 中有下表 enter image description here

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

var apiKeys = _appContext.apikey.ToList();

我收到这个错误

System.InvalidOperationException: No coercion operator is defined between types 'System.Int16' and '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。这与从 tinyint(在数据库中)到 bool(在类中)有什么关系吗?

我正在使用 MySql.Data.EntityFrameworkCore 8.0.13

最佳答案

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

  • > Pomelo driver支持 bool 到 int 的映射,
  • 第二个选项是使用 value converters ,它与另一个驱动程序一起工作。

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

关于c# - EF Core 到 Mysql 表绑定(bind),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53743063/

相关文章:

c# - Entity Framework Code First,不同上下文/数据库之间的导航属性

MySQL:计算许多连接表中的项目

php - 从 Facebook 好友获取共同好友(MySQL 表)

c# - 从 ColumnChooser 隐藏列

c# - System.Data.Entity.ModelConfiguration 不存在

mysql - 枚举类型和 MySQL

c# - 用于网络核心的 Tesseract OCR 包装器?

c# - 将数据传递给 startup.cs

c# - 在特定参数不满足要求的情况下限制授权或减少结果

c# - Socket编程多客户端一台服务器