Syncing Azure Mobile Apps with deleted records

45 views Asked by At

I'm working on this sample: https://learn.microsoft.com/en-us/azure/developer/mobile-apps/azure-mobile-apps/quickstarts/xamarin-forms/offline?pivots=vs2022-windows It works, I can add and edit records and its been synced properly to the cloud and when I refresh on a second device the changes are properly updated.

Now I also want to delete records, so I added a delete button to the sample code and when pressed this is called:
await _service.RemoveItemAsync(item);

This also works, the record is deleted from the offline db and also from the cloud.

Unfortunate, on a second device, when I click the refresh button, the deleted record is still there. It is not deleted from the offline db. I have to purge the offline db and only then its synced correctly.

This is the code on the refresh button:

public async Task RefreshItemsAsync()
{
   await InitializeAsync();
    
   // First, push all the items in the table.
   await _table.PushItemsAsync();
    
   // Then, pull all the items in the table.
   await _table.PullItemsAsync();
}

Are there any additional action required on the second device to also remove deleted records?

I found old posts about this saying we must enable softdelete, but this doesn't seem to exist any more in current mobile app?

1

There are 1 answers

0
Adrian Hall On

Soft delete still exists in the current Azure Mobile Apps libraries. You enable it in the table options - something like the following:

[Route("tables/soft")]
[ExcludeFromCodeCoverage(Justification = "Test suite")]
public class SoftController : TableController<EFMovie>
{
    public SoftController(MovieDbContext context) : base()
    {
        Repository = new EntityTableRepository<EFMovie>(context);
        Options = new TableControllerOptions
        {
            EnableSoftDelete = true
        };
    }
}

This is actually from one of the test cases in the source code. Once you enable soft delete and delete some items (only items enabled AFTER soft delete is enabled are affected), the deletions will propagate to the second device on synchronization.