簡體   English   中英

需要幫助查詢Azure移動服務數據庫

[英]Need help querying azure mobile service database

我正在嘗試查詢azure移動服務數據庫的特定記錄。 我需要查詢來查找其NotifyDate列等於當前日期的記錄。 然后,從找到的記錄中,我要獲取記錄的“ Name列中的字符串值,並將其存儲在可以在數據庫外部使用的字符串中。

這是我想出的,但給我一個錯誤:

無法將方法組“ ToString”轉換為非委托類型“ string”。 您是否打算調用該方法?

在以下行:

string NotifyDate = FindNotifyDate().ToString;

有沒有更好的方法可以想到呢?

當前代碼:

private IMobileServiceTable<TodoItem> todoTable =
 MobileService.GetTable<TodoItem>();

private MobileServiceCollection<TodoItem, TodoItem> items;
private List<TodoItem> notifyItems;

protected void Application_Start()
{
    WebApiConfig.Register();
    string NotifyDate = FindNotifyDate().ToString;
}

public async Task<TodoItem> FindNotifyDate()
{
    DateTime test = DateTime.Now;
    test = test.AddMilliseconds(-test.Millisecond);
    notifyItems = await todoTable.Where(todoItem => todoItem.NotifyDate == test)
                                 .ToListAsync();
    return notifyItems[0];
}

試試下面的代碼

    protected void async Application_Start()
    {
        WebApiConfig.Register();
        var todoItem = await FindNotifyDate();
        string NotifyDate = todoItem.ToString();
    }

FindNotifyDate是異步操作。 您必須等待其完成才能調用TodoItem ToString() 否則,在您的示例中,您將Task作為結果類型,而不是您所期望的。 使它同步操作以在調用之后立即調用ToString()或等待完成,如上面的示例中所示。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM