Bidirectional

This post was originally published on this site

The Daily WTF

Trung worked for a Microsoft and .NET framework shop that used AutoMapper to simplify object mapping between tiers. Their application’s mapping configuration was performed at startup, as in the following C# snippet:

public void Configure(ConfigurationContext context) { AutoMapper.Mapper.CreateMap().AfterMap(Map); … }

where the AfterMap() method’s Map delegate was to map discrepancies that AutoMapper couldn’t.

One day, a senior dev named Van approached Trung for help. He was repeatedly getting AutoMapper’s “Missing type map configuration or unsupported mapping. Mapping types Y -> X …” error.

Trung frowned a little, wondering what was mysterious about this problem. “You’re … probably missing mapping configuration for Y to X,” he said.

“No, I’m not!” Van pointed to his monitor, at the same code snippet above.

Trung shook his head. “That mapping is one-way, from X to Y only. You can create the reverse mapping by using the Bidirectional() extension method. Here

To read the full article click on the 'post' link at the top.