开发者

AutoMapper Sorting List

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))
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜