简体   繁体   中英

AutoMapper mapping Function to a Member's get

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'.

You can override via:

Mapper.CreateMap<Foo, FooDto>()
    .ForMember(d => d.Name, opt => opt.MapFrom(src => src.Name));

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM