Reputation: 351
I am trying to query an azure mobile service database for a specific record. I need the query to find the record whose NotifyDate
column equals the current date. Then from the record that is found, I want to take the string value that is in the record's Name
column and store it in a string that I can use outside of the database.
This is what I've come up with, but it is giving me an error:
Cannot convert method group 'ToString' to non delegate type 'string'. Did you intend to invoke the method?
At the following line:
string NotifyDate = FindNotifyDate().ToString;
Is there a better way that you can think of to do this?
Current Code:
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];
}
Upvotes: 0
Views: 66
Reputation: 7847
try the following code
protected void async Application_Start()
{
WebApiConfig.Register();
var todoItem = await FindNotifyDate();
string NotifyDate = todoItem.ToString();
}
FindNotifyDate
is async operation. You have to wait for it's completion in order to call ToString()
of TodoItem
. Otherwise in your example you get Task as result type and it's not what you were expecting. Make it sync operation to call ToString()
immediately after call or wait for completion as in above sample.
Upvotes: 1