The following display should do the work of aligning your model :
Mapper
.CreateMap<AffiliateComponentType, AffiliateComponentTypeView>()
.ForMember(
dest => dest.ComponentTypeID,
opt => opt.MapFrom(src => src.ComponentType.ComponentTypeID)
)
.ForMember(
dest => dest.Component_Type,
opt => opt.MapFrom(src => src.ComponentType.Component_Type)
)
.ForMember(
dest => dest.ComponentDesc,
opt => opt.MapFrom(src => src.ComponentType.ComponentDesc)
);
and if you change your view model as follows:
[Serializable]
public class AffiliateComponentTypeView
{
public int ComponentTypeComponentTypeID { get; set; }
public string ComponentTypeComponent_Type { get; set; }
public string ComponentTypeComponentDesc { get; set; }
public bool MandatoryComponent { get; set; }
public bool CanBeBookedStandalone { get; set; }
public int PreferenceOrder { get; set; }
}
Smoothing will be performed automatically with AutoMapper using standard conventions, so you only need to:
Mapper.CreateMap<AffiliateComponentType, AffiliateComponentTypeView>();
Component_Type, AutoMapper, .
, :
IEnumerable<AffiliateComponentType> source = ...
IEnumerable<AffiliateComponentTypeView> dest = Mapper.Map<IEnumerable<AffiliateComponentType>, IEnumerable<AffiliateComponentTypeView>>(source);