Martin
Martin

Reputation: 2971

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 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?

Upvotes: 1

Views: 128

Answers (2)

Omu
Omu

Reputation: 71208

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

Upvotes: 1

Darin Dimitrov
Darin Dimitrov

Reputation: 1038830

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.

Upvotes: 1

Related Questions