简体   繁体   English

尝试使用 Automapper 列出 Map 时出错

[英]Error when trying to Map List using Automapper

I need to map IReadOnlyList<Person> to IReadOnlyList<PersonResponse> using Automapper .我需要使用Automapper将 map IReadOnlyList<Person>IReadOnlyList<PersonResponse>

IReadOnlyList<Person> personList = await _personRespository.getall();

var t = MyMapper.Mapper.Map<IReadOnlyList<PersonResponse>>(personList );

Mapping Class映射 Class

CreateMap<IReadOnlyList<PersonResponse>, IReadOnlyList<Person>>().ReverseMap();

The error I get:我得到的错误:

System.TypeLoadException: Method 'get_Item' in type 'Proxy_System.Collections.Generic.IReadOnlyList`1[[App.Application.Responses.PersonResponse, App.Application, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null]] 34471389 ' from assembly 'AutoMapper.Proxies, Version=0.0.0.0, Culture=neutral, PublicKeyToken=be96cd2c38ef1005' does not have an implementation. 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' 没有实现。 at System.Reflection.Emit.TypeBuilder.CreateTypeNoLock() at System.Reflection.Emit.TypeBuilder.CreateTypeInfo()在 System.Reflection.Emit.TypeBuilder.CreateTypeNoLock() 在 System.Reflection.Emit.TypeBuilder.CreateTypeInfo()

Create an mapping between Person and PersonResponse , the concerned element types.创建PersonPersonResponse (相关元素类型)之间的映射。 Automapper would take care of collections themselves. Automapper 会自己处理 collections。

CreateMap<PersonResponse, Person>().ReverseMap();

You can read more Automapper and Collections here您可以在此处阅读更多 Automapper 和 Collections

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM