automapper-3

Automapper: passing parameter to Map method

与世无争的帅哥 提交于 2019-12-03 01:09:30
I'm using Automapper in a project and I need to dynamically valorize a field of my destination object. In my configuration I have something similar: cfg.CreateMap<Message, MessageDto>() // ... .ForMember(dest => dest.Timestamp, opt => opt.MapFrom(src => src.SentTime.AddMinutes(someValue))) //... ; The someValue in the configuration code is a parameter that I need to pass at runtime to the mapper and is not a field of the source object. Is there a way to achieve this? Something like this: Mapper.Map<MessageDto>(msg, someValue)); You can't do exactly what you want, but you can get pretty close

AutoMapper.Mapper.CreateMap<TSource,TDestination>()' is obsolete

女生的网名这么多〃 提交于 2019-11-30 08:32:27
I have to classes Like class A { public int id {get; set;} } class B { public C c {get; set;} } class C { public int id {get; set;} public string Name {get; set;} } My requirement is to map id of class A to id of class C. Now what I was doing till now was: Mapper.CreateMap().ForMember(des => des.C.Id, src => src.MapFrom(x => x.id)); and it was working fine. Now seems like Auto mapper has changed their implementation. and I am getting warning as below: AutoMapper.Mapper.CreateMap()' is obsolete: 'Dynamically creating maps will be removed in version 5.0. Use a MapperConfiguration instance and