Share via


SaveChangeWithChangeUnitsContext.RecordConstraintConflictForItem Method (SyncId, ConstraintConflictReason)

Reports that a constraint conflict occurred when the destination provider tried to apply the change to the destination replica, and specifies the item ID of the destination item that is in conflict.

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

Syntax

'Declaration
Public Sub RecordConstraintConflictForItem ( _
    conflictingItemId As SyncId, _
    reason As ConstraintConflictReason _
)
'Usage
Dim instance As SaveChangeWithChangeUnitsContext
Dim conflictingItemId As SyncId
Dim reason As ConstraintConflictReason

instance.RecordConstraintConflictForItem(conflictingItemId, _
    reason)
public void RecordConstraintConflictForItem(
    SyncId conflictingItemId,
    ConstraintConflictReason reason
)
public:
void RecordConstraintConflictForItem(
    SyncId^ conflictingItemId, 
    ConstraintConflictReason reason
)
member RecordConstraintConflictForItem : 
        conflictingItemId:SyncId * 
        reason:ConstraintConflictReason -> unit 
public function RecordConstraintConflictForItem(
    conflictingItemId : SyncId, 
    reason : ConstraintConflictReason
)

Parameters

Exceptions

Exception Condition
ArgumentNullException

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

SyncInvalidOperationException

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

Examples

The following example shows how to report a constraint conflict that is caused when a new item is created in the destination replica.

Case SaveChangeAction.Create
    If True Then
        ' Create a new item. Report a constraint conflict if one occurs.
        Try
            Dim constraintReason As ConstraintConflictReason
            Dim conflictingItemId As SyncId = Nothing
            ' Check if the item can be created or if it causes a constraint conflict.
            If _ContactStore.CanCreateContact(change, DirectCast(context.ChangeData, String()), constraintReason, conflictingItemId) Then
                ' No conflict, so create the item.
                _ContactStore.CreateContactFromSync(change, DirectCast(context.ChangeData, String()))
            Else
                ' A constraint conflict occurred, so report this to the change applier.
                context.RecordConstraintConflictForItem(conflictingItemId, constraintReason)
            End If
        Catch ex As Exception
            ' Some other error occurred, so exclude this item for the rest of the session.
            Dim errData As New RecoverableErrorData(ex)
            context.RecordRecoverableErrorForItem(errData)
        End Try
        Exit Select
    End If
case SaveChangeAction.Create:
{
    // Create a new item. Report a constraint conflict if one occurs.
    try
    {
        ConstraintConflictReason constraintReason;
        SyncId conflictingItemId;
        // Check if the item can be created or if it causes a constraint conflict.
        if (_ContactStore.CanCreateContact(change, (string[])context.ChangeData, out constraintReason, out conflictingItemId))
        {
            // No conflict, so create the item.
            _ContactStore.CreateContactFromSync(change, (string[])context.ChangeData);
        }
        else
        {
            // A constraint conflict occurred, so report this to the change applier.
            context.RecordConstraintConflictForItem(conflictingItemId, constraintReason);
        }
    }
    catch (Exception ex)
    {
        // Some other error occurred, so exclude this item for the rest of the session.
        RecoverableErrorData errData = new RecoverableErrorData(ex);
        context.RecordRecoverableErrorForItem(errData);
    }
    break;
}

See Also

Reference

SaveChangeWithChangeUnitsContext Class

RecordConstraintConflictForItem Overload

Microsoft.Synchronization Namespace