I have a problem using async, and Task.
I have this function:
public async Task<List> Read(int id)
{
using (var db = new SmartFridgeContext())
{
var list = await db.Lists.Include(l => l.ListItems.Select(li => li.Item)).SingleOrDefaultAsync(l => l.ListId == id);
return list;
}
}
Been trying for hours, but I don't know how to get a List
from Task<List>
. What I mean, is that I want the "pure" list back, so I can use it.
Can anyone help?
EDIT:
To clear up confusion, this is a List:
public class List
{
public int ListId { get; set; }
public string ListName { get; set; }
public ICollection<ListItem> ListItems { get; set; }
public List(string listname)
{
ListName = listname;
}
}
I know I will need to await
the Task
, but then I need to declare the function async
. What if I want to call Read(int id)
in Main()?