AutoMapper issue

此生再无相见时 提交于 2019-11-29 11:37:27
Jimmy Bogard

Something I added recently to AutoMapper might help you - custom naming conventions. If you check out the trunk (R107), look around for INamingConvention. Right now, I have two naming conventions (PascalCase and lower_case_underscore), but it's really just a matter of figuring out the right RegEx to get you going:

INamingConvention.cs

Right now, naming conventions are global and profile-scoped. Since this feature is new, there isn't any documentation other than the tests.

This is how I'm doing it

Mapper.Initialize(cfg =>
        {
            cfg.RecognizeDestinationPrefixes(new []{"_"});
            cfg.RecognizePrefixes(new[] { "_" });

            cfg.CreateMap<To, From>().ReverseMap();
        });

For this you could add a custom mapping to solve this particular case:

Mapper.CreateMap<From, To>()
   .ForMember( dest => dest.Id, opt => opt.MapFrom( src => src._Id ) )
   .ForMember( dest => dest.Name, opt => opt.MapFrom( src => src._Name ) );
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!