Question

In my scenario, I typically put all my database persistence logic in a PersistChangeSet override, since it makes it easier for me to synchronize my save stored procedure wrapper calls involving entities that reference ids in other entities (for example, in case I have an entity A that references a temporary id of -1 in another entity B, I want to be able save entity B first, then update its id reference in entity A with the id returned from the database for entity B).

When one stored procedure returns an error for whatever reason, I just throw a custom exception with the message returned by the stored procedure and leverage the SubmitOperation object's HasError and Error properties on the client side (view model) in order to inform the user what went wrong.

The problem I'm having with the approach just described is that persistence errors rolls back the entire ChangeSet, even if , say, 2 out of 3 "persistence operations" (i.e. calls to stored procedure wrappers) succeed. So, for instance, if I had set a temporary id of -1 for an entity on the client side and then in PersistChangeSet I updated that id to a new value after a successful save to the database, by the time I get back to the SubmitChanges callback that id will have reverted to -1 (because some other entitity failed to save in PersistChangeSet). Ideally, entities that were persisted successfully should be removed from the ChangeSet by the time SubmitChanges completed.

I hope I have described my issue sufficiently well, but feel free to ask for any clarifications. I'm open to suggestions in case the approach I described above is not ideal or otherwise violates the governing principles of RIA.

Thanks in advance for your help!

Was it helpful?

Solution

I resolved this issue by using a TransactionScope in an override of the Submit method in my domain service. This allows the PersistChangeSet to behave as a unit of work (in other words, changes are only persisted if all operations are successful).

Details here: http://msdn.microsoft.com/en-us/library/ee707364(v=vs.91).aspx

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top