I had to use google translator, so I hope I understood correctly ;-)
When you change an existing entity, you can change its scalar values and references, but you cannot change its id (key) fields.
For example, for existing db entities : person.Name = "David" - ok person.ID = 7 -not ok
This is becaus the ObjectStateManager uses the ID information to keep track of entities in the context, and changing the ID of an existing entity contradicts EF behavior.
There is no problem doing the following, though:
person.Father = person2;
If this doesn't answert your question, please paste the code you use that gave you the error (how you change the FK and how you save changes).
Ido. Please mark posts as answers/helpful if it answers your question
Proposed as answer byhaberman michaelWednesday, November 4, 2009 10:54 AM
Marked as answer byYichun_FengWednesday, November 11, 2009 1:28 AM
I had to use google translator, so I hope I understood correctly ;-)
When you change an existing entity, you can change its scalar values and references, but you cannot change its id (key) fields.
For example, for existing db entities : person.Name = "David" - ok person.ID = 7 -not ok
This is becaus the ObjectStateManager uses the ID information to keep track of entities in the context, and changing the ID of an existing entity contradicts EF behavior.
There is no problem doing the following, though:
person.Father = person2;
If this doesn't answert your question, please paste the code you use that gave you the error (how you change the FK and how you save changes).
Ido. Please mark posts as answers/helpful if it answers your question
Proposed as answer byhaberman michaelWednesday, November 4, 2009 10:54 AM
Marked as answer byYichun_FengWednesday, November 11, 2009 1:28 AM