DevForce provides asynchronous save functionality for two reasons:
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.
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 |
---|---|---|
Entities | IList<Object> | Returns the entities saved. |
SaveResult | SaveResult | Returns the SaveResult - see SaveResult |
Exception | EntityManagerSaveException | Returns the exception thrown if an error occurred during save processing. |
C# | // 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; }; |
VB | ' Using lambda syntax: myEntityManager.SaveChangesAsync(Sub(op) 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 |