3

I have the following mapping:

Mapper.CreateMap<Playlist, PlaylistDto>()
      .ReverseMap()
      .ForMember(playlist => playlist.Folder,
          opt => opt.MapFrom(playlistDto => folderDao.Get(playlistDto.FolderId)));

Which converts a Playlist object to a PlaylistDto object and back. It seemed to work great before I updated AutoMapper.

Now, when I call:

Mapper.AssertConfigurationIsValid();

I see:

Unmapped members were found. Review the types and members below.
Add a custom mapping expression, ignore, add a custom resolver, or modify the source/destination type
=====================================================
PlaylistDto -> Playlist (Source member list)
Streamus.Dto.PlaylistDto -> Streamus.Domain.Playlist (Source member list)
-----------------------------------------------------
FolderId

Playlist and PlaylistDto look like:

[DataContract]
public class PlaylistDto
{
    [DataMember(Name = "id")]
    public Guid Id { get; set; }

    [DataMember(Name = "title")]
    public string Title { get; set; }

    [DataMember(Name = "folderId")]
    public Guid FolderId { get; set; }

    [DataMember(Name = "items")]
    public List<PlaylistItemDto> Items { get; set; }

    [DataMember(Name = "sequence")]
    public int Sequence { get; set; }

    public PlaylistDto()
    {
        Id = Guid.Empty;
        Title = string.Empty;
        Items = new List<PlaylistItemDto>();
    }

    public static PlaylistDto Create(Playlist playlist)
    {
        PlaylistDto playlistDto = Mapper.Map<Playlist, PlaylistDto>(playlist);
        return playlistDto;
    }
}

public class Playlist : AbstractShareableDomainEntity
{
    public virtual Folder Folder { get; set; }
    //  Use interfaces so NHibernate can inject with its own collection implementation.
    public virtual ICollection<PlaylistItem> Items { get; set; }
    public virtual int Sequence { get; set; }

    public Playlist()
    {
        Id = Guid.Empty;
        Title = string.Empty;
        Items = new List<PlaylistItem>();
        Sequence = -1;
    }
}

Why is AutoMapper unable to automatically derive the FolderId from Folder after updating?

Note that it still complains even if I try to explicitly define the mapping to FolderId:

Mapper.CreateMap<Playlist, PlaylistDto>()
       .ForMember(playlist => playlist.FolderId,
            opt => opt.MapFrom(playlistDto => playlistDto.Folder.Id))
      .ReverseMap()
      .ForMember(playlist => playlist.Folder,
            opt => opt.MapFrom(playlistDto => folderDao.Get(playlistDto.FolderId)));
Sean Anderson
  • 27,963
  • 30
  • 126
  • 237

1 Answers1

1

The answer was to explicitly declare my mappings:

Mapper.CreateMap<Playlist, PlaylistDto>();
Mapper.CreateMap<PlaylistDto, Playlist>()
    .ForMember(playlist => playlist.Folder,opt => opt.MapFrom(playlistDto => folderDao.Get(playlistDto.FolderId)));
Sean Anderson
  • 27,963
  • 30
  • 126
  • 237