SaveChangeContext.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 SaveChangeContext
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
)
public void RecordConstraintConflictForItem (
SyncId conflictingItemId,
ConstraintConflictReason reason
)
public function RecordConstraintConflictForItem (
conflictingItemId : SyncId,
reason : ConstraintConflictReason
)
Parameters
- conflictingItemId
The item ID of the destination item that conflicts with the change to be applied.
- reason
The reason the conflict occurred.
Exceptions
Exception type | Condition |
---|---|
conflictingItemId is a null reference (Nothing in Visual Basic). |
|
A constraint conflict or recoverable error has already been set on this object. |
Example
The following example checks whether a new item can be created in the item store. If the item cannot be created, a constraint conflict is recorded. The example code is taken from an implementation of SaveChangeWithChangeUnits.
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
SaveChangeContext Class
SaveChangeContext Members
Microsoft.Synchronization Namespace