I am newbie for Automapper.
I have a domin and ViewModel class.
I want to map the domain class to ViewModel class.
Domain Class :
public class PurchaseOrder
{
public int Id { get; set; }
public string PONo { get; set; }
public DateTime PODate { get; set; }
public int CompanyId { get; set; }
}
public class Company
{
public int Id { get; set; }
public string Name { get; set; }
}
View Model Class
public class PurchaseOrderVM
{
public int Id { get; set; }
public string PONo { get; set; }
public DateTime PODate { get; set; }
public int CompanyId { get; set; }
public string CompanyName { get; set; }
}
public class CompanyVM
{
public int Id { get; set; }
public string Name { get; set; }
}
Now, If you can see , I can map ID,PONo,PoDate perfectly.
But, I want to know how can I map the CompanyID and ComapanyName from Domain to VM class ?
Transform Method
static void POTransform()
{
PurchaseOrder PODomain = new PurchaseOrder();
PODomain.Id = 1;
PODomain.PONo = "154";
PODomain.PODate = Convert.ToDateTime("5-Jun-2014");
Mapper.CreateMap<PurchaseOrder, PurchaseOrderVM>()
.ForMember(dest => dest.CompanyName, Source => Source.MapFrom(????);
}