title: TryGetObjectByKey not compiling in .net 4.5
body: <p>I have the following code that does a great job at saving a detached object in a .Net 4 / EF 4 project.  I wanted to use that code in a new .Net 4.5 / EF 5 project.  I copied it in and now it gives me a compile error of:</p>
  
  <p>"MyEntities does not contain a definition for 'TryGetObjectByKey' and no extension method 'TryGetObjectByKey' accepting a first argument of type MyEntities could be found (are you missing a using directive or an assembly reference?)"</p>
  
  <p>Allegedly it is in the System.Data.Objects namespace (so I have a using for it) from the System.Data.Entity assembly (.dll) which is referenced.</p>
  
  <pre><code>public bool UpdateChanged(IEntityWithKey DetachedObject = null) {
      bool Result = false;
  
      try {
          using (MyEntities db = new MyEntities()) {
              if (DetachedObject != null) {
                  object Original = null;
  
                  if (db.TryGetObjectByKey(DetachedObject.EntityKey, out Original))
                      db.ApplyCurrentValues(DetachedObject.EntityKey.EntitySetName, DetachedObject);
              } // if they want to Update an Entity
  
              db.SaveChanges();
              Result = true;
          } // using the database
      } catch (Exception e) {
  
      } // try-catch
  
      return Result;
  } // UpdateChanged - Method
  </code></pre>
  
  <p>According to this link it should work: <a href="http://msdn.microsoft.com/en-us/library/bb738728.aspx" rel="nofollow">http://msdn.microsoft.com/en-us/library/bb738728.aspx</a></p>
  
  <p>Can you please help?</p>
  
  <p><strong>UPDATE / SOLUTION:</strong></p>
  
  <p>Based on @Rowan's answer below I have simply modified my Save method to something like the following instead of creating an UpdateChanged method that takes Detached objects:</p>
  
  <pre><code>using (MyEntities db = new MyEntities()) {
      if (o.ID &gt; 0) {
          // Existing Owner
          db.Owners.Attach(o);
          db.Entry(o).State = EntityState.Modified;
          db.Entry(o.Address).State = EntityState.Modified;
      } else {
          // New Owner
          db.Owners.Add(o);
      } // if this is a New Owner
  
      db.SaveChanges();
  } // using the database
  </code></pre>