I have an entity with a status property that I would like to update.
I would like to do the following:
const int NEW_STATUS = 2;
myEntity.StatusReference.EntityKey = new EntityKey("SetName", "KeyName", NEW_STATUS);
When this is passed to the context, its state is “UnChanged”, despite me changing the relationship! This means the save will not be persisted.
The entity comming in is from a different context to the one that its being attached to and saved.
Anyone know how I can update just the entitykey and persist it!?
Thanks in advance,
David
You can’t. EntityKeys are designed to be mapped to primary keys, which, in any good DB design, will never change. If you’ve mapped your EntityKey to something which is not a PK, change it to the PK. If your DB design calls for PKs to change, please reconsider that design.(Removed after you changed the question.)Added, upon re-reading the question: Are you actually wanting to update the EntityKey of the entity, or do you just want to change the status property? If the latter, try one of the following:
…or…
If your entity state isn’t modified, you probably have the order of operations wrong when adding to/saving the context. You would need to show that when asking for help on it.