.NET Core Automapper — Отсутствует конфигурация карты типов или неподдерживаемое сопоставление

#.net-core #automapper

Вопрос:

Я получал сообщение Missing type map configuration or unsupported mapping.nnMapping types:nObject -> UserDtonSystem.Object -> Types.Dto.UserDto в ответе своего сервера. Я пытаюсь сопоставить свой NotificationEntity с моим UserDto и получить идентификатор уведомления из ответа. Вот что я определил до сих пор (опустил некоторые поля для удобства чтения):

 public class UserDto
{
    public Guid? Id { get; set; }
    ...
    public IEnumerable<UserPicDto> UserPics { get; set; }
    public ICollection<UserEmailSettingsDto> UserEmailSettings { get; set; }
    public virtual NotificationEntity Notification { get; set; }
}
 
 public class NotificationEntity : IAuditable
{
    public Guid Id { get; set; }
    ...
    [Required]
    public Guid NotificationGuid { get; set; }
    ...
    public virtual UserEntity User { get; set; }
}
 

AutoMapperProfile.cs

 CreateMap<UserDto, NotificationEntity>()
    // .ForMember(x => x.NotificationGuid, opt => opt.MapFrom(n => n.Notification));
    .ForMember(x => x.NotificationGuid, opt => opt.Ignore());
 

Я вызываю эту функцию на своем контроллере:

 public async Task<UserDto> InviteMember(InviteMemberDto req)
{
    var userDto = _mapper.Map<UserDto>(req);

    using var transaction = new TransactionScope(TransactionScopeAsyncFlowOption.Enabled);

    // create user
    var user = await CreatePendingUserWithRole(userDto); // returns UserEntity

    ...

    // send email
    var notification = await CreateNotificationSendEmail(user, TemplateType.RegistrationMember); // returns NotificationEntity

    transaction.Complete();

    // This line is giving me the errors
    var userWithNotification = _mapper.Map<UserDto>(notification);

    return _mapper.Map<UserDto>(user);
}
 

Не уверен, чего мне здесь не хватает, потому что я думал, что правильно определяю отображение. Какая-нибудь помощь?

Комментарии:

1. Это CreateMap<Source, Destination>() , а не наоборот.