下面的代码给出了这个错误。我最近改用了MongoDb,而不是Ef。看起来,automapper并没有将对象包含在其中,而是一个序列化的表单"{document}“或其他任何东西。无法找到很多关于这一点,也调试了自动代码,但似乎无法弄清楚为什么会发生这种情况。
错误:
表达式树({document})中不支持
GetPartyFullName类型的Application.Read.Common.Helpers.MapHelpers。
var partiesList = await parties
.OrderByDescending(x => x.Created)
.ThenBy(x => x.Name) // this is IOrderedMongoQueryable
//.AsQueryable() => not working either
.ProjectTo<PartyDto>(_mapper.ConfigurationProvider)
.PaginatedListAsync(request.PageNumber, request.PageSize);
映射
... code
profile.CreateMap<Party, PartyDto>()
.ForMember(d => d.FullName, opt => opt.MapFrom(s => MapHelpers.GetPartyFullName(s)));
... more code
任何帮助都将不胜感激。
发布于 2021-03-11 16:12:50
在使用.ProjectTo
扩展时,automapper将将其转换为select
操作。
根据文档:The .ProjectTo<OrderLineDTO>() will tell AutoMapper’s mapping engine to emit a select clause to the IQueryable...
。
因此,很可能mongo查询转换器只是不支持您的MapHelpers.GetPartyFullName
函数。尝试在.MapFrom(...)
调用中直接重写您的映射。
https://stackoverflow.com/questions/66585576
复制相似问题