升级版本:

NetCore sdk 2.2.108 、AspNetCore 2.2.0、EFCore 2.2.6

所有程序引用均从NuGet上下载,并支持NetCore


问题:

问题1:No coercion operator is defined between types 'System.Int16' and 'System.Boolean'(mysql 数据库类型转化中int16 byte bool 转化问题)

解决方案:

引用 Pomelo.EntityFreamworkCore.Mysql 2.2.0 代替 MySql.Data.EntityFrameworkCore

问题2:Error generated for warning 'Microsoft.EntityFrameworkCore.Database.Transaction.AmbientTransactionWarning: An ambient transaction has been detected. The current provider does not support ambient transactions.(环境事务、分布式事务问题)

解决方案:

因为Pomelo.EFCore.Mysql 2.2.0 不支持TransactionScope

所以 采用 using (var scope = DataContextFactory.GetDataContext().Database.BeginTransaction(System.Data.IsolationLevel.RepeatableRead)) 或者

using (var scope = new CommittableTransaction()) 这两种事务代替

问题3:HttpResponseMessage 问题

解决方案:

两个解决方案,建议第一个

1:改为File()返回   2:添加引用 并在startup里注册 services.AddMvc().AddWebApiConventions();

问题4:依赖问题

解决方案:采用Autofac4.9.3 版本支持NetCore 

问题5:模型转换 Model  不支持static 

解决方案:将之前的代码改为第二个里面的 ,并在调用的地方统一 实例化

        public center_flow CenterFlowDto_to_CenterFlow(CenterFlowDto dto)
{
var mapper = CreateMap<CenterFlowDto, center_flow>(); return mapper.Map<CenterFlowDto, center_flow>(dto);
}
/// <summary>
/// 险别列表
/// </summary>
/// <param name="list"></param>
/// <returns></returns>
public List<compensate_insurance> CompensateInsuranceDtoList_to_EntityList(List<CompensateInsuranceDto> list)
{
//var mapper = CreateMap<CompensateAdjustmentDto, compensate_adjustment>();
//return mapper.Map<List<CompensateInsuranceDto>, List<compensate_insurance>>(list); var config = new MapperConfiguration(cfg => { cfg.CreateMap<List<CompensateInsuranceDto>, List<compensate_insurance>>(); });
var mapper = config.CreateMapper(); return mapper.Map<List<CompensateInsuranceDto>, List<compensate_insurance>>(list);
}

 


帮助类:SqlQuery<T>

 public static class DataContextExtend
{
public static List<T> SqlQuery<T>(this DatabaseFacade facade, string sql, params object[] parameters)
{
using (var conn = new MySqlConnection(facade.GetDbConnection().ConnectionString))
{
conn.Open();
var ds = new DataSet();
using (var da = new MySqlDataAdapter(sql, conn.ConnectionString))
{
if (parameters.Any())
{
da.SelectCommand.Parameters.AddRange(parameters);
}
da.Fill(ds);
} conn.Close();
if (ds.Tables.Count > )
{
return ToDataList<T>(ds.Tables[]);
}
else
{
return new List<T>();
}
}
}
/// <summary>
/// 返回首行首列
/// </summary>
/// <typeparam name="T"></typeparam>
/// <param name="facade"></param>
/// <param name="sql"></param>
/// <param name="parameters"></param>
/// <returns></returns>
public static T SqlCount<T>(this DatabaseFacade facade, string sql, params object[] parameters)
{
using (var conn = new MySqlConnection(facade.GetDbConnection().ConnectionString))
{
conn.Open();
T result;
var ds = new DataSet(); using (var commend = new MySqlCommand(sql, conn))
{
if (parameters.Any())
commend.Parameters.AddRange(parameters);
result = (T)commend.ExecuteScalar();
} conn.Close(); return result; } } /// <summary>
/// DataTable转成List
/// </summary>
/// <typeparam name="T"></typeparam>
/// <param name="dt"></param>
/// <returns></returns>
public static List<T> ToDataList<T>(this DataTable dt)
{
var list = new List<T>();
var plist = new List<PropertyInfo>(typeof(T).GetProperties());
if (typeof(T) == typeof(string))
{
foreach (DataRow givenObject in dt.Rows)
{
for (int i = ; i < dt.Columns.Count; i++)
{
if (givenObject[i] != DBNull.Value && givenObject[i] != null)
{
var instance = givenObject[i].ToString(); // Your custom conversion to string.
list.Add((T)(object)instance);
}
else
{
list.Add((T)(object)null);
}
}
}
}
else if (typeof(T).IsClass)
{
foreach (DataRow item in dt.Rows)
{
T s = Activator.CreateInstance<T>();
for (int i = ; i < dt.Columns.Count; i++)
{
PropertyInfo info = plist.Find(p => p.Name.ToUpper() == dt.Columns[i].ColumnName.ToUpper());
if (info != null)
{
try
{
if (!Convert.IsDBNull(item[i]))
{
object v = null;
if (info.PropertyType.ToString().Contains("System.Nullable"))
{
v = Convert.ChangeType(item[i], Nullable.GetUnderlyingType(info.PropertyType));
}
else
{
if (info.PropertyType.BaseType != null && info.PropertyType.BaseType.ToString().Contains("System.Enum"))
{
//将字符串转换为枚举对象
//v = Enum.Parse(info.PropertyType, item[i].ToString());
v = int.Parse(item[i].ToString());
}
else
{
v = Convert.ChangeType(item[i], info.PropertyType);
}
}
info.SetValue(s, v, null);
}
}
catch (Exception ex)
{
throw new Exception("字段[" + info.Name + "]转换出错," + ex.Message);
}
}
}
list.Add(s);
}
}
else if (typeof(T).BaseType == typeof(System.ValueType))
{
try
{
foreach (DataRow item in dt.Rows)
{
for (int i = ; i < dt.Columns.Count; i++)
{
if (item[i] != DBNull.Value && item[i] != null)
{
if (plist.Count > )
{
list.Add((T)((object)Convert.ChangeType(item[i], plist.LastOrDefault()?.PropertyType)));
}
else
{
if (item[i].GetType().ToString() == "System.Int64" && typeof(T).FullName == "System.Int32")
{
list.Add((T)((object)int.Parse(item[i].ToString())));
}
else
{
list.Add((T)((object)item[i]));
}
}
}
else
{
list.Add((T)(object)null);
}
}
}
}
catch (Exception ex)
{
throw new Exception("类型[" + typeof(T) + "]转换出错," + ex.Message);
}
}
return list;
} }

Nuget 引用及版本

帮助类:

Model

Repository

Service

API

.netFramework 升级NetCore 问题汇总及解决方案的更多相关文章

  1. H5项目常见问题汇总及解决方案

    H5项目常见问题汇总及解决方案 H5   2015-12-06 10:15:33 发布 您的评价:       4.5   收藏     4收藏 H5项目常见问题及注意事项 Meta基础知识: H5页 ...

  2. flume常见异常汇总以及解决方案

    flume常见异常汇总以及解决方案 作者:尹正杰 版权声明:原创作品,谢绝转载!否则将追究法律责任. 实际生产环境中,我用flume将kafka的数据定期的往hdfs集群中上传数据,也遇到过一系列的坑 ...

  3. 【转】使用kettle工具遇到的问题汇总及解决方案

    使用kettle工具遇到的问题汇总及解决方案   转载文章版权声明:本文转载,原作者薄海 ,原文网址链接 http://blog.csdn.net/bohai0409/article/details/ ...

  4. H5 常见问题汇总及解决方案

    原文链接:http://mp.weixin.qq.com/s/JVUpsz9QHsNV0_7U-3HCMg H5 项目常见问题汇总及解决方案 -- 由钟平勇分享 转自 https://github.c ...

  5. Android 实现应用升级方案(暨第三方自动升级服务无法使用后的解决方案)

    第三方推送升级服务不再靠谱: 以前在做Android开发的时候,在应用升级方面都是使用的第三方推送升级服务,但是目前因为一些非技术性的问题,一些第三方厂商不再提供自动升级服务,比如友盟,那么当第三方推 ...

  6. H5项目常见问题汇总及解决方案(果断复制粘贴,不解释)

    H5项目常见问题及注意事项 Meta基础知识: H5页面窗口自动调整到设备宽度,并禁止用户缩放页面 //一.HTML页面结构 <meta name="viewport" co ...

  7. 重回程序员之路。重写博客。我的ecshop小京东二开问题汇总与解决方案。

    问题1:混合支付(余额支付+在线支付)不跟更新订单状态问题. 解决方案:http://bbs.ecshop.com/viewthread.php?tid=156761&highlight= i ...

  8. linux中python环境搭建及升级后yum不可用解决方案

    1.1 LinuxCentOS 为例.1.1.1 升级 Python(1) 下载 Python 版本$ wget https://www.python.org/ftp/python/2.7.11/Py ...

  9. C#版微信公众号支付|微信H5支付|微信扫码支付问题汇总及解决方案总结

    最近负责的一些项目开发,都用到了微信支付(微信公众号支付.微信H5支付.微信扫码支付).在开发的过程中,在调试支付的过程中,或多或少都遇到了一些问题,今天总结下,分享,留存.代码在文章结尾处,有需要的 ...

随机推荐

  1. 前端 JS 获取 Image 图像 宽高 尺寸

    前端 JS 获取 Image 图像 宽高 尺寸 简介 项目中用到获取图片的原始尺寸,然后适配宽高:网上的大部分前端解决方案,都是new Image()后,在onload事件中获取image的尺寸. 在 ...

  2. IOS 之 NSBundle 使用

    来源:http://blog.sina.com.cn/s/blog_b0c59541010151rd.html An NSBundle object represents a location in ...

  3. 部署---Apache服务器安装SSL证书

    在云服务器的证书控制台下载Apache版本证书,下载到本地的是一个压缩文件. 解压后里面包含: _public.crt文件是证书文件, _chain.crt是证书链(中间证书)文件, .key文件是证 ...

  4. kubeadm添加新master或node

    一.首先在master上生成新的token kubeadm token create --print-join-command [root@cn-hongkong nfs]# kubeadm toke ...

  5. Redis主从同步之主库挂死解决方案

    Redis实现了主从同步,但是主库挂死了,如何处理 方案:切换主库的身份 # 连接从库 [root@localhost redis-]# redis-cli -p # 取消从库身份 > slav ...

  6. Java精通并发-透过openjdk源码分析wait与notify方法的本地实现

    上一次https://www.cnblogs.com/webor2006/p/11442551.html中通过openjdk从c++的底层来审视了ObjectMonitor的底层实现,这次继续来探究底 ...

  7. #《你们都是魔鬼吗》第八次团队作业:第五天Alpha冲刺

    <你们都是魔鬼吗>第八次团队作业:Alpha冲刺 项目 内容 这个作业属于哪个课程 任课教师博客主页链接 这个作业的要求在哪里 作业链接地址 团队名称 你们都是魔鬼吗 作业学习目标 完成最 ...

  8. 《少年先疯队》第八次团队作业:Alpha冲刺第二天

    前言   第一天冲刺会议   时间:2019.6.15   地点:宿舍 2.1 今日完成任务情况以及遇到的问题.   2.1.1今日完成任务情况 姚玉婷:房间信息管理功能的实现,如房间的显示, 马丽莎 ...

  9. java通过url读取网络图片

    使用java.net读取网络文件 import java.io.BufferedInputStream; import java.io.FileOutputStream; import java.io ...

  10. 【C语言基础】编码规范

    from:程序员互动联盟 2016-12-28 1. 基本要求  1.1 程序结构清析,简单易懂,单个函数的程序行数不得超过100行.  1.2 打算干什么,要简单,直接了当,代码精简,避免垃圾程序. ...