List<MyClass> from awaitable task List<MyClass> from awaitable task sqlite sqlite

List<MyClass> from awaitable task


nPages doesn't exist in the current context....I don't see where I made a mistake.

The first thing to mention is that the declaration of the List<Page> seems backwards.

nPages<List<Page>>=database....

The type has to be written first followed by the variable name.

List<Page> nPagesTask = database...

Another interpretation could be that you have a generic type variable nPages in which you want to specify the generic type. So the compiler looks whether this variable has already been declared. And apparently it cannot find any.

The second thing If you have an async method that returns a Task<string> you could do the following:

public async Task<string>GetStartPageGUID(){    Task<List<Page>> nPagesTask = database.QueryAsync<Page>("SELECT * FROM pages WHERE pageisstartpage=?", true);    List<Page> npages = await nPagesTask;    return nPages.First().GUID;}

Here is the source of the QueryAsync method. this is the signature:

public Task<List<T>> QueryAsync<T> (string query, params object[] args)

so it returns a Task<List<T>>. Since your method specifies a different return type the usual pattern is to await it in a async method as described in the MSDN example and then return the type that you specified in you method.


You have to declare nPages correctly:

List<Page> nPages = database.QueryAsync<Page>("SELECT * FROM pages WHERE pageisstartpage=?", true);