Skip to content

Commit

Permalink
Use async implementation in EF core example
Browse files Browse the repository at this point in the history
  • Loading branch information
a-gubskiy committed Feb 14, 2023
1 parent a84b225 commit 91ca9d8
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions examples/Example.Website/Controllers/HomeController.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Example.DAL;
using Microsoft.AspNetCore.Mvc;
using X.PagedList;
Expand Down Expand Up @@ -30,17 +31,17 @@ public IActionResult AjaxIndex(int page = 1)
return View();
}

public IActionResult EFCore(int page = 1)
public async Task<IActionResult> EFCore(int page = 1)
{
// return a 404 if user browses to before the first page
if (page < 1)
{
return NotFound();
}

var records = _databaseContext.Animals
var records = await _databaseContext.Animals
.Select(o => o.Name)
.ToPagedList(page, PageSize);
.ToPagedListAsync(page, PageSize);

// return a 404 if user browses to pages beyond last page. special case first page if no items exist
if (records.PageNumber != 1 && page > records.PageCount)
Expand Down

0 comments on commit 91ca9d8

Please sign in to comment.