automapper - AutoMapper 10.0.0 with F# - 如何在没有额外映射的情况下修复它?
问题描述
我有 3 种类型:
type [<CLIMutable>] status = { id : Guid; name : string }
type [<CLIMutable>] container = { id : Guid; name : string; status : status}
type [<CLIMutable>] scontainer = { id : Guid; name : string; status : string}
和下一个配置
let c =
MapperConfiguration(
fun config ->
config.CreateMap<container, scontainer>()
.ForMemberFs((fun sc -> sc.name), (fun opts -> opts.MapFrom(fun m _ -> m.status.name))) |> ignore
)
我正在尝试使用下一个代码进行映射
let con = { id = Guid.NewGuid(); name = "Template 1"; container.status = { id = Guid.NewGuid(); name = "Draft" } }
let mapper = c.CreateMapper()
let sc = mapper.Map<scontainer>(con)
但是没有调用成员映射,并且 sc.status 包含状态对象的字符串表示形式(id 和 name 一起)。
当我添加新地图时:
config.CreateMap<status, string>().ConvertUsing(fun s -> s.name) |> ignore
然后 sc.status 包含正确的值。
有谁知道如何在没有额外映射的情况下使其工作?
解决方案
下一行解决了我的问题:
let c =
AutoMapper.MapperConfiguration(
fun config ->
config.ShouldMapProperty <- fun _ -> false
config.ShouldMapField <- fun _ -> true
)
推荐阅读
- docker - 如何将 docker 镜像从 localhost docker 私有注册表拉到 GKE?
- ruby-on-rails - 如何为rails中的特定操作设置带有自定义域的自定义url
- azure - 使用托管标识从逻辑应用调用受 Azure AD 保护的 API
- excel - 从多维度数组中删除行
- java - 找到对集合的共享引用:OneToMany 空集合引用相同的 PersistentBag
- r - 将 dplyr 数据框转换为 R 中的时间序列对象列表
- scala - 如何最小化akka流中的内存使用
- python - 将数据框中的每个单元格除以熊猫中该列的最大值
- spring-boot - 使用 SpringBootDev 的 HttpSecurity
- r - 将 rails 变量传递给 .Rmd 文件以呈现 R 降价