我想在调用 Map 函数时忽略一些映射。
这是我创建地图的地方:
Mapper.CreateMap<User, UserViewModel>()
.ForMember(dest => dest.WebLicenseCount, opt => opt.MapFrom(src => GetCount(src, "0801")))
.ForMember(dest => dest.MobileLicenseCount, opt => opt.MapFrom(src => GetCount(src, "0901")))
.ForMember(dest => dest.ExcelAddInLicenseCount, opt => opt.MapFrom(src => GetCount(src, "0895")))
.ForMember(dest => dest.NextExpirationDate, opt => opt.MapFrom(src => src.Licences.Min(l => l.LicenceProducts.Min(lp => lp.ExpirationDate))))
.ForMember(dest => dest.Licences, opt => opt.MapFrom(src => src.Licences.ToList()))
.ForMember(dest => dest.TicketsCount, opt => opt.MapFrom(src => src.Tickets.Count(t => t.Status != (int)TicketStatusType.Closed)))
.ForMember(dest => dest.ParentContact, opt => opt.MapFrom(src => src.Contact))
.ForMember(dest => dest.ParentUser, opt => opt.MapFrom(src => src.User2))
.ForMember(dest => dest.Contacts, opt => opt.MapFrom(src => src.Contacts))
.ForMember(dest => dest.MainContact, opt => opt.Ignore())
.ForMember(dest => dest.SessionID, opt => opt.Ignore())
;
在我的控制器中,我这样做:
users = Mapper.Map<UserViewModel[]>(response.users);
我想在这个调用中忽略这些属性的映射:WebLicenseCount
、、、MobileLicenseCount
。ExcelAddInLicenseCount
有没有办法做到这一点?