当我在一些中间件中运行以下代码时
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/53473726/