automapperautomapper-2automapper-3

AutoMapper DataServiceCollection to List<string>


I am attempted to use AutoMapper to map a DataServiceCollection to a list of strings and also create the reverse mapping. Any ideas on how to map a specialized collection like this to another?

Mapper.CreateMap<DataServiceCollection<LocationCountyValue>, List<string>>();

Solution

  • Thanks to Thiago Sa I created the mapping in both directions like so:

    Mapper.CreateMap<DataServiceCollection<CountyValue>, List<string>>()
        .ConvertUsing((src) => { return src.Select(c => c.Value).ToList(); });
    
    Mapper.CreateMap<List<string>, DataServiceCollection<CountyValue>>()
        .ConvertUsing((src) =>
        {
            return new DataServiceCollection<CountyValue>(
                src.Select(c => new CountyValue() { Value = c }));
        });