我在使用AutoMapper时遇到了问题
我的代码:
public static IQueryable<IGrouping<Int64, GroupTimeSheetViewModel>> ToListGroupViewModel(this IQueryable<IGrouping<Int64, GroupTimeSheet>> entity)
{
return Mapper.Map<IQueryable<IGrouping<Int64, GroupTimeSheet>>, IQueryable<IGrouping<Int64, GroupTimeSheetViewModel>>>(entity);
}当我运行我的代码时,我会得到错误:
值"System.Collections.Generic.List
1[PG.Admin.Models.TimeSheetHeaders.GroupTimeSheetViewModel]" is not of type "System.Linq.IGrouping2System.Int64,PG.Admin.Models.TimeSheetHeaders.GroupTimeSheetViewModel“,不能在此泛型集合中使用。参数名称:值
发布于 2015-03-11 02:54:08
AutoMapper不能直接映射查询。如果我是你,我会用AutoMapper的LINQ投影功能。它使用LINQ构建选择投影。这样,您得到的LINQ将类似于:
dbContext.GroupTimeSheets
.GroupBy(ts => ts.Something)
.Project().To<GroupTimeSheetViewModel>()
.ToListAsync();https://stackoverflow.com/questions/27832947
复制相似问题