2017-08-15 43 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

相關問題