I understand that they are not supposed to be changed, this is somewhat of a schema migration and only a one-time thing.
I would like to change the key names of entities in my Google App Engine application, effectively deleting and re-crating an entity and updating all references to it.
What is the best way to do this? I'm interesting in hearing anyone's experience with such things.
You cannot update the primary key through entity framework, since entity framework would not know which database row to update. However, if you really need to do it, you could write a stored procedure that updates the primary key, and then execute the stored procedure from entity framework.
An entity key is a property or a set of properties of an entity type that are used to determine identity. The properties that make up an entity key are chosen at design time. The values of entity key properties must uniquely identify an entity type instance within an entity set at run time.
Configuring a primary key By convention, a property named Id or <type name>Id will be configured as the primary key of an entity. Owned entity types use different rules to define keys. You can configure a single property to be the primary key of an entity as follows: Data Annotations.
Since changing the key name is functionally identical to creating a new, identical entity with that key, what you want to do is clone the entity with the new key. Here's some code that does just that.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With