Print Page | Close Window

Caching of entities to be saved

Printed From: IdeaBlade
Category: DevForce
Forum Name: DevForce 2010
Forum Discription: For .NET 4.0
URL: http://www.ideablade.com/forum/forum_posts.asp?TID=3249
Printed Date: 13-May-2026 at 12:42pm


Topic: Caching of entities to be saved
Posted By: cocog
Subject: Caching of entities to be saved
Date Posted: 02-Feb-2012 at 8:26am
Our SL screen will allow the user to create new Owner entities.  The owner entity has an identity column for it's primary key in the database.  We also capture the time the entity was instantiated by the entity manager (e.g. when the class was created, not saved to the db).  We save all additions/modification using "SaveChangesAsync."  

Occasionally, we will get records in the database that show the records are not saved in the order they were created.  For example:

Owner 1 (created first):
ID: 1001
Instantiated: 10:02 AM

Owner 2 (created second):
ID: 1000
Instantiated: 10:05 AM

SaveChangesAsync was called after each owner was created. 

Why would Owner 1 not be saved to the db until after Owner 2, 3 minutes later?




Replies:
Posted By: DenisK
Date Posted: 02-Feb-2012 at 1:19pm
Hi cocog,

The order in which asynchronous operations execute and complete is non-deterministic. If you want to control the save order in SL, you can:

1. Do Option 2 as suggested here.  http://drc.ideablade.com/xwiki/bin/view/Documentation/save-order - http://drc.ideablade.com/xwiki/bin/view/Documentation/save-order

2. Or use Serial Coroutine to suspend the second SaveChangesAsync call until the first one completes. See  http://drc.ideablade.com/xwiki/bin/view/Documentation/coroutines - http://drc.ideablade.com/xwiki/bin/view/Documentation/coroutines

Hope this answers your questions.



Print Page | Close Window