SaveChangeContext.RecordConstraintConflictForItem 方法 (SyncId, ConstraintConflictReason)
报告在目标提供程序尝试将变更应用于目标副本时出现了约束冲突,并指定发生冲突的目标项的项 ID。
命名空间: Microsoft.Synchronization
程序集: Microsoft.Synchronization(在 microsoft.synchronization.dll 中)
语法
声明
Public Sub RecordConstraintConflictForItem ( _
conflictingItemId As SyncId, _
reason As ConstraintConflictReason _
)
用法
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
)
参数
- conflictingItemId
与要应用的变更发生冲突的目标项的项 ID。
- reason
发生冲突的原因。
异常
异常类型 | 条件 |
---|---|
conflictingItemId 为 null 引用(在 Visual Basic 中为 Nothing)。 |
|
已对此对象设置约束冲突或可恢复错误。 |
示例
以下示例检查是否可在项存储区中创建新项。如果无法创建项,则记录一个约束冲突。此示例代码摘自 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;
}
请参阅
参考
SaveChangeContext 类
SaveChangeContext 成员
Microsoft.Synchronization 命名空间