2

I have a Member named "Name" and I'm using AutoMapper to map between my ViewModel and my base Model. However, I also have a method named "GetName()" on a separate ViewModel which seems to be overriding my "Name" member's 'get' on the actual model.

I've since renamed the method to "GetFullName()" and this is no longer a problem.

This work-around works just fine, however, I would like to know what override in AutoMapper I can implement to let it know to not map function values like "GetName()" to a member's 'get'.

2
  • Sounds interesting. Can you show some code?
    – lbrahim
    May 1, 2015 at 21:43
  • I think you need to implement an INamingConvention interface, see this answer
    – Christian
    May 1, 2015 at 21:54

1 Answer 1

0

You can override via:

Mapper.CreateMap<Foo, FooDto>()
    .ForMember(d => d.Name, opt => opt.MapFrom(src => src.Name));
2
  • Good call, the problem (and I should have stated this earlier) is I do not know where else in our code base this could occur. I'm afraid other members are being overwritten by methods and want to prevent that from happening. May 4, 2015 at 13:07
  • There's no way to prevent that, other than to not name your methods confusingly. I wouldn't name things like this WITHOUT AutoMapper. May 4, 2015 at 14:51

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.