2

I've just started using this and immediately ran into a problem mapping a parameter to a a constructor parameter.

I've tried every example I can find on SO but none seem to work and the documentation doesn't mention this feature as far as I can see.

The examples show:

Mapper.CreateMap<UserProfile, UserProfileModel>().ConstructUsing(x => new UserProfileModel(x.Id);

I can't figure out the syntax to get access to the Id property on the UserProfile object.

Another example shows:

Mapper.CreateMap<TypeOneDto, TypeOne>().ConstructUsing((Func<ResolutionContext, TypeOne>) (r => new TypeOne()));

On using any of these lambdas I just have access to the ResolutionContext not the parent object?

Any Ideas?

Jammer
  • 9,969
  • 11
  • 68
  • 115
  • I've got the mapping working now but this blows up doing two way mapping ... Mapper.Initialize(cfg => cfg.CreateMap()); Mapper.Initialize(cfg => cfg.CreateMap()); How do you configure two way mapping? – Jammer Oct 10 '12 at 23:47
  • 1
    Did you manage to sort this out? FYI - I would use profiles as described [here](http://blog.velir.com/index.php/2012/08/27/organizing-automappers-map-configurations-in-mvc/). – Mightymuke Nov 14 '12 at 06:57
  • I actually changed my implementation so I didn't need it in the end but this info is very useful, thanks. – Jammer Nov 17 '12 at 10:58

0 Answers0