Posts

Showing posts from May, 2012

AutoMapper 2.1 AfterMap() Fires Multiple Times

I've been writing some complex mapping for the hierarchical data on my RustyShark site (the Media entities on the site consist of a lot of dynamic meta data, which can be added and removed when edited). I'm using Entity Framework and AutoMapper, and I've ran in to an issue where AfterMap() executes multiple times, when it should only really execute once. I just thought I'd post my workaround, which also helps to demonstrate how C# interfaces can be handy. Here's what my source entity looks like: public class Medium : IAutoMapperAfterMapUsage { public int ? MediumID { get ; set ; } public string Title { get ; set ; } public DateTime ReleaseDate { get ; set ; } public User CreatedBy { get ; set ; } public DateTime CreatedDate { get ; set ; } public List<Genre> Genres { get ; set ; } public List<MediaFormat> Formats { get ; set ; } public List<MetaData> MetaData { get ; set ; } #region IAutoMapperAft