DomainContext.SubmitChanges Method (Action<SubmitOperation>, Object)

[WCF RIA Services Version 1 Service Pack 2 is compatible with either .NET framework 4 or .NET Framework 4.5, and with either Silverlight 4 or Silverlight 5.]

Submits all pending changes to the domain service.

Namespace:  System.ServiceModel.DomainServices.Client
Assembly:  System.ServiceModel.DomainServices.Client (in System.ServiceModel.DomainServices.Client.dll)

Syntax

'Declaration
Public Overridable Function SubmitChanges ( _
    callback As Action(Of SubmitOperation), _
    userState As Object _
) As SubmitOperation
'Usage
Dim instance As DomainContext
Dim callback As Action(Of SubmitOperation)
Dim userState As Object
Dim returnValue As SubmitOperation

returnValue = instance.SubmitChanges(callback, _
    userState)
public virtual SubmitOperation SubmitChanges(
    Action<SubmitOperation> callback,
    Object userState
)
public:
virtual SubmitOperation^ SubmitChanges(
    Action<SubmitOperation^>^ callback, 
    Object^ userState
)
abstract SubmitChanges : 
        callback:Action<SubmitOperation> * 
        userState:Object -> SubmitOperation 
override SubmitChanges : 
        callback:Action<SubmitOperation> * 
        userState:Object -> SubmitOperation 
public function SubmitChanges(
    callback : Action<SubmitOperation>, 
    userState : Object
) : SubmitOperation

Parameters

  • userState
    Type: System.Object
    Optional user state to associate with the operation.

Return Value

Type: System.ServiceModel.DomainServices.Client.SubmitOperation
The submit operation.

Remarks

You use the SubmitChanges method to update, insert, or delete data. All of the pending changes are submitted in one operation. You provide a callback method when you have code that must execute after the asynchronous operation has finished. In the callback method, you can check for errors and update the user interface as needed.

Examples

The following code example shows methods that call the SubmitChanges and RejectChanges methods.

Private Sub SaveButton_Click(ByVal sender As System.Object, ByVal e As System.Windows.RoutedEventArgs)
    _customerContext.SubmitChanges(AddressOf OnSubmitCompleted, Nothing)
End Sub

Private Sub RejectButton_Click(ByVal sender As System.Object, ByVal e As System.Windows.RoutedEventArgs)
    _customerContext.RejectChanges()
    CheckChanges()
End Sub

Private Sub CustomerGrid_RowEditEnded(ByVal sender As System.Object, ByVal e As System.Windows.Controls.DataGridRowEditEndedEventArgs)
    CheckChanges()
End Sub

Private Sub CheckChanges()
    Dim changeSet = _customerContext.EntityContainer.GetChanges()
    ChangeText.Text = changeSet.ToString()

    Dim hasChanges = _customerContext.HasChanges
    SaveButton.IsEnabled = hasChanges
    RejectButton.IsEnabled = hasChanges
End Sub

Private Sub OnSubmitCompleted(ByVal so As SubmitOperation)
    If (so.HasError) Then
        MessageBox.Show(String.Format("Submit Failed: {0}", so.Error.Message))
        so.MarkErrorAsHandled()
    End If
    CheckChanges()
End Sub
private void SaveButton_Click(object sender, RoutedEventArgs e)
{
    _customerContext.SubmitChanges(OnSubmitCompleted, null);
}

private void RejectButton_Click(object sender, RoutedEventArgs e)
{
    _customerContext.RejectChanges();
    CheckChanges();
}

private void CustomerGrid_RowEditEnded(object sender, DataGridRowEditEndedEventArgs e)
{
    CheckChanges();
}

private void CheckChanges()
{
    EntityChangeSet changeSet = _customerContext.EntityContainer.GetChanges();
    ChangeText.Text = changeSet.ToString();

    bool hasChanges = _customerContext.HasChanges;
    SaveButton.IsEnabled = hasChanges;
    RejectButton.IsEnabled = hasChanges;
}

private void OnSubmitCompleted(SubmitOperation so)
{
    if (so.HasError)
    {
        MessageBox.Show(string.Format("Submit Failed: {0}", so.Error.Message));
        so.MarkErrorAsHandled();
    }
    CheckChanges();
}

See Also

Reference

DomainContext Class

SubmitChanges Overload

System.ServiceModel.DomainServices.Client Namespace