views:

49

answers:

2

Can you

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

and then later on add another mapping of the 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?

+1  A: 

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.

Darin Dimitrov
+2  A: 

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

Omu