.Net4 Entity Framework, N-Tier (so objects are detatched)
I have 2 objects generated Database first such that object1 has a Navigation Property (1 – 1) to object 2.
I can successfully make changes to other properties of object 1, but when I try to change object2 I get an error.
My webpage has a drop down list of object2 names and indices.
I have tried setting the object1.object2Id property and saving it and I get a referential Key error. (I can see that this may be because the object still holds the original object2).
If however I load in the new object2 and attempt to update object1 I get the object could not be added or attached because its EntityReference has an Entity Key Property that does not match.
So I seem to be going round in circles.
So using Detached objects and Entity Framework, what is the correct way of updating a child object / foreign key?
Ok, Figured it out. Its a result of me working in detatched mode. If I wait until I am at the Business tier about to write the changes, and change the fk once I have re attached the object to the context it works.
Just one of things I needed to learn I guess !