This project has moved. For the latest updates, please go here.


Multiple calls to AfterMap for bidirectional relationships


When you have entities with bidirectional relationships (e.g. parent/child) and specify an AfterMap handler, that handler gets invoked multiple times. Only the last call is actually after the mapping. The previous calls happens when AutoMapper finds the object in its cache and are before the mapping is complete, meaning some of the properties are not yet mapped.
This feels like a bug to me. If you add a BeforeMap handler it's only invoked once as expected.
I've attached a modified version of the BidirectionalRelationships.cs unit test to show this behaviour
Moving the AfterMap call from TypeMapMapper.Map to TypeMapObjectMapperRegistry.Map (i.e same place that BeforeMap is called) seems to solve the problem. All other tests still pass after doing that change.

file attachments

Closed Sep 2, 2011 at 10:45 PM by jbogard
All issues moved to GitHub