Share via


ChangeOperation Enumeration

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

Specifies the change operations that can be performed on an object.

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

Syntax

'Declaration
Public Enumeration ChangeOperation
'Usage
Dim instance As ChangeOperation
public enum ChangeOperation
public enum class ChangeOperation
type ChangeOperation
public enum ChangeOperation

Members

Member name Description
None No change operation to perform.
Insert An insert operation.
Update An update operation.
Delete A delete operation.

Examples

<EnableClientAccess()>
Public Class CustomerDomainService
    Inherits LinqToEntitiesDomainService(Of AdventureWorksLTEntities)

    Public Function GetCustomers() As IQueryable(Of Customer)
        Return Me.ObjectContext.Customers
    End Function

    Public Function c(ByVal customer As Customer, ByVal address As CustomerAddress)
        Return address
    End Function

    Public Function UpdateCustomer(ByVal currentCustomer As Customer)
        If currentCustomer <> Nothing Then
            Me.ObjectContext.Customers.AttachAsModified(currentCustomer, Me.ChangeSet.GetOriginal(currentCustomer))
        Else
            Me.ObjectContext.Attach(currentCustomer)
        End If

        For Each address As CustomerAddress In ChangeSet.GetAssociatedChanges(currentCustomer, c)
            Select Case (operation)
                Case ChangeOperation.Insert
                    ObjectContext.Detach(address)
                    address.EntityKey = Nothing
                    ObjectContext.AddToCustomerAddresses(address)
                    break()
                Case ChangeOperation.Update
                    ObjectContext.Attach(address)
                    break()
                Case ChangeOperation.Delete
                    ObjectContext.DeleteObject(address)
                    break()
                Case Else
                    break()
            End Select
        Next
    End Function

End Class
public void UpdateCustomer(Customer currentCustomer)
{
    if (currentCustomer != null)
    {
        this.ObjectContext.Customers.AttachAsModified(currentCustomer, this.ChangeSet.GetOriginal(currentCustomer));
    }
    else
    {
        this.ObjectContext.Attach(currentCustomer);
    }

    foreach(CustomerAddress address in ChangeSet.GetAssociatedChanges(currentCustomer, c => c.CustomerAddresses))
    {
        ChangeOperation operation = ChangeSet.GetChangeOperation(address);

        switch (operation)
        {
            case ChangeOperation.Insert:
                ObjectContext.Detach(address);
                address.EntityKey = null;
                ObjectContext.AddToCustomerAddresses(address);
                break;
            case ChangeOperation.Update:
                ObjectContext.Attach(address);
                break;
            case ChangeOperation.Delete:
                ObjectContext.DeleteObject(address);
                break;
            default:
                break;
        }
    }
}

See Also

Reference

System.ServiceModel.DomainServices.Server Namespace