ORMEntityOutOfSyncException but: IsNew==False && IsDirty==False && Fields.State==Fetched

Posts   
 
    
acl
User
Posts: 91
Joined: 28-Mar-2012
# Posted on: 22-Oct-2015 10:31:36   

Hi,

LLBLGen Version 4.0.0.0.

I received a bug report with an ORMEntityOutOfSyncException. This exception contains an OutOfSyncEntity, which I suppose is the entity that generated the error.

Our error handling code prints out several properties of the exception and of the exception's OutOfSyncEntity:

SD.LLBLGen.Pro.ORMSupportClasses.ORMEntityOutOfSyncException Message: The entity is out of sync with its data in the database. Refetch this entity before using this in-memory instance. Source: SD.LLBLGen.Pro.ORMSupportClasses TargetSite: System.Object GetValue(Int32, Boolean) LLBLGen RuntimeBuild: 06062013 LLBLGen RuntimeVersion: 4.0.0.0 OutOfSyncEntity: IsNew: False IsDirty: False Fields: IsDirty: False State: Fetched Fields List: EntityField2: Name: TDocument_Id IsChanged: False IsNull: False CurrentValue: 96405 DbValue: 96405 ...

I do not understand why the ORMEntityOutOfSyncException is raised, since everything indicates that the entity is good.

I would like to be able to test whether the Entity is OutOfSync before accessing any properties. Currently I'm testing IsNew and Fields.State. But that does not seem to be sufficient.

Any help would be appreciated.

Thanks!

Walaa avatar
Walaa
Support Team
Posts: 14950
Joined: 21-Aug-2005
# Posted on: 22-Oct-2015 20:27:15   

Is this a New entity or a fetched one? Does Fields.State reports anything but New or Fetched?

acl
User
Posts: 91
Joined: 28-Mar-2012
# Posted on: 23-Oct-2015 08:47:16   

The entity is always a fetched one.

The Fields.State property is Fetched as shown above. (I only had this bug once.)

Walaa avatar
Walaa
Support Team
Posts: 14950
Joined: 21-Aug-2005
# Posted on: 23-Oct-2015 15:56:48   

if you are using the entity after saving it, you will get this exception. Unless you re-fetch after save (there is a flag in the save methods to re-fetch the saved entities). Or if you are sure nothing is changed to the entity when saved (i.e. no trigger based or sequence based fields have been updated at the database side) you can mark the entity as saved (change the Fields.State) value, so you can use it after the Save without re-fetching it.

acl
User
Posts: 91
Joined: 28-Mar-2012
# Posted on: 26-Oct-2015 09:38:45   

What value would I have to assign to the Fields.State property? If the answer is "Fetched", then too bad, that **is **the value of the property. (Unless there is some side-effect from explicitly setting the Fields.State property even if its value does not change.)

Walaa avatar
Walaa
Support Team
Posts: 14950
Joined: 21-Aug-2005
# Posted on: 26-Oct-2015 19:16:15   

Are you setting it after the save operation? Could you please share a simple code snippet?