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 ...
随机推荐
- matlab之plot()函数
是个画图函数: 语法: figure(1000);hold on;plot(x,y);axis equal; 其中,x和y是某两个长度相同的列向量.比如:x=[1;2;3;4];y=[1;2;3;4] ...
- SENet(Squeeze-and-Excitation Networks)算法笔记---通过学习的方式来自动获取到每个特征通道的重要程度,然后依照这个重要程度去提升有用的特征并抑制对当前任务用处不大的特征
Momenta详解ImageNet 2017夺冠架构SENet 转自机器之心专栏 作者:胡杰 本届 CVPR 2017大会上出现了很多值得关注的精彩论文,国内自动驾驶创业公司 Momenta 联合机器 ...
- 疑难杂症:“代理 XP”组件已作为此服务器安全配置的一部分被关闭。系统管理员可以使用 sp_configure 来启用“代理 XP”。
“代理 XP”组件已作为此服务器安全配置的一部分被关闭.系统管理员可以使用 sp_configure 来启用“代理 XP”.有关启用“代理 XP”的详细信息,请参阅 SQL Server 联机丛书中的 ...
- str_2.判断两个字符串是否互为旋转词
1. 字符串str的前面任意部分挪到后面形成的字符串叫做字符串str的旋转词 $str1 = "2ab1"; $str2 = "ab12"; $ret = is ...
- leetcode 303. Range Sum Query - Immutable(前缀和)
Given an integer array nums, find the sum of the elements between indices i and j (i ≤ j), inclusive ...
- Codeforces Round #394 (Div. 2) 题解
无需吟唱,直接传送 problem A 题目大意 已知有n个偶数,m个奇数,问这些数有没有可能组成一个严格递增1的序列 题解 判断abs(n,m) <= 1即可,注意n,m均为0的情况. Cod ...
- 【Lintcode】112.Remove Duplicates from Sorted List
题目: Given a sorted linked list, delete all duplicates such that each element appear only once. Examp ...
- 如何加快建 index 索引 的时间
朋友在500w的表上建索引,半个小时都没有结束.所以就讨论如何提速. 一.先来看一下创建索引要做哪些操作:1. 把index key的data 读到内存==>如果data 没在db_cache ...
- DataGridColum的bug
Datagrid有多个bug: 1,不支持DynamicResource的东西 2, 在Column隐藏后再显示, ColumnHeader的Tag或者DataContext为null. 解决办法: ...
- AR/VR-VR-Info-Micron-Insight:虚拟现实开辟心理健康新途径
ylbtech-AR/VR-VR-Info-Micron-Insight:虚拟现实开辟心理健康新途径 1.返回顶部 1. 虚拟现实开辟心理健康新途径 全国心理疾病联盟最近发表的一份报告揭示了惊人的统计 ...