aherrick
aherrick

Reputation: 20169

Azure Mobile Client - Offline Sync Deleted Data

Trying to better understand how the Mobile Sync Client works with deleted data from the DB.

So I've pulled a list of data objects from my Sync table like this:

public class AzureMobileService
{
    public MobileServiceClient Client { get; private set; }
    private IMobileServiceSyncTable<Debt> debtTable;

    public async Task Initialize()
    {
        if (Client != null)
        {
            return;
        }

        Client = new MobileServiceClient("https://ajhmobile.azurewebsites.net");
        var path = Path.Combine(MobileServiceClient.DefaultDatabasePath, "ajhmobile.db");
        var store = new MobileServiceSQLiteStore(path);
        store.DefineTable<Debt>();
        await Client.SyncContext.InitializeAsync(store, StoreTrackingOptions.NotifyLocalAndServerOperations);
        debtTable = Client.GetSyncTable<Debt>();
    }

    public async Task SyncAsync()
    {
        try
        {
            await Client.SyncContext.PushAsync();

            await debtTable.PullAsync(
                "all",
                this.debtTable.CreateQuery());
        }
        catch (MobileServicePushFailedException exc)
        {
            // handle resolve
        }
    }

    public async Task<List<Debt>> GetAllDebts()
    {
        await Initialize();
        await SyncAsync();
        return await debtTable.ToListAsync();
    }
}

However, if I delete all the Debt data from the DB and a run a Sync Refresh, it's still returning the records, as if its not hitting the API and looking for fresh data.

Is there something I'm not doing correctly or just not understanding how the Sync table should be working?

I would think when I attempt to sync data, if I have records locally but the server no longer has them, it should return no results, correct?

Upvotes: 0

Views: 572

Answers (1)

Eric Hedstrom
Eric Hedstrom

Reputation: 1627

If you delete the records from the database completely, you will also have to purge the data from the table on the device before calling PullAsync() to fetch new records. Normally you would keep the records in place on the server but set the deleted column to 1. Then when the client pulls the updates it sees that those records have been marked deleted.

Upvotes: 1

Related Questions