2017-08-15 172 views
0

我有一个测试,要求Mapper.ConfigurationProvider.AssertConfigurationIsValid();AutoMapper抛出AutoMapperConfigurationException的一个映射,但不是另一个

我得到一个AutoMapperConfigurationException当我尝试了IReadOnlyCollection映射到List,但只有我第二次尝试这样做。

我在AutoMapper版本6.0.2上。编辑:我运行在最新版本6.1.1,仍然有这个错误。

我有4个班。

  • FooRow
  • Foo
  • BarRow
  • Bar

我有以下的映射。

  1. CreateMap<FooRow, Foo>
  2. CreateMap<IReadOnlyCollection<FooRow>, List<Foo>>
  3. CreateMap<BarRow, Bar>
  4. CreateMap<IReadOnlyCollection<BarRow>, List<Bar>>

只有#4失败。我收到了错误Unmapped properties: Capacity。现在,显然#4我可以添加.ForMember(d => d.Capacity, o => o.Ignore)但是我更感兴趣的是我必须为Bar而不是Foo做第二次映射。

+0

作为一个说明,我知道那有#1和#3足以让测绘工作,也许我在上面做的只是错误的? – Questioning

回答

2

这可能是值得尝试删除的集合映射,因为AutoMapper已经内置了对数组和列表支持:

https://github.com/AutoMapper/AutoMapper/wiki/Lists-and-arrays

+0

上面的链接将指向[Automapper的Github主页](https://github.com/AutoMapper/AutoMapper)。尝试使用此链接http://automapper.readthedocs.io/en/latest/Lists-and-arrays.html – HExit

相关问题