There is an unsaved comment in progress. You will lose your changes if you continue. Are you sure you want to reopen the work item?
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.