NetCore + Mysql + EF:No coercion operator is defined between types 'System.Int16' and 'System.Boolean',
总结三种解决办法:
1.Mysql升级到7
2.Nuget安装Pomelo.EntityFrameworkCore.MySql 2.2.0替代MySql.Data.EntityFrameworkCore 8.0.16后正常.
PS:如果使用Pomelo库的SQL语句查询Convert.ToDateTime(item["createtime"]).ToString("yyyy-MM-dd HH:mm:ss")会报Unable to cast object of type 'MySql.Data.Types.MySqlDateTime' to type 'System.IConvertible'. 要改成Convert.ToDateTime(item["dskuupdatetime"].ToString()).ToString("yyyy-MM-dd HH:mm:ss").
3.EF上下文添加转换代码
protected override void OnModelCreating(ModelBuilder builder)
{
base.OnModelCreating(builder); foreach (var entityType in builder.Model.GetEntityTypes())
{
foreach (var property in entityType.GetProperties())
{
if (property.ClrType == typeof(bool))
{
property.SetValueConverter(new BoolToIntConverter());
}
}
}
}
public class BoolToIntConverter : ValueConverter<bool, int>
{
public BoolToIntConverter( ConverterMappingHints mappingHints = null)
: base(
v => Convert.ToInt32(v),
v => Convert.ToBoolean(v),
mappingHints)
{
} public static ValueConverterInfo DefaultInfo { get; }
= new ValueConverterInfo(typeof(bool), typeof(int), i => new BoolToIntConverter(i.MappingHints));
}
PS: Linq Any转换失败:
var isExist = db.MyDbTable.Any(o => o.Id == id);
//throw No coercion operator is defined between types 'System.Int16' and 'System.Boolean',
要改成
var isExist = db.MyDbTable.FirstOrDefault(o => o.Id == id) != null;
对于Linq Any有其他解决办法吗?
NetCore + Mysql + EF:No coercion operator is defined between types 'System.Int16' and 'System.Boolean',的更多相关文章
- efcore操作mysql,出现System.InvalidOperationException:“No coercion operator is defined between types 'System.Int16' and 'System.Boolean'.”
这个恶心的问题,只需要把EF的依赖换成 Pomelo.EntityFrameworkCore.MySql 库即可解决
- System.InvalidOperationException:“No coercion operator is defined between types 'System.Int16' and 'System.Boolean'.”
modelBuilder.Entity<MentItems>().Property(e=>e.IsValid) .HasColumnType("bit(1)") ...
- NetCore+MySql+EF 数据库生成实体模型
NetCore版本 2.1 1.点击“工具”->“NuGet包管理器”->“程序包管理器控制台” 分别安装以下几个包 Mysql 版本: MySql.Data.EntityFrame ...
- .NetCore之EF跳过的坑
我在网上看到很多.netCore的信息,就动手自己写一个例子测试哈,但是想不到其中这么多坑: 1.首先.netCore和EF的安装就不用多说了,网上有很多的讲解可以跟着一步一步的下载和安装,但是需要注 ...
- VS2015+MySql EF的配置问题
自己做笔记,防止以后各种找! 去MySql下载最新版的安装包,MySql For Windows全部就可以了,根据开发需求安装功能,然后安装MySql的步骤上网去找一大堆. 注意事项: 第一:必须把V ...
- asp.net core + mysql + ef core + linux
asp.net core + mysql + ef core + linux 以前开发网站是针对windows平台,在iis上部署.由于这次需求的目标服务器是linux系统,就尝试用跨平台的.NET ...
- MySql+EF <二>
C#使用Mysql+EF架构项目有一系列问题. 一.EF没有Mysql的驱动,这个需要自己安装2个插件 ①mysql-connector-net-6.9.10.msi ②mysql-for-visua ...
- .NET Core1.1+VS2017RC+MySQL+EF搭建多层Web应用程序
先贴上解决方案截图 一.新建4个解决方案文件夹 1-Presentation 2-Application 3-Domain 4-Infrastructure 二.在解决方案文件夹中分别创建项目 其余项 ...
- MySQL not equal to operator <> && !=
MySQL :: MySQL 5.7 Reference Manual :: 12.3.2 Comparison Functions and Operatorshttps://dev.mysql.co ...
随机推荐
- 使用vscode写typescript(node.js环境)起手式
动机 一直想把typescript在服务端开发中用起来,主要原因有: javascript很灵活,但记忆力不好的话,的确会让你头疼,看着一月前自己写的代码,一脸茫然. 类型检查有利有敝,但在团队开发中 ...
- consider increasing the maximum size of the cache.
虚拟机上搭建jenkins,出现unable to free [10] percent of the cache for Context [/jenkins] 提示让我加大缓存 consider in ...
- Java里的阻塞队列
JDK7提供了7个阻塞队列,如下: ArrayBlockingQueue : 一个数组结构组成的有界阻塞队列. LinkedBlockingQueue : 一个由链表结构组成的有界阻塞队列 . Pr ...
- BZOJ 3398 [Usaco2009 Feb]Bullcow 牡牛和牝牛:dp【前缀和优化】
题目链接:http://www.lydsy.com/JudgeOnline/problem.php?id=3398 题意: 约翰要带N(1≤N≤100000)只牛去参加集会里的展示活动,这些牛可以是牡 ...
- aop 例子(annotation方式实现)
面向切面编程(也叫面向方面),可以通过预编译方式和运行期动态代理实现在不修改源代码的情况下给程序动态统一添加功能的一种技术.AOP实际是GoF设计模式的延续,设计模式孜孜不倦追求的是调用者和被调用者之 ...
- oracle 11g 常用命令
sqlplus system/123@ORCL; 查看oracle字符集: select * from nls_database_parameters where parameter ='NLS_CH ...
- sangfor-AF 地址转换以及各种模式理解(路由,透明,虚拟网线,混合模式)
目的地址转换: 1.路由其实很简单的,其实你可以理解为路由器就好了2.透明和虚拟网线的区别:虚拟网线不对数据做任何的处理,你可以理解为不封装不拆包,直接丢给对端.而透明不一样,透明你可以把设备当做是交 ...
- chronoy & NTP
同步时间 配置文件中/etc/chrony.conf 里面指定: server master iburst keyfile /etc/chrony.keys commandkey 1 allow al ...
- python--面向对象(最全讲解)
http://www.cnblogs.com/Eva-J/articles/7293890.html 阅读目录 楔子 面向过程vs面向对象 初识面向对象 类的相关知识 对象的相关知识 对象之间的交互 ...
- java.lang.NoClassDefFoundError: org/apache/commons/collections/map/LRUMap 解决方法
转自:https://blog.csdn.net/q664243624/article/details/69221324