DataMapper.Map Ignore List

DataMapper.Map Ignore List

Old forum URL: forums.lhotka.net/forums/t/7477.aspx


GregP posted on Tuesday, August 18, 2009

DataMapper.Map is designed so that the ignore list is applied to the properties in the source object which means that it iterates all properties in the source object. That just seems backwards to me. The goal is to place data into the target object so it seems that the ignore list should identify properties in the target that you don't want set. It seems like this gives the following advantages:

  1. It allows you to use a much wider source object (e.g. DTO) than target (e.g. business object) without having to come up with a large ignore list.
  2. When the width of the source is greater than the target, the Map function only interates over the target properties, which are the only candidates to be mapped anyway.
  3. It would make it easier to use a single DTO representing the entire width of a DB table to populate a variety of info objects of different widths because no (or very small) ignore lists would be needed.

So instead of this line in DataMapper.Map:

    foreach (var propertyName in GetPropertyNames(source.GetType()))

we would have:

    foreach (var propertyName in GetPropertyNames(target.GetType()))

So my question is: Why is this implemented to iterate over the properties in the source and, hence, require an ignore list based on the source? I think about it in the opposite way - what am I missing here?

RockfordLhotka replied on Thursday, August 20, 2009

The ignore list is a blunt instrument no matter how you look at it. If you want finer control over the mapping, then create a DataMap object to directly control the mapping.

Copyright (c) Marimer LLC