title: Assigning ids to entities with EntityFramework 4
body: <p>I'd like to implement "default" Id generation support for my entities.</p>
  
  <p>When saving the entity, I'd like EntityFramework to only generate the id value for the Entity if it's not already set. If the ID already has a non-null, non-zero value, I want to have that entity ID preserved when the entity is saved in the database.</p>
  
  <p>I'm migrating data from a legacy data model (EntityFramework model created from the old database) to a newly created (model-first) EntityFramework model. Let's call the old model A, and the new model T.</p>
  
  <p>Typically, I'd want T entities to get their Ids set upon save (they're all int64), for the long-term use of the new model.</p>
  
  <p>Currently, I'm explicitly assigning T entity Ids based on the Id of the corresponding A entity from which I'm migrating. This is so the migration results are easy to check. </p>
  
  <p>However, although I can assign the id for a T entity to the same id as the A entity in my migration routine, after I save the entities the Id values have changed.</p>
  
  <p>Is there a way to override the default saving method for all entities in the T model so the id value is only assigned if it's not already set in the entity before it gets saved?</p>
  
  <p>I've looked at some of the other EntityFramework/Id questions here, but to my mind none of them are asking the same thing.</p>
  
  <p>Thanks for any leads.</p>