【发布时间】:2019-02-22 22:16:01
【问题描述】:
我正在尝试将 Superhero 模型自动映射到 Supervillan 模型,每个模型都有类似的字典声明:
超级英雄:
public class Superheroes {
public Dictionary<string, SomeHero>> SuperNumber {get; set;}
}
public class SomeHero {
// unique properties
}
超级反派:
public class Supervillans {
public Dictionary<string, SomeVillan>> SuperNumber {get; set;}
}
public class SomeVillan {
// unique properties
}
我尝试按照其他类似主题中的建议进行操作,但没有成功。这是我最新的尝试,但执行失败:
CreateMap<KeyValuePair<string, Superheroes>, KeyValuePair<string, Supervillans>>();
如何将我的 Superhero SuperNumber 字典映射到我的 Supervillan SuperNumber 字典?
注意:SomeHero/SomeVillan 模型将具有独特的属性,但我不关心这个问题。
【问题讨论】:
-
您还需要来自
SuperheroesSupervillans的映射来定义其转换方式 -
您可能应该考虑升级您的 Automapper 版本,我相信这已在版本 6+ Example 中得到修复。
-
感谢@ErikPhilips 的示例,我会检查我的版本。
标签: c# dictionary automapper