title: ASP.Net MVC 3, Complex Objects and Lazy Loading
body: <p>First of all, I am new to ASP.Net MVC 3, and I am also using EF 4.1.</p>
  
  <p>I have a complex object, something similar to let's say a Product object containing a Category object. So we have Product.CategoryId, Product.Category and some extra properties. I also have a form to create products with a dropdown list to select the category.</p>
  
  <p>In my controller, after the product has been created, I need to have access to some property of the Category to perform some extra stuff. However, although Product.CategoryId is set, I cannot access Product.Category.SomeProperty because Product.Category is null. I expected Product.Category would be loaded automatically using some lazy loading, but it does not seem to be.</p>
  
  <p>The code in my Controller looks like this:</p>
  
  <pre><code>[HttpPost]
  public ActionResult Create(Product product)
  {
     if (ModelState.IsValid)
      {
          db.Products.Add(product);
          db.SaveChanges();
  
          string someString = product.Category.SomeProperty;
          ...
  </code></pre>
  
  <p>Now, this does not work because product.Category is null. What do I need to add so that I can access SomeProperty?</p>