-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathProgram.cs
47 lines (40 loc) · 1.32 KB
/
Program.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
using Microsoft.EntityFrameworkCore;
using System;
using System.Linq;
using System.Threading.Tasks;
using ToPage;
using ToPage.EFCore;
namespace EntityFramework
{
class Program
{
static async Task Main()
{
using var context = new AppDbContext();
context.Database.Migrate();
var command = "";
do
{
Console.Write("Enter a page number (> 0), or type exit to quit: ");
command = Console.ReadLine();
if (int.TryParse(command, out var pageNumber) && pageNumber > 0)
{
var page = await context.People
.OrderBy(person => person.Id)
.ToPageWithCountsAsync(pageNumber, itemsPerPage: 10);
RenderPage(page);
}
} while (command != "exit");
}
static void RenderPage(IPageWithCounts<Person> page)
{
Console.Clear();
Console.WriteLine($"Id\tAge\tFavorite Color");
foreach (var person in page)
{
Console.WriteLine($"{person.Id}\t{person.Age}\t{person.FavoriteColor}");
}
Console.WriteLine($"Page {page.PageNumber} of {page.PageCount} ({page.ItemCount} people total)");
}
}
}