英文:
AutoMapper - Using ProjectTo method
问题
I am using AutoMapper in my code and I wanna use ProjectTo
for the mappings like this:
var queryable = await _unitOfWork.ProductRepository
.GetList(query);
return new Paging<ProductListDto>
{
Data = queryable.Data.ProjectTo<ProductListDto>(_mapper.ConfigurationProvider).ToList()
};
but I got the following error while using ProjectTo
:
英文:
I am using AutoMapper in my code and I wanna use ProjectTo
for the mappings like this:
var queryable = await _unitOfWork.ProductRepository
.GetList(query);
return new Paging<ProductListDto>
{
Data = queryable.Data.ProjectTo<ProductListDto>(_mapper.ConfigurationProvider).ToList()
};
but I got the following error while using ProjectTo
:
答案1
得分: 2
ProjectTo
方法只支持 IQueryable
,而不支持 IEnumerable
。
你应该使用基本的 _mapper.Map<T>(/* source */)
。
return new Paging<ProductListDto>
{
Data = _mapper.Map<List<ProductListDto>>(queryable.Data)
};
英文:
ProjectTo
method only supports IQueryable
but not IEnumerable
.
You should use the basic _mapper.Map<T>(/* source */)
.
return new Paging<ProductListDto>
{
Data = _mapper.Map<List<ProductListDto>>(queryable.Data)
};
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论