2

Here is my mapping config:

Mapper.Initialize(config =>
{
    config.SourceMemberNamingConvention = new LowerUnderscoreNamingConvention();
    config.DestinationMemberNamingConvention = new PascalCaseNamingConvention();
    config.CreateMap<Rotator_Ad_Run, RotatorAdRunViewModel>()
        .ReverseMap();
}

And the simplified classes:

public class Rotator_Ad_Run
{
    public DateTime Start_Date { get; set; }
    public DateTime End_Date { get; set; }
    public bool Enabled { get; set; }
}

public class RotatorAdRunViewModel
{
    public DateTime StartDate { get; set; }
    public DateTime EndDate { get; set; }
    public bool Enabled { get; set; }
}

The mapper is mapping from Rotator_Ad_Run to RotatorAdRunViewModel but when reversed, it only maps the Enabled property. It works when I explicitly map the values using .ForMember().

Is there anything I need to do to let Automapper know that the naming conventions need to be reversed?

UPDATE

I'm trying to find a workaround using Profiles, but those don't seem to work either...

Mapper.Initialize(config =>
{
    config.AddProfile<ModelToViewModel>();
    config.AddProfile<ViewModelToModel>();
});

...

internal class ModelToViewModel : Profile
{
    protected override void Configure()
    {
        SourceMemberNamingConvention = new LowerUnderscoreNamingConvention();
        DestinationMemberNamingConvention = new PascalCaseNamingConvention();

        this.CreateMap<Rotator_Ad_Run, RotatorAdRunViewModel>();
    }
}
internal class ViewModelToModel : Profile
{
    protected override void Configure()
    {
        SourceMemberNamingConvention = new PascalCaseNamingConvention();
        DestinationMemberNamingConvention = new LowerUnderscoreNamingConvention();

        this.CreateMap<RotatorAdRunViewModel, Rotator_Ad_Run>();
    }
}

The ModelToViewModel profile works, but the ViewModelToModel does not.

Jason
  • 506
  • 3
  • 14

2 Answers2

3

Here's a workaround (at least until the bug is fixed):

Mapper.Initialize(config =>
{
    config.ReplaceMemberName("_", "");
    //Map as normal
});
Jason
  • 506
  • 3
  • 14
0

This is a bug, can you open a GitHub issue?

Jimmy Bogard
  • 26,045
  • 5
  • 74
  • 69
  • I have added an issue that links back to here. [https://github.com/AutoMapper/AutoMapper/issues/698](https://github.com/AutoMapper/AutoMapper/issues/698) – Jason Mar 26 '15 at 13:12