Home > Back-end >  How to map Object Property to string with Automapper in Asp.Net Core
How to map Object Property to string with Automapper in Asp.Net Core

Time:11-26

I have an Object and need to select the Name property and assign it to String.

but it doesn't work!

who to write true Profiles mapping

class Tag
{ 
      public string Name {get;set;}
}
public class TagProfile : ProfileBase
{
    public TagProfile()
    {
        CreateMap<Tag, string>()
          .ForMember(dest => dest, opt => opt.MapFrom(src => src.Name));
    }
}

CodePudding user response:

you can try it on profile contractor:

CreateMap<Tag, string>()
     .ConvertUsing(source => source.Name);
  • Related