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 appreciated an extension added by Steve Rukuts, so I decided to add one more extension method based on his example. Hope it will help somebody:
Usage:
Hello All Please Use this it's working fine... for auto mapper use multiple .ForMember in C#
From Jimmy Bogard:
CreateMap<Foo, Bar>().ForMember(x => x.Blarg, opt => opt.Ignore());
It's in one of the comments at his blog.
There is now (AutoMapper 2.0) an IgnoreMap attribute, which I'm going to use rather than the fluent syntax which is a bit heavy IMHO.
Just for anyone trying to do this automatically, you can use that extension method to ignore non existing properties on the destination type :
to be used as follow :
thanks to Can Gencer for the tip :)
source : http://cangencer.wordpress.com/2011/06/08/auto-ignore-non-existing-properties-with-automapper/
You can do this: