1

I'm just getting started with Azure Mobile Services, and I'm not sure I understand how soft delete works.

I'm working on Windows console executable that is responsible for populating an Azure mobile database that is synced against an iOS app using Mobile Services sync. It's connecting to the database using Entity Framework.

I've inserted records, and update records, and have them show up on the mobile without a problem. But when I delete the records, they're gone.

I'd have expected the tables to have a trigger in place that would have set the __deleted flag, so that deleting the record would be removed from the iOS app. But that's not happening.

So, how should I delete a record?

Is doing a normal delete the correct procedure, and I need to figure out why the trigger isn't running?

Or should I set the __deleted flag, myself?

Or is there something else entirely, I should be doing?

========= Additional Comments =========

If I understand this, if I set the __delete flag on a record in the azure database, the sync process will delete the matching record in the local database on the mobile.

Will it delete the record after the sync is done?

Or is there some way for me to know that the sync has been done, and it's safe to delete the record?

Or should I just let the delete records accumulate?

1
  • I have set the _deleted = true, and in my database it has been set to true and record is not deleted, but when I sync my iOS device with the service, records are still there in my device, what I am missing here ? Commented Mar 1, 2016 at 5:32

2 Answers 2

2

In order to mark records as deleted when accessing the database directly, you need to set the __deleted flag yourself. There IS a trigger that will set __updatedAt to the time when __deleted was set. That way when your mobile app queries for updates it will see that the record has been deleted.

It's only when you access the data via the Mobile Services REST API that it will translate an HTTP DELETE to setting __deleted for you.

Edit to add response to comments

Yes, when the mobile device syncs the record with __deleted set, it will delete the record off the device.

How long you keep deleted records depends on how many records you're expecting, how many devices are sharing them, and other business requirements you may have for keeping records. The article Adrian linked to has example schedulers for deleting the records for good 30 days after they were soft-deleted.

The article also recommends you have the mobile app periodically purge and re-download the whole data set from the server, to make sure it is not stuck with lingering records that have been deleted for good on the server (e.g. on a device that is used very infrequently compared to the soft-delete period, 30 days in this example).

Sign up to request clarification or add additional context in comments.

2 Comments

Can you look at the additional comments in the question?
@EricHedstrom I have set the _deleted = true, and in my database it has been set to true and record is not deleted, but when I sync my iOS device with the service, records are still there in my device, what I am missing here ?
2

Functionally, soft delete is the same in both Azure Mobile Services and Azure Mobile Apps. The only difference is the column name. You can read a document about Soft Delete in Azure Mobile Services here: https://azure.microsoft.com/en-us/documentation/articles/mobile-services-using-soft-delete/

Soft Delete is a backend feature, so you should not have to do anything in your client to enable it. You do have to change code in your backend though.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.