I have two classes
public class SourceClass
{
public Guid Id { get; set; }
public string Provider { get; set; }
}
public class DestinationClass
{
public Guid Id { get; set; }
public List<string> Provider { get; set; }
}
I've initialized my mapping by using the following code
CreateMap<SourceClass, DestinationClass>();
And then in my controller, I have :
Mapper.Map<List<DestinationClass>>(requests)
where "requests" is a List of SourceClass objects being passed in to my controller.
My question is, how can I map the Provider(of type string) in my SourceClass to Provider(of type List in my Destination class?
The provider in sourceclass will always be a single string, and provider in the destination class will always be a list of a single string.
Here is what I've tried in the mapping configurations:
CreateMap<SourceClass, DestinationClass>().ForMember(destinationMember => destinationMember.Provider,
memberOptions => memberOptions.MapFrom(src => {
return string.IsNullOrEmpty(src.Provider) ? [""] : src.Provider.ToList());