[英]Error when trying to Map List using Automapper
我需要使用Automapper
將 map IReadOnlyList<Person>
到IReadOnlyList<PersonResponse>
。
IReadOnlyList<Person> personList = await _personRespository.getall();
var t = MyMapper.Mapper.Map<IReadOnlyList<PersonResponse>>(personList );
映射 Class
CreateMap<IReadOnlyList<PersonResponse>, IReadOnlyList<Person>>().ReverseMap();
我得到的錯誤:
System.TypeLoadException:“Proxy_System.Collections.Generic.IReadOnlyList`1[[App.Application.Responses.PersonResponse, App.Application, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null]] 類型中的方法 'get_Item' 34471389 ' 來自程序集 'AutoMapper.Proxies, Version=0.0.0.0, Culture=neutral, PublicKeyToken=be96cd2c38ef1005' 沒有實現。 在 System.Reflection.Emit.TypeBuilder.CreateTypeNoLock() 在 System.Reflection.Emit.TypeBuilder.CreateTypeInfo()
創建Person
和PersonResponse
(相關元素類型)之間的映射。 Automapper 會自己處理 collections。
CreateMap<PersonResponse, Person>().ReverseMap();
您可以在此處閱讀更多 Automapper 和 Collections
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.