我在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数据库,只是转移到MySQL . 这与从tinyint(在db中)到bool(在类中)有什么关系?
我正在使用 MySql.Data.EntityFrameworkCore 8.0.13
1 回答
已经在评论中回答了2个可能的选项 .
Pomelo driver支持bool到int mapping,
第二个选项是使用value converters,它与另一个驱动程序一起使用 .
entity.Property(p => p.isActive).HasConversion <int>();