我有一张包含消息的票。此外,票证模型包含一个 resolutionMessage,它是可以为空的消息。
我想做这样的事情:
Mapper.CreateMap<Ticket, TicketModel>()
.ForMember(dest => dest.ResolutionMessage, opt => opt.MapFrom(src =>
{
if (src.ResolutionMessageID != null)
{
src.Messages.Where(m => m.MessageID == src.ResolutionMessageID);
}
else
// Return null;
}
));
第二次尝试 :
.ForMember(dest => dest.ResolutionMessage, opt =>
{
(opt.MapFrom(src => if(src.ResolutionMessageID != null)
opt.MapFrom(src => src.Messages.Where(m => m.MessageID == src.ResolutionMessageID));
else
opt => opt.Ignore();
}
);
有任何想法吗?