title: Automapper lazy loading. Entity framework
body: <p>I have an Entity and a ViewModel</p>
  
  <pre><code>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; }
  }
  </code></pre>
  
  <p>and</p>
  
  <pre><code>public class OrderViewModel
  {
      public string Name { get; set; }
      public int? DeliveryMethodId { get; set; }
  }
  </code></pre>
  
  <p>My controller receives the view model and uses automapper to map it back to the entity</p>
  
  <pre><code>[HttpPost]
  public ActionResult GetQuote(OrderViewModel ordervm)
  {
      Order order = Mapper.Map&lt;Order&gt;(ordervm);
      // Do something with the order...
  
      return View();
  }
  </code></pre>
  
  <p>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.</p>
  
  <p>Shouldn't the DeliveryMethod load due to the lazy loading?</p>