I'd like to implement "default" Id generation support for my entities.
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.
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.
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.
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.
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.
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?
I've looked at some of the other EntityFramework/Id questions here, but to my mind none of them are asking the same thing.
Thanks for any leads.