Compartilhar via


SubmitOperation Class

[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.]

Represents an asynchronous submit operation.

Inheritance Hierarchy

System.Object
  System.ServiceModel.DomainServices.Client.OperationBase
    System.ServiceModel.DomainServices.Client.SubmitOperation

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

Syntax

'Declaration
Public NotInheritable Class SubmitOperation _
    Inherits OperationBase
'Usage
Dim instance As SubmitOperation
public sealed class SubmitOperation : OperationBase
public ref class SubmitOperation sealed : public OperationBase
[<SealedAttribute>]
type SubmitOperation =  
    class
        inherit OperationBase
    end
public final class SubmitOperation extends OperationBase

The SubmitOperation type exposes the following members.

Properties

  Name Description
Public property CanCancel Gets a value that indicates whether this OperationBase is currently in a state that enables it to be canceled. (Inherited from OperationBase.)
Public property ChangeSet Gets change set being submitted.
Public property EntitiesInError Gets any entities that have errors after the submit operation completes.
Public property Error Gets the operation error if the operation failed. (Inherited from OperationBase.)
Public property HasError Gets a value that indicates whether the operation failed. (Inherited from OperationBase.)
Public property IsCanceled Gets a value that indicates whether this operation has been canceled. (Inherited from OperationBase.)
Public property IsComplete Gets a value that indicates whether this operation has completed. (Inherited from OperationBase.)
Public property IsErrorHandled Gets or sets a value that indicates whether the operation error has been handled. (Inherited from OperationBase.)
Protected property Result Gets the result of the asynchronous operation. (Inherited from OperationBase.)
Protected property SupportsCancellation Gets a value that indicates whether this operation supports cancellation. (Inherited from OperationBase.)
Public property UserState Gets the optional user state for this operation. (Inherited from OperationBase.)

Top

Methods

  Name Description
Public method Cancel Cancels the operation. (Inherited from OperationBase.)
Protected method CancelCore When overridden in a derived class, provides the logic to cancel the operation. (Inherited from OperationBase.)
Protected method Complete(Exception) Completes a failed operation with the specified error. (Inherited from OperationBase.)
Protected method Complete(Object) Completes a successful operation with the specified result. (Inherited from OperationBase.)
Public method Equals (Inherited from Object.)
Protected method Finalize (Inherited from Object.)
Public method GetHashCode (Inherited from Object.)
Public method GetType (Inherited from Object.)
Protected method InvokeCompleteAction Invokes the completion callback. (Inherited from OperationBase.)
Public method MarkErrorAsHandled Specifies that an error encountered in an operation is handled. (Inherited from OperationBase.)
Protected method MemberwiseClone (Inherited from Object.)
Protected method OnPropertyChanged Called when the value of a property changes. (Inherited from OperationBase.)
Protected method RaisePropertyChanged Raises the System#ComponentModel#INotifyPropertyChanged#PropertyChanged() event. (Inherited from OperationBase.)
Public method ToString (Inherited from Object.)

Top

Events

  Name Description
Public event Completed Occurs when the operation completes. (Inherited from OperationBase.)

Top

Explicit Interface Implementations

  Name Description
Explicit interface implemetationPrivate event INotifyPropertyChanged.PropertyChanged Occurs when a property value changes. (Inherited from OperationBase.)

Top

Examples

The following example shows a callback method named OnSubmitCompleted that accepts a SubmitOperation object as a parameter. It uses this object to check for errors and mark the errors as handled.

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();
}

Thread Safety

Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.

See Also

Reference

System.ServiceModel.DomainServices.Client Namespace