I am not sure this can be done with AutoMapper. You can try to define an extension method, such as this:
public static CustomerViewModel ToViewModel(this Customer cust)
{
return new CustomerViewModel()
{
CompanyName = cust.CompanyName,
CustomerType = cust.CustomerType,
ContactName = cust.CustomerContacts.First().ContactName,
ContactTel = cust.CustomerContacts.First().ContactTel
};
}
Of course, a little validation on top would be nice. Then you use it like this:
Customer cust= GetCustomer();
CustomerViewModel model= cust.ToViewModel();