sdk/dotnet/src/Microsoft.Datasync.Client/Offline/SyncContext.cs
/// <summary>
/// Deletes all the items in the offline table that match the query.
/// </summary>
/// <param name="tableName">The name of the offline table.</param>
/// <param name="query">An OData query that determines which items to delete.</param>
/// <param name="options">The options used to configure the purge operation.</param>
/// <param name="cancellationToken">A <see cref="CancellationToken"/> to observe.</param>
/// <returns>A task that completes when the purge operation has finished.</returns>
Deletes all the items in the offline table that match the query.
Deletes all the items in the offline table that match the query .
public async Task PurgeItemsAsync(string tableName, string query, PurgeOptions options, CancellationToken cancellationToken = default)
        {
            Arguments.IsValidTableName(tableName, nameof(tableName));
            Arguments.IsNotNull(query, nameof(query));
            Arguments.IsNotNull(options, nameof(options));
            EnsureContextIsInitialized();
            var queryId = options.QueryId ?? GetQueryIdFromQuery(tableName, query);
            var queryDescription = QueryDescription.Parse(tableName, query);
            using (await tableLock.AcquireAsync(tableName, cancellationToken).ConfigureAwait(false))
            {
                if (await TableIsDirtyAsync(tableName, cancellationToken).ConfigureAwait(false))
                {
                    if (options.DiscardPendingOperations)
                    {
                        await DiscardTableOperationsAsync(tableName, cancellationToken).ConfigureAwait(false);
                    }
                    else
                    {
                        throw new InvalidOperationException("The table cannot be purged because it has pending operations.");
                    }
                }
                using (await queueLock.WriterLockAsync(cancellationToken).ConfigureAwait(false))
                {
                    if (!string.IsNullOrEmpty(queryId))
                    {
                        await DeltaTokenStore.ResetDeltaTokenAsync(tableName, queryId, cancellationToken).ConfigureAwait(false);
                    }
                    await OfflineStore.DeleteAsync(queryDescription, cancellationToken).ConfigureAwait(false);
                }
            }
        }
public async Task PurgeItemsAsync ( string tableName , string query , PurgeOptions options , CancellationToken cancellationToken = default ) { Arguments . IsValidTableName ( tableName , nameof ( tableName ) ) ; Arguments . IsNotNull ( query , nameof ( query ) ) ; Arguments . IsNotNull ( options , nameof ( options ) ) ; EnsureContextIsInitialized ( ) ; var queryId = options . QueryId ?? GetQueryIdFromQuery ( tableName , query ) ; var queryDescription = QueryDescription . Parse ( tableName , query ) ; using ( await tableLock . AcquireAsync ( tableName , cancellationToken ) . ConfigureAwait ( false ) ) { if ( await TableIsDirtyAsync ( tableName , cancellationToken ) . ConfigureAwait ( false ) ) { if ( options . DiscardPendingOperations ) { await DiscardTableOperationsAsync ( tableName , cancellationToken ) . ConfigureAwait ( false ) ; } else { throw new InvalidOperationException ( " " ) ; } } using ( await queueLock . WriterLockAsync ( cancellationToken ) . ConfigureAwait ( false ) ) { if ( ! string . IsNullOrEmpty ( queryId ) ) { await DeltaTokenStore . ResetDeltaTokenAsync ( tableName , queryId , cancellationToken ) . ConfigureAwait ( false ) ; } await OfflineStore . DeleteAsync ( queryDescription , cancellationToken ) . ConfigureAwait ( false ) ; } } }
Deletes all the items in the offline table that match the query.
Deletes all the items in the offline table that match the query .
// Execute the purge
A task that completes when the purge operation has finished.
A task that completes when the purge operation has finished .
tableName
string
The name of the offline table.
The name of the offline table .
query
string
An OData query that determines which items to delete.
An OData query that determines which items to delete .
options
PurgeOptions
The options used to configure the purge operation.
The options used to configure the purge operation .
cancellationToken
CancellationToken
A  to observe.
A to observe .