Quantcast
Channel: ASP.NET Core
Viewing all articles
Browse latest Browse all 9386

Automapper Doesnt map a navigation property

$
0
0

Hello guys,

I have a problem with Automapper in particolar with .projectTo that doesnt map the navigation property of attachments, following the code:

var messagesList = dataContext.EmailMessages
                                     .Include(em => em.FromAddresses)
                                     .Include(em => em.ToAddresses)
                                     .Include(em => em.CcAddresses)
                                     .Include(em => em.BccAddresses)
                                     .Include(em => em.Attachments).ThenInclude(at => at.ContentType)
                                     .Include(em => em.MessageFlags)
                                     .Include(em => em.ReplyTo)
                                     .Include(em => em.Uid)
                                     .Include(em => em.References)
                                     .Where(em => em.UserId == userId &&
                                            em.MessageDirection == EmailMessageDirection.received)
                                     .ProjectTo<EmailMessageDto>(new MapperConfiguration(cfg =>
                                     {
                                         cfg.CreateMap<EmailMessage, EmailMessageDto>();
                                         cfg.CreateMap<EmailContentType, EmailContentTypeDto>();
                                         cfg.CreateMap<EmailAttachment, EmailAttachmentDto>();
                                         cfg.CreateMap<EmailHeader, EmailHeaderDto>();
                                         cfg.CreateMap<EmailMessageFlag, EmailMessageFlagDto>();
                                         cfg.CreateMap<EmailUid, EmailUidDto>();
                                         cfg.CreateMap<EmailAddress, EmailAddressDto>();
                                         cfg.CreateMap<EmailMessageId, EmailMessageIdDto>();
                                     }))
                                     .OrderByDynamic(sortField, sortOrder.ToUpper());

When I get the IQueryable List the contentType is everitime null, if I check without Mapping ContentType is there.

I think the configuration of projectTo mapping is not good, some suggestion ?

Thankyou


Viewing all articles
Browse latest Browse all 9386

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>