I have an Entity and a ViewModel
public class Order
{
[Key]
public int Id { get; set; }
[Required]
public string Name { get; set; }
[Required]
[ForeignKey("DeliveryMethod")]
public int DeliveryMethodId { get; set; }
public virtual RouteDeliveryMethod DeliveryMethod { get; set; }
}
and
public class OrderViewModel
{
public string Name { get; set; }
public int? DeliveryMethodId { get; set; }
}
My controller receives the view model and uses automapper to map it back to the entity
[HttpPost]
public ActionResult GetQuote(OrderViewModel ordervm)
{
Order order = Mapper.Map<Order>(ordervm);
// Do something with the order...
return View();
}
This is all fine, however after it has done the mapping back to an Order object it doesn't load the DeliveryMethod, DeliveryMethodId has a valid value, but DeliveryMethod is always null.
Shouldn't the DeliveryMethod load due to the lazy loading?