我正在尝试将一个类型映射UserProfileEditorViewModel
到一个类型UserProfile
,如下所示:
public ActionResult Edit(UserProfileEditorViewModel userProfileViewModel)
{
UserProfile user = _getUserByIdQuery.Invoke(SessionData.UserId);
Mapper.Map(userProfileViewModel, user);
当前抛出此错误:
提供的值是 System.String 类型,但应为 MyNamespace.Web.Models.UserProfileEditorViewModel。
就行了Mapper.Map(userProfileViewModel, user);
。
我的映射配置如下:
Mapper.CreateMap<UserProfileEditorViewModel, UserProfile>()
.ForMember(
dto => dto.Tags,
opt => opt.ResolveUsing<TagNameStringToTagCollectionResolver>());
TagNameStringToTagCollectionResolver
看起来像:
protected override IEnumerable<Tag> ResolveCore(string source)
{
return _getTagsByNamesQuery.Invoke(source.Split(','));
}
有什么想法为什么会抛出该异常?我是 Automapper 的新手,有点难过。