I’m facing an issue with AutoMapper where ReverseMap is not working as expected. The mapping from ParentA to ParentB works fine, but the reverse mapping from ParentB to ParentA does not. Here is an example of my classes and mapping configuration.
ParentA ssssssss = new ParentA { Id = 1, isActive = "Y", Name = "test" };
var response = automapper.Map<ParentB>(ssssssss);
response.Value = 500;
var yyyy = automapper.Map<ParentA>(response);
public class ParentA
{
public int Id { get; set; }
public string Name { get; set; }
public string isActive { get; set; }
}
[AutoMap(typeof(ParentA), ReverseMap = true)]
public class ParentB
{
public int Id { get; set; }
public string Name { get; set; }
[ValueConverter(typeof(IntConverter))]
[SourceMember("isActive")]
public int Value { get; set; }
}
public class IntConverter : IValueConverter<string, int>/*, IValueConverter<int, string>*/
{
public int Convert(string sourceMember, ResolutionContext context)
{
if (sourceMember == "Y") return 100;
if (sourceMember == "N") return 200;
if (sourceMember == "P") return 500;
return 1000;
}
public string Convert(int sourceMember, ResolutionContext context)
{
throw new NotImplementedException();
}
}