Using Automapper 3 (upgrading is not an option), I am wondering how can I map an entity (src) to destination where the property in destination does NOT exist in source?
Let's call the property in the destination some non mapped "temp" or "calculation" property. Of course when mapping, AM fails because the property in destination was not found in source.
CreateMap<SystemConfiguration, SystemConfigurationModel>()
.ForMember(dest => dest.UserRulesModel, opt => opt.MapFrom(src => src.UserRules));
In the "UserRulesModel", I have this temp property. I want AM to ignore it when mapping from the entity (DB) into the View Model (UserRulesModel)
UPDATE: UserRulesModel is a collection, as is UserRules.
thank you.
You can configure that when you create the map from
UserRulestoUserRulesModel:UPDATE
Let's say
UserRulesis a collection ofUserRuleItemobjects andUserRulesModelis a collection ofUserRuleModelItemobjects.If there is a property in
UserRuleModelItemthat is not present inUserRuleItem, you can configure AutoMapper to ignore that property using the syntax I posted originally:The type of
destwill be the type of object you are mapping to, which isUserRuleModelItemin this case.