2015-08-25 24 views
0

我想查询某个特定记录的azure移动服务数据库。我需要查询来查找NotifyDate列等于当前日期的记录。然后从找到的记录中,我想获取记录的Name列中的字符串值,并将其存储在我可以在数据库之外使用的字符串中。需要帮助查询azure移动服务数据库

这是我想出的,但它给我一个错误:

Cannot convert method group 'ToString' to non delegate type 'string'. Did you intend to invoke the method?

在下面一行:

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]; 
} 
+0

这有什么好运气? – Artiom

回答

1

试试下面的代码

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

FindNotifyDate是异步操作。您必须等待完成才能拨打TodoItemToString()。否则在你的例子中,你得到Task作为结果类型,这不是你所期望的。如同上述样品一样,在呼叫完成或等待完成后立即进行同步操作以呼叫ToString()

+1

另外,您应该重命名FindNotifyDate()以FindNotifyDateAsync()遵循C#异步约定。 –

+0

我想你错过了ToString后面的括号。该行应为:string NotifyDate = todoItem.ToString();没有括号,你会得到与原始问题相同的错误。 – WiteCastle

+0

@WiteCastle thx,已修复 – Artiom