title: Beginner EF4 / CodeFirst / MVC3 help
body: <p>Although I love what I'm learning, I'm finding it a struggle and need some help</p>
  
  <p>I've been using these two tutorials which I think are awesome:
  <a href="http://weblogs.asp.net/scottgu/archive/2010/07/16/code-first-development-with-entity-framework-4.aspx" rel="nofollow">http://weblogs.asp.net/scottgu/archive/2010/07/16/code-first-development-with-entity-framework-4.aspx</a>
  http://msdn.microsoft.com/en-us/data/gg685467</p>
  
  <p>Currently my main problem/confusion is:</p>
  
  <p>I have a CodeFirst table/entity I don't know how to correctly get data from other tables/entities to show in my views:</p>
  
  <pre><code>public class Car {
      public int ID { get; set; }
      public string Name { get; set; }
  
      public int EngineID { get; set; }
      public virtual Engine { get; set; }
  }
  
  public class Engine {
      public int ID { get; set; }
      public string Name { get; set; }
      public string Manufacturer { get; set; }
      // (plus a whole lot of other things)
  }
  </code></pre>
  
  <p>Now when I create a View for Cars (using the List type/option) I get a nice autogenerated list</p>
  
  <pre><code>@foreach (var item in Model) {
  &lt;tr&gt;
      &lt;td&gt;@item.ID&lt;/td&gt;
      &lt;td&gt;@item.Name&lt;/td&gt;
      &lt;td&gt;@item.EngineID&lt;/td&gt;
  &lt;/tr&gt;
  </code></pre>
  
  <p>Perfect... except EngineID is mostly worthless to the viewer, and I want to show Engine.Name instead</p>
  
  <p>So I assumed I could use EF lazy loading:</p>
  
  <pre><code>&lt;td&gt;@item.Engine.Name&lt;/td&gt;
  </code></pre>
  
  <p>Unfortunately when I tried that, it says my ObjectContext has been disposed so can't get any further data requiring a connection</p>
  
  <p>Then I tried going to the controller and including the Engine.Name</p>
  
  <pre><code>var cars = (from c in db.Cars.Include("Engine.Name") select c;
  </code></pre>
  
  <p>Which tells me: Entities.Engine does not declare a navigation property with the name 'Name'</p>
  
  <p>... ? Lies</p>
  
  <p>Include("Engine") works fine, but all I want is the Name, and Include("Engine") is loading a large amount of things I don't want</p>
  
  <p>Previously in a situation like this I have created a view in the DB for Car that includes EngineName as well. But with CodeFirst and my noobness I haven't found a way to do this</p>
  
  <p>How should I be resolving this issue?</p>
  
  <p>I thought perhaps I could create a Model pretty much identical to the Car entity, but add Engine.Name to it. This would be nice as I could then reuse it in multiple places, but I am at a loss on how to populate it etc</p>
  
  <p>Wanting to learn TDD as well but the above is already frustrating me :p </p>
  
  <p>Ps any other tutorial links or handy things to read will be greatly appreciated</p>