Actually, AutoMapper provides object flattening out-of-the-box, so this will be done automatically for you.
Person person = new Person();
Mapper.CreateMap<Person, EmployeeDTO>()
.ForMember(dest => dest.personid, opt =>
opt.MapFrom(src => src.id)); // this line is only because I noticed different property names (id vs personid)
EmployeeDTO employeeDTO = Mapper.Map<EmployeeDTO>(person);
employeeDTO.genderid.ShouldEqual(person.gender.id);
If you use the convention OuterProperty.InnerProperty
in your complex domain object, and the types match properly, AutoMapper will flatten it down to OuterPropertyInnerProperty
in the destination object. You can read all about that here: http://github.com/AutoMapper/AutoMapper/wiki/Flattening