Search code examples
sqliteazurexamarinsoft-delete

query soft deleted records in an Azure mobile app easy table


I have a Azure mobile Easy Table Xamarin App that is a bunch of lists, reminders for myself. It works fine to add, update and delete. I want to be able to get a list of soft deleted items so I can undelete some to add them back into a list without retyping them. I cannot figure out how to do this. I see in Google searches an IncludeDeleted attribute but it does not seem to apply to the IMobileServiceSyncTable table I am using. Here is the code, but it retrieves zero records. If I run it in LinqPad 5 I get all the soft deleted records.

public async Task<IEnumerable<ListData>> GetDeletedItemsAsync()
    {
        await InitializeClient();
        await SyncItems();

        try
        { 
            IEnumerable<ListData> items = await listdata
                .Where(listdata => listdata.Deleted == true )
                .ToEnumerableAsync();

            return new ObservableCollection<ListData>(items);
        }
        catch (MobileServiceInvalidOperationException msioe)
        {
            Debug.WriteLine(@"Invalid sync operation: {0}", msioe.Message);
        }
        catch (Exception e)
        {
            Debug.WriteLine(@"Sync error: {0}", e.Message);
        }
        return null;

    }

Here is the Class:

public class ListData
{
    public string id { get; set; }
    [JsonProperty(PropertyName = "listname")]
    public string ListName { get; set; }
    [JsonProperty(PropertyName = "itemdata")]
    public string ItemData { get; set; }
    [JsonProperty(PropertyName = "itemdetail")]
    public string ItemDetail { get; set; }
    [JsonProperty(PropertyName = "deleted")]
    public Boolean Deleted { get; set; }
    // *** Enable Optimistic Concurrency *** //
    [Version]
    public string Version { get; set; }
}

What am I missing? Thanks.


Solution

  • The way to do this is to go directly to the server using an IMobileServiceTable object. It is pretty simple. You can then use the IncludeDeleted directive on the query. Case solved.