Up Save
DevForce 2010 Resource Center » DevForce development » Save » Perform a save asynchronously

Perform a save asynchronously

Last modified on August 15, 2012 17:20

DevForce provides asynchronous save functionality for two reasons:  

  • Firstly, the Silverlight and WP7 CLR (common language runtime) environments do not permit synchronous web service calls.
  • Secondly, even in those environments where synchronous API's are supported, there are use cases where an asynchronous save can be useful.

While an overview of asynchonous programming in DevForce is also available; the remainder of this topic discusses the specific asynchronous API's provided in the context of saving.

EntitySaveOperation and EntitySavedEventArgs

The return value from any call to one of the EntityManager.SaveChangesAsync overloads is an instance of an EntitySaveOperation. This operation result can be either be accessed directly within the method's callback logic or via the operation's Completed event.  In the case of the Completed event; the event delegate gets passed a EntitySavedEventArgs parameter.

Regardless of whether you are working with an EntitySaveOperation or an EntitySavedEventArgs, the following readonly properties are provided in addition to those inherited from the BaseOperation or AsyncEventArgs base classes. Please see Asynchronous Programming for more detail on the 'standard' DevForce asynchronous model and the properties available there. The following discussion is only about those additional properties that are available during an asynchonous save. 

Property Property Type  Description
EntitiesIList<Object>Returns the entities saved.
SaveResultSaveResultReturns the SaveResult - see SaveResult
ExceptionEntityManagerSaveExceptionReturns the exception thrown if an error occurred during save processing.


// Using lambda syntax:                                       
myEntityManager.SaveChangesAsync(op => {
  var savedEntities = op.Entities;
  var sr            = op.SaveResult;
  var error         = op.Exception;

// Using Completed event syntax:
var op = myEntityManager.SaveChangesAsync()
op.Completed += (sender, eventArgs) => {
  var savedEntities = eventArgs.Entities;
  var sr            = eventArgs.SaveResult;
  var error         = eventArgs.Exception;
' Using lambda syntax:
                                    Dim savedEntities = op.Entities
                                    Dim sr = op.SaveResult
                                    Dim err = op.Exception
                                End Sub)

' Using Completed event syntax:
AddHandler Dim op = myEntityManager.SaveChangesAsync() _
    op.Completed, Sub(sender, eventArgs)
                   Dim savedEntities = eventArgs.Entities
                   Dim sr = eventArgs.SaveResult
                   Dim err = eventArgs.Exception
                  End Sub


Created by DevForce on February 19, 2011 23:55

This wiki is licensed under a Creative Commons 2.0 license. XWiki Enterprise 3.2 - Documentation. Copyright © 2015 IdeaBlade