I have this mapping defined
Mapper.CreateMap<Telephone, TelephoneDTO>()
.ForMember(dto => dto.Extension, opt => opt.MapFrom(src => src.Extension))
.ForMember(dto => dto.Number开发者_如何学C, 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
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();
or
IList<TelephoneDTO> dtos = Mapper
.Map<IList<Telephone>, IList<TelephoneDTO>>(tels.OrderBy(x => x.Type))
精彩评论