I'm using Automapper and I have the following scenario: Class OrderModel has a property called 'ProductName' that isn't in the database. So when I try to do the mapping with:
Mapper.CreateMap<OrderModel, Orders>();
It generates an exception :
"The following 1 properties on Project.ViewModels.OrderModel are not mapped: 'ProductName'
I've read at AutoMapper's Wiki for Projections the opposite case (the extra attribute is on the destination, not in the source which is actually my case )
How can I avoid automapper to make the mapping of this property?
I'm perhaps a bit of a perfectionist; I don't really like the ForMember(..., x => x.Ignore()) syntax. It's a little thing, but it it matters to me. I wrote this extension method to make it a bit nicer:
It can be used like so:
You could also rewrite it to work with
params
, but I don't like the look of a method with loads of lambdas.When mapping a view model back to a domain model, it can be much cleaner to simply validate the source member list rather than the destination member list
Now my mapping validation doesn't fail, requiring another
Ignore()
, every time I add a property to my domain class.