注销时如何清除 sqlite 数据库

4
我正在使用Xamarin Forms和WindowsAzure.MobileServices.SQLiteStore NuGet来处理我的sqlite数据库和azure数据库之间的同步。一切正常,但是当我想注销用户时,我想清除数据库。这样,在下次登录时,它将再次生成数据库并从零开始同步。 我尝试过清空表格,但这只会删除本地数据,当您重新登录时,它只会同步任何新数据。
目前,我的dispose如下:
// Globally declared and initialized in my init() method
MobileServiceSQLiteStore store { get; set; }
public MobileServiceClient MobileService { get; set; }

public async Task Dispose()
{
    try
    {
        initialized = false;

        // await this.userTable.PurgeAsync<AzureUser>("CleanUsers", this.userTable.CreateQuery(), CancellationToken.None);

        store.Dispose();
        MobileService.Dispose();

        store = null;
        MobileService = null;
    }
    catch (Exception ex)
    {
        throw ex;
    }
}

请问我如何使用这个组件在注销时清理我的sqlite数据库?谢谢!


你尝试过在清除数据后强制同步吗?可以在 PurgeAsync() 后加上 await MobileService.SyncContext.PushAsync(); 进行同步。 - hvaughan3
@hvaughan3 用户重新登录后,再次进行同步,但是已清除的数据不会被同步,只有新记录会被同步。 - Orlando
1个回答

4
如果你想清除所有项目,请使用以下命令:
this.userTable.PurgeAsync(null, null, true, CancellationToken.None);

查看代码


2
这是一个示例:https://github.com/lindydonna/ContosoMoments/blob/dev/src/Mobile/ContosoMoments/App.cs#L132 - lindydonna
抱歉,我刚看到这个消息,因为我的优先事项发生了变化。purgeAsync方法清理本地数据库,但当用户再次登录时,它仅同步在Azure中添加的新行,而不是之前清除的行...你有任何想法为什么会发生这种情况吗? - Orlando

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接