วันพฤหัสบดีที่ 10 พฤษภาคม พ.ศ. 2555

DomainContext.SubmitChanges Method

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.
This member is overloaded. For complete information about this member, including syntax, usage, and examples, click a name in the overload list.


NameDescription
Public methodSubmitChanges()Submits all pending changes to the domain service.
Public methodSubmitChanges(Action<SubmitOperation>, Object)Submits all pending changes to the domain service.



public virtual SubmitOperation SubmitChanges(
Action<SubmitOperation> callback,
Object userState
)

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.

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

ไม่มีความคิดเห็น:

แสดงความคิดเห็น