Dictionary map to an object using Automapper

前端 未结 6 556
执笔经年
执笔经年 2020-11-29 07:50

Below code is just for this question

I am having a class like

public User class
{
 public string Name{get;set;}
 public string Age{get;set;
}
         


        
6条回答
  •  甜味超标
    2020-11-29 08:03

    Much simpler solution. Just map your object from KeyValuePair. Example:

    CreateMap, User>()
                .ForMember(u => u.Id, src => src.MapFrom(x => x.Key))
                .ForMember(u => u.Name, src => src.MapFrom(x => x.Value));
    

提交回复
热议问题