報告當目的地提供者嘗試將變更套用至目的地複寫時發生了衝突,並且指定發生衝突之目的地項目的項目識別碼。
命名空間: 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
與要套用之變更發生衝突之目的地項目的項目識別碼。
- 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 命名空間