2

I have 2 class Data and MainData that I need to map

public class Data
{
    public Field<string> Results { get; set; }
    public Field<int> A { get; set; }
    public Field<int> B { get; set; }
}

public class Field<T>
{
 public string Label { get; set; }
 public T Value { get; set; }  
}

public class MainData{
 public string result {get; set; }
 public int a {get; set; }
 public int b {get; set; }
}

I've tried to map Data to MainData using automapper as follows:

Mapper.CreateMap(Data, MainData))
.ForMember(dest => dest.result, conf => conf.MapFrom(src => src.results.Value))
.ForMember(dest => dest.a, conf => conf.MapFrom(src => src.A.Value))
.ForMember(dest => dest.b, conf => conf.MapFrom(src => src.B.Value))

var destination = Mapper.Map<Data, MainData>(source);

It's never get mapped value to desination variable. All i get is new MainData object.

dev
  • 898
  • 1
  • 13
  • 33
  • Add `Mapper.Configuration.AssertConfigurationIsValid()` https://github.com/AutoMapper/AutoMapper/wiki/Configuration-validation and http://stackoverflow.com/questions/12037986/is-automapper-assertconfigurationisvalid-enough-to-ensure-good-mapping – Eris Sep 21 '16 at 04:18
  • I think your mapping configuration is correct, I just tested it and got back a MainData with filled-in details. Is there something you missed? (admittedly, this was tested using automapper 5, could that be an issue?) – Nicholas Sizer Sep 21 '16 at 04:23
  • same here, tested with automapper 3.3, still working – Alexandru Marculescu Sep 21 '16 at 08:10
  • @NicholasSizer i am using automapper 4.0.4 version. – dev Sep 21 '16 at 13:05

0 Answers0