SaveChangeWithChangeUnitsContext.RecordConstraintConflictForChangeUnit Method

Reports that a constraint conflict occurred when the destination provider tried to apply the change to the destination replica, for a change that contains change units.

Namespace: Microsoft.Synchronization
Assembly: Microsoft.Synchronization (in microsoft.synchronization.dll)

Syntax

'Declaration
Public Sub RecordConstraintConflictForChangeUnit ( _
    changeUnitChange As ChangeUnitChange _
)
'Usage
Dim instance As SaveChangeWithChangeUnitsContext
Dim changeUnitChange As ChangeUnitChange

instance.RecordConstraintConflictForChangeUnit(changeUnitChange)
public void RecordConstraintConflictForChangeUnit (
    ChangeUnitChange changeUnitChange
)
public:
void RecordConstraintConflictForChangeUnit (
    ChangeUnitChange^ changeUnitChange
)
public void RecordConstraintConflictForChangeUnit (
    ChangeUnitChange changeUnitChange
)
public function RecordConstraintConflictForChangeUnit (
    changeUnitChange : ChangeUnitChange
)

Parameters

  • changeUnitChange
    The change unit on the destination replica that conflicts with the change unit to be applied.

Exceptions

Exception type Condition

ArgumentNullException

changeUnitChange is a null reference (Nothing in Visual Basic).

ArgumentException

changeUnitChange is not found in the change to be applied.

SyncInvalidOperationException

A constraint conflict or recoverable error has already been set on this object.

Remarks

A constraint conflict occurs when a destination provider tries to apply a change to the destination replica, and the change violates a constraint of the destination replica. For change units, this typically means that the change violates some business logic on the destination replica. As an example of a business logic conflict, consider a low-fidelity replica that stores two change units: name and country. Also consider a high-fidelity replica that stores three change units: name, state/province, and country. The high-fidelity replica contains business logic that checks the state/province field against the country field, and will not store a change that does not pass the check. The low-fidelity replica acts as the source and sends an item with country set to "USA". The destination provider attempts to apply the change to the high-fidelity replica, but on the high-fidelity replica the item contains "British Columbia" in its state/province field. Therefore, the change violates the business logic and causes a constraint conflict on the change unit that represents the state/province field.

When the destination provider uses this method to report a constraint conflict, the change applier resolves the conflict according to the conflict resolution action set by the application for the specified conflict. The change applier then dispatches any necessary calls to the destination provider so that the destination provider can apply the resolved conflict to the destination replica. For more information, see Detecting and Resolving Constraint Conflicts.

Example

The following example checks whether a change unit can be updated in the destination replica. When the change unit cannot be updated, a constraint conflict is recorded for the change unit.

Case SaveChangeAction.UpdateVersionAndData
    If True Then
        ' Update the item store and metadata store for the specified change unit.
        Try
            Dim cuData As String = DirectCast(context.ChangeData, String())(cuChange.ChangeUnitId.GetByteId())

            If _ContactStore.CanUpdateContact(change.ItemId, cuChange.ChangeUnitId, cuData) Then
                _ContactStore.UpdateContactFromSync(change, cuChange, cuData)
            Else
                context.RecordConstraintConflictForChangeUnit(cuChange)

            End If
        Catch ex As Exception
            Dim errData As New RecoverableErrorData(ex)
            context.RecordRecoverableErrorForChangeUnit(cuChange, errData)
        End Try
        Exit Select
    End If
case SaveChangeAction.UpdateVersionAndData:
{
    // Update the item store and metadata store for the specified change unit.
    try
    {
        string cuData = ((string[])context.ChangeData)[cuChange.ChangeUnitId.GetByteId()];

        if (_ContactStore.CanUpdateContact(change.ItemId, cuChange.ChangeUnitId, cuData))
        {
            _ContactStore.UpdateContactFromSync(change, cuChange, cuData);
        }
        else
        {
            context.RecordConstraintConflictForChangeUnit(cuChange);
        }

    }
    catch (Exception ex)
    {
        RecoverableErrorData errData = new RecoverableErrorData(ex);
        context.RecordRecoverableErrorForChangeUnit(cuChange, errData);
    }
    break;
}

See Also

Reference

SaveChangeWithChangeUnitsContext Class
SaveChangeWithChangeUnitsContext Members
Microsoft.Synchronization Namespace