2
我有以下映射:更新AutoMapper現在接收映射的財產除外
Mapper.CreateMap<Playlist, PlaylistDto>()
.ReverseMap()
.ForMember(playlist => playlist.Folder,
opt => opt.MapFrom(playlistDto => folderDao.Get(playlistDto.FolderId)));
其中一個播放列表對象轉換爲PlaylistDto對象和背部。在我更新AutoMapper之前,它似乎工作得很好。
現在,當我打電話:
Mapper.AssertConfigurationIsValid();
我看到:
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
播放列表和PlaylistDto樣子:
[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;
}
}
爲什麼AutoMapper無法自動導出FolderId更新後的文件夾?
注意,它仍然抱怨,即使我嘗試顯式定義映射到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)));
當你明確地映射'FolderId '..錯誤是完全一樣的嗎? –
是的,當我明確地映射它時收到相同的錯誤。奇怪,對吧? –
這是一個ASP.NET應用程序嗎?我假設你在Application_Start/Global.asax中初始化AutoMapper是嗎?您是否嘗試徹底重新啓動本地Web服務器/關閉Visual Studio並重新打開? –