共用方式為


RecoverableErrorReportingContext.RecordConstraintError 方法

記錄嘗試將變更套用至項目時所發生的條件約束錯誤。用來描述與變更發生條件約束衝突的本機項目。

命名空間: Microsoft.Synchronization.SimpleProviders
組件: Microsoft.Synchronization.SimpleProviders (在 microsoft.synchronization.simpleproviders.dll)

語法

'宣告
Public Sub RecordConstraintError ( _
    conflictingItemKey As ItemFieldDictionary _
)
'用途
Dim instance As RecoverableErrorReportingContext
Dim conflictingItemKey As ItemFieldDictionary

instance.RecordConstraintError(conflictingItemKey)
public void RecordConstraintError (
    ItemFieldDictionary conflictingItemKey
)
public:
void RecordConstraintError (
    ItemFieldDictionary^ conflictingItemKey
)
public void RecordConstraintError (
    ItemFieldDictionary conflictingItemKey
)
public function RecordConstraintError (
    conflictingItemKey : ItemFieldDictionary
)

參數

  • conflictingItemKey
    正在記錄條件約束錯誤之項目的索引鍵。

例外

例外狀況型別 條件

ChangeDeferredByProviderException

由於發生條件約束衝突,要套用的變更已被提供者延遲到下一個同步處理工作階段。

SimpleProviderInvalidOperationException

有多項條件約束錯誤、有一項條件約束錯誤是在已經失效的物件上報告的,或是條件約束錯誤原則不允許可復原的條件約束錯誤。

備註

稍後將在同步處理工作階段中重新套用或解決此變更。如需有關條件約束衝突的詳細資訊,請參閱處理簡單提供者的衝突

範例

下列程式碼範例示範 InsertItem 方法的實作,此方法會將插入套用到記憶體中的範例資料存放區。如果無法套用插入,這個方法便會記錄條件約束錯誤。若要在完整應用程式的內容中檢視這段程式碼,請參閱 Sync Framework SDK 及 Code Gallery 中的 "Sync101 using Simple Sync Provider" 應用程式。

public override void InsertItem(object itemData, 
    IEnumerable<SyncId> changeUnitsToCreate,
    RecoverableErrorReportingContext recoverableErrorReportingContext, 
    out ItemFieldDictionary keyAndUpdatedVersion, 
    out bool commitKnowledgeAfterThisItem)
{
    ItemTransfer transfer = (ItemTransfer)itemData;
    ItemData dataCopy = new ItemData(transfer.ItemData);

    // Check for duplicates, and record a constraint error if a duplicate is detected.
    if (!_store.Contains(transfer.Id))
    {
        _store.CreateItem(dataCopy, transfer.Id);
        keyAndUpdatedVersion = _store.CreateItemFieldDictionary(transfer.Id);
    }
    else
    {
        recoverableErrorReportingContext.RecordConstraintError(_store.CreateItemFieldDictionary(transfer.Id));
        keyAndUpdatedVersion = null;
    }
    commitKnowledgeAfterThisItem = false;
}
Public Overrides Sub InsertItem(ByVal itemData As Object, ByVal changeUnitsToCreate As IEnumerable(Of SyncId), ByVal recoverableErrorReportingContext As RecoverableErrorReportingContext, ByRef keyAndUpdatedVersion As ItemFieldDictionary, ByRef commitKnowledgeAfterThisItem As Boolean)
    Dim transfer As ItemTransfer = DirectCast(itemData, ItemTransfer)
    Dim dataCopy As New ItemData(transfer.ItemData)

    ' Check for duplicates, and record a constraint error if a duplicate is detected. 
    If Not _store.Contains(transfer.Id) Then
        _store.CreateItem(dataCopy, transfer.Id)
        keyAndUpdatedVersion = _store.CreateItemFieldDictionary(transfer.Id)
    Else
        recoverableErrorReportingContext.RecordConstraintError(_store.CreateItemFieldDictionary(transfer.Id))
        keyAndUpdatedVersion = Nothing
    End If
    commitKnowledgeAfterThisItem = False
End Sub

請參閱

參考

RecoverableErrorReportingContext 類別
RecoverableErrorReportingContext 成員
Microsoft.Synchronization.SimpleProviders 命名空間