Marcus wrote:
Otis wrote:
The ID is refetched for synchronization purposes. (like an FK pointing to an identity pk in a related object). Reading the value through the property walks the normal way of retrieving a value, which will end in the state check.
Are you saying that the new Identity ID which is returned (as requested by DynamicQueryEngine.CreateInsertDQ) is discarded after the saves complete?
No, the value is there and readable, though fields which aren't marked as the PK aren't. So if a field is marked as the PK at runtime, the value is readable.
I discovered a bug yesterday with the designer, loading an old project: PK fields weren't marked as PK anymore in the designer. I'll update the designer later this morning.
I couldn't find your explaination of why OutOfSync is required, but I seem to remember you saying something about needing to update default values, values set by triggers etc that might be set duing the save process on the server...
Correct.
I'm struggling with the fact that other than the new ID (which as far as I can tell is returned from the INSERT statement) I have no need to re-read the data. I'm not using default values or triggers.
Then that value should be available to you after a Save.
It therfore seems logical for me to go ahead and override the setting of EntityState in SaveEntity to EntityState.Fetched again. I thought I could do this in the OnSaveEntityComplete event, but in fact this event is fired before the state is set to OutOfSync.
Now I'm thinking that maybe there is another good reason why you have not provided for this possibility, a reason that I have not thought of?
In 1.0.2004.1, it was always throwing this exception, in 1.0.2004.2, it only throws this exception for non-PK fields. My unit-tests use this feature a lot, so I'll run into it whenever this changes accidently. The main thing is: after an entity is saved, the entity is marked OutOfSync, unless it's refetched. The EntityBase2.GetCurrentFieldValue() method checks for OutOfSync AND if the field is a PK field. If it's not a PK field, the exception is thrown, otherwise it's proceeding. It's therefore key the field is marked as a PK in the generated code (it normally is when it's a PK in the designer
).