I have quite a bit of entities and so far, I’ve been doing stuff like
Mapper.CreateMap<Employee, EmployeeDetailsDTO>()
.ForSourceMember(mem => mem.NewsPosts, opt => opt.Ignore());
I want to tell AutoMapper to simply ignore missing properties in the destination object without having to specify each of them. So far, I haven’t found a way to do so with my multiple SO and Google searches. Anyone has a solution? I’m ready to do some sort of loop or anything, as long as it can be written once and that it will scale with model / dto changes or added properties.
When are you getting the error? Is it when you call
AssertConfigurationIsValid?If yes, then simply dont call this method
You dont have to call this method, consider the following mapping which works:
You may want to call
AssertConfigurationIsValidfor other mappings to ensure they are correct so instead what you need to do is organize your mappings into Profiles:and then if you decide you want to check the validity of the mapping (case by case basis in your situation) then call
important in your case and/or any case where you dont call
AssertConfigurationIsValidyou should use something like AutoFixture and a Unit Test to ensure your mapping is working. (which is the intent ofAssertConfigurationIsValid)