开发者

Add another propertymapping? (AutoMapper)

Can you

  Mapper.CreateMap<Foo, Bar>() 
        .ForMember(x => x.IsFoo, x => x.Ignore());

and then later on add another mapping of 开发者_如何学Gothe sort

  .ForMember(x => x.IsBar, x => x.Ignore());

or even change the old one

  .ForMember(x => x.IsFor, x => x.MapFrom(z => z.IsBar));

? If so, how?


No you can't. Mappings in AutoMapper are defined only once per application domain preferably in your application initialization method. Quote from the documentation:

If you're using the static Mapper method, configuration only needs to happen once per AppDomain. That means the best place to put the configuration code is in application startup, such as the Global.asax file for ASP.NET applications. Typically, the configuration bootstrapper class is in its own class, and this bootstrapper class is called from the startup method.


try calling Mapper.CreateMap<Foo, Bar>() each time before mappping

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜