tags:

views:

69

answers:

2

I have this mapping defined

Mapper.CreateMap<Telephone, TelephoneDTO>()
.ForMember(dto => dto.Extension, opt => opt.MapFrom(src => src.Extension))
.ForMember(dto => dto.Number, opt => opt.MapFrom(src => src.Number))
.ForMember(dto => dto.Type, opt => opt.MapFrom(src => src.TelephoneType.Id));

when i do

IList<TelephoneDTO> dtos = Mapper.Map<IList<Telephone>, IList<TelephoneDTO>>(tels);

i would like the list of TelephoneDTO to be sorted by the Type.

How can i do that ?

thanks

+2  A: 

AutoMapper is used for mapping, not for sorting. You could sort the list once the mapping being done:

IList<TelephoneDTO> dtos = Mapper
    .Map<IList<Telephone>, IList<TelephoneDTO>>(tels)
    .OrderBy(x => x.Type)
    .ToList();
Darin Dimitrov
A: 

or

IList<TelephoneDTO> dtos = Mapper
    .Map<IList<Telephone>, IList<TelephoneDTO>>(tels.OrderBy(x => x.Type))
epitka
good also depending on which collection need to be sorted
mathieu tanguay

related questions