Export (0) Print
Expand All

SimpleSyncProvider.DeleteItem Method

When overridden in a derived class, called by the Sync Framework runtime to delete an item from the destination store.

Namespace:  Microsoft.Synchronization.SimpleProviders
Assembly:  Microsoft.Synchronization.SimpleProviders (in Microsoft.Synchronization.SimpleProviders.dll)

public abstract void DeleteItem(
	ItemFieldDictionary keyAndExpectedVersion,
	RecoverableErrorReportingContext recoverableErrorReportingContext,
	out bool commitKnowledgeAfterThisItem


Type: Microsoft.Synchronization.SimpleProviders.ItemFieldDictionary
The key and expected version properties of the item to be deleted. The provider must perform an optimistic concurrency check to verify that the version of the item on the destination corresponds to the values found in keyAndExpectedVersion. If this check fails, provider should report a recoverable error by using a RecoverableErrorReportingContext object.
Type: Microsoft.Synchronization.SimpleProviders.RecoverableErrorReportingContext
A RecoverableErrorReportingContext object that is used to report recoverable errors that occur during attempts to delete an item.
Type: System.Boolean%
Returns whether the Sync Framework runtime should commit knowledge to the metadata store after processing is complete for the specified item.

After Sync Framework has detected and loaded changes from the source, it must apply those changes and corresponding metadata changes to the destination replica. Metadata changes at the destination are handled by Sync Framework, but applying data changes is store-specific and is handled by implementing the following methods: DeleteItem, InsertItem, and UpdateItem.

The following code example shows an implementation of this method that applies deletes to an in-memory sample data store. To view this code in the context of a complete application, see the "Sync101 using Simple Sync Provider" application that is available in the Sync Framework SDK and from Code Gallery.

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))
        // 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
        ' 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

© 2014 Microsoft