-
Notifications
You must be signed in to change notification settings - Fork 22
/
Copy pathProgram.cs
37 lines (27 loc) · 936 Bytes
/
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
// See https://aka.ms/new-console-template for more information
using Microsoft.Data.Sqlite;
using Microsoft.EntityFrameworkCore;
using PaginationEF;
var connection = CreateInMemoryConnection();
var options = new DbContextOptionsBuilder()
.UseSqlite(CreateInMemoryConnection())
.Options;
var db = new BlogPostDbContext(options);
await AddInstancesAsync(20, db);
var page1 = await db.BlogPosts.ToPagedListAsync(1, 15);
Console.WriteLine("Count: " + page1.Count);
connection.Close();
SqliteConnection CreateInMemoryConnection()
{
var sqliteConnection = new SqliteConnection("DataSource=:memory:");
sqliteConnection.Open();
return sqliteConnection;
}
async Task AddInstancesAsync(int instanceCount, BlogPostDbContext context)
{
for (var i = 0; i < instanceCount; i++)
{
await context.BlogPosts.AddAsync(new BlogPost() { Title = "Hello " + i });
}
await context.SaveChangesAsync();
}