title: Entity Framework Attaching an object but not calling SaveChanges
body: <p>Below is an example code which should demonstrate what I'm trying to achieve:</p>
  
  <pre><code>    public static void addRecord(CargoShip ship, DbContext db)
      {
          // Realistically, in my application this is decided by business logic, - omitted for brevity
          long containerTypeIDNewContainer = 5;
  
          Container containerToAdd = new Container()
          {
              cargoShipBelongingToID = ship.cargoShipID,
              containerTypeID = containerTypeIDNewContainer
          };
          ship.Containers.Add(containerToAdd);
  
          // This line of code is what I want to be able to do
          // WITHOUT doing a db.SaveChanges
  
          // ContainerType is a lookup table in the database, each container type has pre-defined
          // Height/Width etc
  
          // This throws a null exception, ContainerType object does not exist.
          string containerHeight = containerToAdd.ContainerType.Height;
      }
  </code></pre>
  
  <p>I basically want to be able to create a new <code>Container</code> and fill in a foreign key on that object, and be able to access the child of the foreign key as an object in code.</p>
  
  <p>if I call a SaveChanges, it will naturally go and fetch the values for the Container object, but I want to fill in those values/objects without having to do a Savechanges.</p>
  
  <p><strong>edit:</strong></p>
  
  <p>Forgot to mention incase it is not clear. The relationship is: <code>CargoShip</code> has many <code>Container</code>, a <code>Container</code> has ONE <code>ContainerType</code>, which is a FK and is non nullable.</p>
  
  <p>Can you help with this.</p>
  
  <p>Thanks</p>