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.
Assembly: Microsoft.Synchronization (in Microsoft.Synchronization.dll)
public: void RecordConstraintConflictForItem( SyncId^ conflictingItemId, ConstraintConflictReason reason )
Parameters
- conflictingItemId
- Type: Microsoft.Synchronization::SyncId
The item ID of the destination item that conflicts with the change to be applied.
- reason
- Type: Microsoft.Synchronization::ConstraintConflictReason
The reason the conflict occurred.
| Exception | Condition |
|---|---|
| ArgumentNullException | conflictingItemId is a nullptr. |
| SyncInvalidOperationException | A constraint conflict or recoverable error has already been set on this object. |
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; }
Show: