I have a ViewComponent, and DTO and ViewModel classes. I want to pass a list of ViewModels to the view, but because of async/await I cannot do it in one line like so:
List<PageVM> pages = await _context.Pages.ToArray().Where(x => x.Slug != "home").OrderBy(x => x.Sorting).Select(x => new PageVM(x)).ToList();
I can do it in more lines like so:
List<PageVM> pages = new List<PageVM>();
List<PageDTO> dto = await _context.Pages.Where(x => x.Slug != "home").ToListAsync();
foreach (var item in dto)
{
pages.Add(new PageVM(item));
}
But is it possible to modify the one line so it works with await?