I am mapping an object to an object model as shown below:
CreateMap<Order, OrderModel>()
.ForMember(result =>
result.OrderId,
opt => opt.MapFrom(source => source.OrderId))
.ForMember(result =>
result.Quantity,
opt => opt.MapFrom(source => source.Quantity))
.ReverseMap();
Here are the object and model:
public class Order
{
public int OrderId { get; set; }
public int Quantity { get; set; }
public int ItemId { get; set; }
}
public class OrderModel
{
public int OrderId { get; set; }
public int Quantity { get; set; }
public Item ItemPurchased { get; set; }
}
And here is the class of the ItemPurchased field:
public class Item
{
public int ItemId { get; set; }
public string ItemName { get; set; }
}
My question is how do I handle the Item? The Item itself is another class. How do I map it so that the Item object is obtained using the itemId, and then mapped to the OrderModel? What is the typical way to do this? Or is this not a practical or typical way to have a class member that is another class?
I googled for a typical solution, but was unsuccessful.