Avoid ORMEntityOutOfSyncException

Posts   
 
    
Hong
User
Posts: 9
Joined: 16-Sep-2009
# Posted on: 11-Nov-2009 09:37:57   

I've got the problem with getting ORMEntityOutOfSyncException exception occasionally for a while, even I marked Refetch After Saved to True. I guess it was because I implement thread for save process and the main thread reach the entity's property while the SaveEntity is trying to re-prefetch after saving. So I try to put lock(savingEntity) over SaveEntity call but it didn't solve that.

I finally put <add key="markSavedEntitiesAsFetched" value="true"/> in web.config so no OutOfSync state anymore after saving. It seemed OK for a few days till an hour ago that tester comes to tell me that it still happens disappointed

How can I resolve this ?

Here is the exception I got.

SD.LLBLGen.Pro.ORMSupportClasses.ORMEntityOutOfSyncException occurred
  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.NET20"
  RuntimeBuild="06162009"
  RuntimeVersion="2.6.0.0"

C# .NET 3.5 Adapter

Walaa avatar
Walaa
Support Team
Posts: 14993
Joined: 21-Aug-2005
# Posted on: 11-Nov-2009 09:57:32   

I guess it was because I implement thread for save process and the main thread reach the entity's property while the SaveEntity is trying to re-prefetch after saving.

EntityClasses are not thread safe.

Hong
User
Posts: 9
Joined: 16-Sep-2009
# Posted on: 11-Nov-2009 10:14:10   

Walaa wrote:

I guess it was because I implement thread for save process and the main thread reach the entity's property while the SaveEntity is trying to re-prefetch after saving.

EntityClasses are not thread safe.

So let's focus that what putting

<add key="markSavedEntitiesAsFetched" value="true"/>

web.config actually does then? Since I have no any store proc and trigger etc. so I have no problem with disabling OutOfSync check. Don't this act stop the OutOfSyncException ?

Walaa avatar
Walaa
Support Team
Posts: 14993
Joined: 21-Aug-2005
# Posted on: 11-Nov-2009 10:29:17   

That's true, but the problem might come from that you wouldn't know at which stage does the other thread access the entity in the saving process.

Is there a chance that a thread is trying to access an entity just deleted by the other thread.

Trying to use a deleted entity, will raise the same exception.

Hong
User
Posts: 9
Joined: 16-Sep-2009
# Posted on: 11-Nov-2009 11:05:56   

Walaa wrote:

That's true, but the problem might come from that you wouldn't know at which stage does the other thread access the entity in the saving process.

Is there a chance that a thread is trying to access an entity just deleted by the other thread.

Trying to use a deleted entity, will raise the same exception.

Sounds like even marked that flag, touching the entity in the middle of save process still breaks it ?

Walaa avatar
Walaa
Support Team
Posts: 14993
Joined: 21-Aug-2005
# Posted on: 11-Nov-2009 11:20:19   

Yes.