I'm trying to update a foreign key relationship in EntityFramework 4 (with a microsoft sql server database) via a foreign key.
I load the object using .Single()
and then try set to the the Object.ExampleId
(The Example table is a reference table that corresponds to an enumeration in C#). Then I call SaveChanges()
on the context.
Doing so works locally, but on production servers it fails and appears to hang. Using debug statements I've narrowed the hang down to the line where I actually set the Id.
I was able to fix the problem by loading the entire Example object and doing Object.Example = loadedExample
instead of Object.ExampleId = exampleId
.
My question is why is this the case? Other places I have been able to update relationships just by setting the Id. Is this a bad practice?