C# Automapper ASP.NET核心映射自定义泛型类型错误
我有自己的泛型类型:C# Automapper ASP.NET核心映射自定义泛型类型错误,c#,asp.net,asp.net-core,automapper,C#,Asp.net,Asp.net Core,Automapper,我有自己的泛型类型:PagedList,它负责从存储库中获取查询并返回后的分页,例如PagedList到服务,我的服务应该返回PagedList。所以我尝试映射:return\u mapper.map(userList)这就是我得到的: ArgumentException: App.Core.Paging.PagedList`1[App.Infrastructure.DTO.UserDTO] needs to have a constructor with 0 args or only op
PagedList
,它负责从存储库中获取查询并返回后的分页,例如PagedList
到服务,我的服务应该返回PagedList
。所以我尝试映射:return\u mapper.map(userList)代码>这就是我得到的:
ArgumentException:
App.Core.Paging.PagedList`1[App.Infrastructure.DTO.UserDTO] needs to have a
constructor with 0 args or only optional args.
Parameter name: type
lambda_method(Closure , PagedList<User> , PagedList<UserDTO> ,
ResolutionContext )
AutoMapperMappingException: Error mapping types.
ArgumentException:
App.Core.Paging.PagedList`1[App.Infrastructure.DTO.UserDTO]需要具有
具有0个参数或仅可选参数的构造函数。
参数名称:类型
lambda_方法(闭包、页面列表、页面列表、,
决议(上下文)
AutoMappingException:映射类型错误。
在我的映射器配置中:
cfg.CreateMap()代码>
这足够了还是我遗漏了什么?这两个类中的属性相同。错误消息告诉您确切的问题:PagedList
类需要AutoMapper可以使用的构造函数。最简单的选项是向类添加空构造函数:
public class PagedList<T>
{
//Add this:
public PagedList() { }
}
公共类页面列表
{
//添加以下内容:
公共页面列表(){}
}
但是,您需要确定这是否适合您的情况。错误告诉您问题所在,UserDTO
是否有可用的构造函数?事实上,我应该说PagedList
。@DavidG oh我在PagedList中创建了空构造函数,并且在搜索User/UserDTO的整个过程中它都起作用。谢谢