0

I have these two models

public class ModelA
{
    public string name { get; set; }
    public string email_address { get; set; }
}

public class ModelB
{
    public string Name { get; set; }
    public string EmailAddress { get; set; }
}

and I have this mapping:

Mapper.Initialize(cfg => cfg.CreateMap<OldStudent, NewStudent>());
var newModel = Mapper.Map<NewStudent>(oldStudent);

Well my mapping wont work because email_address and EmailAddress cannot be mapped.

Now I want to create a logic or to insert code where the email_address will turn to EmailAddress so the mapping will work, (in short I want to remove the underscore and make it CamelCase)

I also have too many properties so I dont want to use the manual mapping (.ForMember method by automapper)

Any idea how can I achieve this? Thanks in advance.

1 Answers1

0

Follow the link naming-conventions

and add below lines to config.

Mapper.Initialize(cfg => {
  cfg.SourceMemberNamingConvention = new LowerUnderscoreNamingConvention();
  cfg.DestinationMemberNamingConvention = new PascalCaseNamingConvention();
});

This would fix the issue.

sunder
  • 1,803
  • 4
  • 29
  • 50