Here is the scenario:
I have a Product Entity, which has an ImageID field, so it has a relationship with the Image Entity. This is all defined in the schema and DBML.
Now, say I create a new Product entity, without a ImageID, and save it to the DB. At this point, the _Image field of the Entity has HasLoadedOrAssignedValue set to false, as it should.
Now, when I go and retrieve that entity from the DB, without an ImageID, i.e ImageID is set to null, and the Image Entity attached to it is also set to null, HasLoadedOrAssignedValue is set to true. Why?
Now, when I try and set the ImageID property to a valid int, I get a ForeignKeyReferenceAlreadyHasValueException
exception.
Now, I know that people say, "oh, you have to set the relationship property itself, so, Product.Image = someImage, not Product.ImageID = 2", but I always set the ID field, and it always works... Well, almost always.
So, my question is twofold:
The problem is something is looking at the Image property and causing it to load - perhaps even the debugger.
Set a breakpoint in the Product.Image property and see what path is causing it.