它是否映射对象列表?

我有以下Automapper定义:

Mapper.CreateMap<IB.BusinessComponents.Data.LocationMaster, IB.Entites.Master.Location>();
Mapper.CreateMap<IB.BusinessComponents.Data.LocationMaster, IB.Entites.Master.Location>()
    .ForMember(destination => destination.Id, source => source.MapFrom(item => item.LocationMasterID))
    .ForMember(destination => destination.ChildLocationList, source => source.Ignore());

当我映射单个对象时,这工作正常。 但我似乎无法通过对象列表。 在列表中传递时是否需要不同的定义,还是不可能?


在你的AutoMapper定义中:

    CreateMap<MyStuffDTO, MyStuffViewModel>()
        .ForMember(dto => dto.MyDate, opt => opt.MapFrom(src => src.LastDate))
        .ForMember(dto => dto.MyTime, opt => opt.MapFrom(src => src.LastTime))
        .ForMember(dto => dto.Category, opt => opt.MapFrom(src => src.Category));

在代码中:

对于单人:

var result = Mapper.Map<MyStuffDTO, MyStuffViewModel>(obj);

列表:

var list = Mapper.Map<IList<MyStuffDTO>, IList<MyStuffViewModel>>(obj);
链接地址: http://www.djcxy.com/p/6375.html

上一篇: Does it map lists of objects?

下一篇: Merge two objects to produce third using AutoMapper