0

该项目是一个使用 Sqlite 的 xamarin 形式的测验应用程序,在代码中需要一种加载问题的方法,我将展示他们如何在 Azure 中执行此操作,我需要在 Sqlite 中做同样的事情。我还包含一个指向使用 Azure 的 xamarin 测验的源代码的链接。[1]:https ://github.com/garudaslap/xamarinquiz

    public async Task LoadQuestions()
    {
        IsLoading = true;
        MobileServiceClient client = AppSettings.MobileService;

        IMobileServiceTable<XamarinQuiz> xamarinQuizTable = 
        client.GetTable<XamarinQuiz>();

        try
        {
            QuestionList = await xamarinQuizTable.ToListAsync();
        }
        catch (Exception exc)
        {
        }


        IsLoading = false;
        ChooseNewQuestion();
    }
4

1 回答 1

0

您可以将 SQLite 与此插件一起使用:

https://docs.microsoft.com/en-us/xamarin/xamarin-forms/data-cloud/data/databases

然后您的代码将类似于:

public async Task LoadQuestions()
{
    IsLoading = true;
    SQLiteAsyncConnection connection = new SQLiteAsyncConnection(dbPath);

    // if you need to create the table
    connection.CreateTableAsync<XamarinQuiz>().Wait();

    try
    {
        QuestionList = await database.Table<XamarinQuiz>().ToListAsync();
    }
    catch (Exception exc)
    {
    }


    IsLoading = false;
    ChooseNewQuestion();
}
于 2019-12-04T01:03:24.447 回答