I am using EF 4.0 and WPF and I had similar problem, and ....
found the issue that solved it (at least for me) in a very simple way.
Because, like you, I thought it must be simple to update a field in a table (i.e. in your case: Contact) that is referenced to by a foreignkey from another table (i.e. in your case: ContactType).
However, the Error Message:
".... is part of the object's key information and cannot be modified."
only appears when you try to update a Primary Key (which wasn't my intention at all).
Had a closer look at the XML code of my EntityModel and found it:
<EntityType Name="Contact">
<Key>
<PropertyRef Name="ID" />
<PropertyRef Name="contactTypeID" /> <!-- This second line caused my problem -->
</Key>
<Property Name="ID" Type="int" Nullable="false" />
...
...
</EntityType>
For some reason (maybe I made some foolish mistake within my database), when Visual Studio autogenerated for me the DataModel from my database, it added in that very table (Contact), where I wanted to update the field (ContactTypeID
) a second PropertyRef
(second line).
I just deleted that second PropertyRef
:
<PropertyRef Name="contactTypeID" />
in both, the store model and the conceptual model and .... issue was solved :-)
Hence, remains like:
<EntityType Name="Contact">
<Key>
<PropertyRef Name="ID" />
</Key>
<Property Name="ID" Type="int" Nullable="false" />
...
...
</EntityType>
Updates and Inserts are now running smoothly like a baby .... :-)
Hence, good idea to check the XML of the datamodel to verify that only your PK is listed as PropertyRef
. Worked for me ... :-)