title: When the EntityKey create and when it disposed
body: <p>I create a new object and want to attach it to a context like this,</p>
  
  <pre><code>User user = new User();
  user.userName=”Kobe”;
  context.Attach(user);
  </code></pre>
  
  <p>An error message appears – “An object with a null EntityKey value cannot be attached to an object context”.
  If I query out a user object from database and assign it’s EntityKey to the new object, then detach the query result object like this,</p>
  
  <pre><code>User user = (from u in context.Users where u.userID == 1 select u).First();
  User newUser = new User();
  newUser.userName = “Kobe”;
  newUser.EntityKey = user.EntityKey;
  context.Detach(user);
  context.Attach(newUser);
  </code></pre>
  
  <p>Another error message appears – “The object cannot be attached because the value of a property that is a part of the EntityKey does not match the corresponding value in the EntityKey.”
  I really don’t know what the EntityKey is, I searched on the internet and have seen the EntityKey Class in MSDN, but still can’t understand clearly. When the EntityKey created and attached to an object? where can I find it? If I detach the object, why the EntityKey is still exist?</p>
  
  <p>Anyone can help? Thanks in advance!</p>