public async Task <IActionResult> CountryStats() { var stats = await _orderQueries.GetCountryStatsAsync(String.Empty); var typedStats = stats .Select(c => new { c.next, c.country, c.year, c.month, c.max, c.min, c.std, c.count, c.sales, c.med, c.prev }) .ToList(); var csvFile = File(Encoding.UTF8.GetBytes(typedStats.FormatAsCSV()), "text/csv"); csvFile.FileDownloadName = "countries.stats.csv"; return(csvFile); }