How do I Lazy
load the Bars collection using async-await
? It must take an Id from the MyClass instance to get the specific collection back.
public class MyClass {
public int Id { get; set; }
public Lazy<List<Bar>> Bars { get; private set; }
public MyClass() {
Bars = new Lazy<List<Bar>>(async () => await LoadBars(), true);
}
private async Task<List<Bar>> LoadBars() {
return await Util.Database.GetBarsAsync(Id);
}
}
This collection consumes a lot of memory so I only want it loaded when I need it.
The error I get is on the =>
:
Cannot convert async lambda expression to delegate type 'Func>'. An async lambda expression may return void, Task or Task, none of which are convertible to 'Func>'