共用方式為


DeleteItem 方法

在衍生類別中覆寫時,由 Sync Framework 執行階段呼叫,以便從目的地存放區中刪除項目。

命名空間:  Microsoft.Synchronization.SimpleProviders
組件:  Microsoft.Synchronization.SimpleProviders (在 Microsoft.Synchronization.SimpleProviders.dll 中)

語法

'宣告
Public MustOverride Sub DeleteItem ( _
    keyAndExpectedVersion As ItemFieldDictionary, _
    recoverableErrorReportingContext As RecoverableErrorReportingContext, _
    <OutAttribute> ByRef commitKnowledgeAfterThisItem As Boolean _
)
'用途
Dim instance As SimpleSyncProvider
Dim keyAndExpectedVersion As ItemFieldDictionary
Dim recoverableErrorReportingContext As RecoverableErrorReportingContext
Dim commitKnowledgeAfterThisItem As Boolean

instance.DeleteItem(keyAndExpectedVersion, _
    recoverableErrorReportingContext, _
    commitKnowledgeAfterThisItem)
public abstract void DeleteItem(
    ItemFieldDictionary keyAndExpectedVersion,
    RecoverableErrorReportingContext recoverableErrorReportingContext,
    out bool commitKnowledgeAfterThisItem
)
public:
virtual void DeleteItem(
    ItemFieldDictionary^ keyAndExpectedVersion, 
    RecoverableErrorReportingContext^ recoverableErrorReportingContext, 
    [OutAttribute] bool% commitKnowledgeAfterThisItem
) abstract
abstract DeleteItem : 
        keyAndExpectedVersion:ItemFieldDictionary * 
        recoverableErrorReportingContext:RecoverableErrorReportingContext * 
        commitKnowledgeAfterThisItem:bool byref -> unit 
public abstract function DeleteItem(
    keyAndExpectedVersion : ItemFieldDictionary, 
    recoverableErrorReportingContext : RecoverableErrorReportingContext, 
    commitKnowledgeAfterThisItem : boolean
)

參數

  • commitKnowledgeAfterThisItem
    型別:System. . :: . .Boolean%
    傳回 Sync Framework 執行階段是否應該在指定之項目的處理完成之後,將知識認可至中繼資料存放區。

備註

在 Sync Framework 偵測到來源中的變更並加以載入後,它必須將這些變更和對應的中繼資料變更套用到目的地複寫。目的地的中繼資料變更是由 Sync Framework 所處理,但是套用資料變更是存放區特定的動作,而且會藉由實作下列方法:DeleteItem、InsertItemUpdateItem 來加以處理。

範例

下列程式碼範例示範這個方法的實作,此方法會將刪除套用到記憶體中的範例資料存放區。若要在完整應用程式的內容中檢視這段程式碼,請參閱 Sync Framework SDK 及 Code Gallery 中的 "Sync101 using Simple Sync Provider" 應用程式。

public override void DeleteItem(ItemFieldDictionary keyAndExpectedVersion, 
    RecoverableErrorReportingContext recoverableErrorReportingContext, 
    out bool commitKnowledgeAfterThisItem)
{
    IDictionary<uint, ItemField> expectedFields = (IDictionary<uint, ItemField>)keyAndExpectedVersion;
    ulong id = (ulong)expectedFields[CUSTOM_FIELD_ID].Value;
    if (_store.Contains(id))
    {
        _store.DeleteItem(id);
    }
    else
    {
        // If the item to delete does not exist, record an error on this change and 
        // continue with the rest of the session.
        recoverableErrorReportingContext.RecordRecoverableErrorForChange(new RecoverableErrorData(new Exception("Item not found in the store")));
    }
    commitKnowledgeAfterThisItem = false;
}
Public Overrides Sub DeleteItem(ByVal keyAndExpectedVersion As ItemFieldDictionary, ByVal recoverableErrorReportingContext As RecoverableErrorReportingContext, ByRef commitKnowledgeAfterThisItem As Boolean)
    Dim expectedFields As IDictionary(Of UInteger, ItemField) = DirectCast(keyAndExpectedVersion, IDictionary(Of UInteger, ItemField))
    Dim id As ULong = CULng(expectedFields(CUSTOM_FIELD_ID).Value)
    If _store.Contains(id) Then
        _store.DeleteItem(id)
    Else
        ' If the item to delete does not exist, record an error on this change and 
        ' continue with the rest of the session. 
        recoverableErrorReportingContext.RecordRecoverableErrorForChange(New RecoverableErrorData(New Exception("Item not found in the store")))
    End If
    commitKnowledgeAfterThisItem = False
End Sub

請參閱

參考

SimpleSyncProvider類別

SimpleSyncProvider 成員

Microsoft.Synchronization.SimpleProviders 命名空間