升级版本:

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. css文字的渐变色设置

      background-image: -webkit-linear-gradient( ); //设置颜色与渐变方向   -webkit-background-clip: text; //主要用于剪 ...

  2. css设置全局变量和局部变量

    在我们使用less或者sass时常常会使用到局部变量和全局变量,其实在我们使用css做开发时也可以定义全局变量和局部 变量来简化我们的开发效率,很简单也很实用:1.设置全局变量只需要在我们的根引用的c ...

  3. zubax_gnss移植到STM32F407

    源码下载:https://github.com/Zubax/zubax_gnss.git 源码默认支持STM32F107芯片 STM32 HAL库测试:zubax_gnss\bootloader\zu ...

  4. rabbitmq实战:一、天降奇兵

    缘由,最近换了工作,而新的项目中使用了celery+rabbitmq来实现一个分布式任务队列系统,为了能够维护好这套系统,只能来学习一下这两个组件,顺便把学习笔记记录下来,留作以后回顾,当然如果碰巧能 ...

  5. 导出带图片的Excel——OOXML文件分析

    需求: 普通js导出文件excel具有兼容性问题,通过js-xsl导出文件API未找到导出图片的方案,实例过少,因此针对07年后以.xlsx后缀的excel文件,通过修改后缀.zip参考文件模板来实现 ...

  6. 关于CSDN的一些信息

    CSDN资源共享规范 为广大用户提供资源(包括但不限于文章.文档.音频.视频.图片.课程.软件.源代码等相关资源)共享的网络存储平台 与不得违反国家法律法规相关的规定 不得上传与CSDN提供的服务内容 ...

  7. 私有容器镜像仓库harbor

    私有镜像仓库Harbor 1.Harbor概述 Habor是由VMWare公司开源的容器镜像仓库.事实上,Habor是在Docker Registry上进行了相应的企业级扩展,从而获得了更加广泛的应用 ...

  8. top命令定位CPU高占用代码

    步骤如下: 1.使用top命令定位异常进程.可以看见12836的CPU和内存占用率都非常高 2.使用top -H -p 进程号查看异常线程 3.使用printf "%x\n" 线程 ...

  9. md5 32位小写加密源码

    import java.security.MessageDigest; import java.security.NoSuchAlgorithmException; /** * md5 32位小写加密 ...

  10. MongoDB与Python的交互

    驱动模块 pymongo是python里常用的操作MongoDB的驱动模块 可用pip下载安装 pip install pymongo 创建连接 MongoClient是MongoDB的客户端代理对象 ...