无法映射byte []或byte []? 可空字节[],使用AutoMapper ForCtorParam函数

问题描述

无法映射字节[]或字节[]? (nullable byte [])使用AutoMapper ForCtorParam函数,我得到以下错误消息

AutoMapper.AutoMapperConfigurationException:未映射的成员是 找到了。在下面查看类型和成员。添加自定义映射 表达式,忽略,添加自定义解析器或修改 源/目标类型对于没有匹配的构造函数,请添加一个无参数 ctor,添加可选参数或映射所有构造函数参数 =============================================== ===============================模型->模型Dto(目标成员列表) AutoMapperForCtorParamTest + Model-> AutoMapperForCtorParamTest + ModelDto(目标成员列表)未映射 属性:代码LinkId

在下面重新创建的示例代码

SELECT 
extract (year from order_completed_date) as SalesYear,extract (month from order_completed_date) as SalesMonth,count(case when order_info = 'repeat' then 1 end) as Repeat_cust,count(case when order_info = 'first' then 1 end) as New_cust,count(customer_id) as TotalCust,SUM(case when order_info = 'repeat' then GMV end) as repeat_Sales,SUM(case when order_info = 'first' then GMV end) as new_Sales,SUM(GMV) AS TotalSales
FROM order
where order_completed_date >= '2020-01-01 00:00:00'
GROUP BY salesyear,salesmonth 
ORDER BY salesyear,salesmonth 

注意:

  1. 我正在使用启用了可为空类型的dotnet core 3.1

  2. 我不想使用构造函数或函数转换

  3. 我正在使用Automapper v 10.0.0

解决方法

使用:

.ForCtorParam("text",opt => opt.MapFrom<byte[]?>(src => null));

在我的情况下(字符串)我用:

.ForCtorParam("text",opt => opt.MapFrom<string>(src => null));

相关问答

错误1:Request method ‘DELETE‘ not supported 错误还原:...
错误1:启动docker镜像时报错:Error response from daemon:...
错误1:private field ‘xxx‘ is never assigned 按Alt...
报错如下,通过源不能下载,最后警告pip需升级版本 Requirem...