I struggled with this for too long, or at least a problem like this. I had a class with many properties (about 30), and I just wanted to display about 4 of them. It seems crazy to add 26 ignored statements (especially when it means that future changes to the class mean they need to be updated!)
I finally found that I can tell AutoMapper to ignore everything, and then explicitly add the ones I need.
You will be forgiven to think that you can just do this (but not because it will not compile):
The reason this does not work is because the ForAllMembers () method does not support free chaining (at least in the current version 2.0).
The good news is that the chainless version really works. Of course, one of the caveats is that you need to explicitly tell AutoMapper which members should be displayed. I have not yet found an easy way to have it in both directions, so that you can still use the implicit mappings and ignore the broken ones.
Nicholas Green Oct 17 '11 at 10:27 2011-10-17 22:27
source share