automapper multi objects to one object

You should just be able to do:

Mapper.CreateMap<ANote, CNote>();

Mapper.CreateMap<Foo1, Foo3>()
    .ForMember(dest => dest.ANotes, opt => opt.MapFrom(src => src.ANotes))
    .ForMember(dest => dest.BNotes, opt => opt.Ignore());

Mapper.CreateMap<Foo2, Foo3>()
    .ForMember(dest => dest.BNotes, opt => opt.MapFrom(src => src.ANotes))
    .ForMember(dest => dest.ANotes, opt => opt.Ignore());

Foo3 foo3 = new Foo3();

Mapper.Map<Foo1, Foo3>(foo, foo3);
Mapper.Map<Foo2, Foo3>(foo2, foo3);

foo3.ANotes and foo3.BNotes should both have been mapped correctly.

Tags:

C#

Automapper