Print Page | Close Window

save duplicating rows

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=2555
Printed Date: 18-Oct-2025 at 3:24pm


Topic: save duplicating rows
Posted By: hueha
Subject: save duplicating rows
Date Posted: 11-Mar-2011 at 3:48pm
I am having an issue where my row is being saved twice into the database.  I've found the problem occurs when I am asynchronously saving the object in two different ways.  

Background:
I have a foreign key relationship lets say invoice and orders.  On the invoice screen I have a grid to maintain the orders using in place editing.  If I enter an order and then click the save invoice button what happens is the following
1) The row change occurs and it tries to commit the currently edited order to the database asynchronously
2) It tries to save the invoice and its orders.  When I save an invoice I get an entity graph of related objects and call the savechangesasync with this list.
3) I get the callback from the order save
4) I get the callback from the invoice save

As far as I can tell this is a concurrency issue.  Basically at the time of saving both items have key of -100 so they both do an insert into the table.  Is there a way of blocking the second save until the first save is done?  The saving is happening in a separate sandbox so I'm happy to make saves  "single-threaded" within that entity manager.  




Replies:
Posted By: kimj
Date Posted: 18-Mar-2011 at 6:21pm
There's not a way within DevForce to block an action, since DF will allow any actions on the two sandbox editors.  You should be able to use a busy indicator to block the UI, or some sort of signalling or locking within your application.


Posted By: hueha
Date Posted: 18-Mar-2011 at 6:50pm
the problem is that it's part of the same ui action.  They are in a grid and then they click the save button.  The grid loses focus and calls save.  At the same time the button calls a save.


Posted By: kimj
Date Posted: 18-Mar-2011 at 7:02pm

Oh, the two saves are within the same sandbox.  DevForce will allow any concurrent async actions, even though two concurrent saves don't really make a lot of sense.  It's up to the application to provide it's own synchronization.  Can you just set a flag when a save is underway, which you can then check before trying to issue another save?



Posted By: hueha
Date Posted: 20-Mar-2011 at 5:49am
Yeah I was afraid you were going to say that.  I'll have to find a way to get the two view models to communicate now.  Thanks for your help

Hue


Posted By: hueha
Date Posted: 20-Mar-2011 at 7:30pm
Ok that's not working.

This is what is currently happening

In OrderGrid Row update method
1) I set a flag let's say updatingDB = true
2) I call entity manager to save changes on the new row
3) On callback of save I set updating DB = false

In the invoice save I do
1) Check updatingDB
2) if true then sleep and loop to check again 
3) Update invoice

The problem is that while it is executing the loop to check the updatingDB flag the callback for the order row save is never processed.

I tried moving the check to a background thread but then the entity manager save for the invoice complained that it had to be executed on the UI thread.




Print Page | Close Window