Efficient Pagination with Skip/Take

Efficient pagination using OFFSET-FETCH on SQL Server.

Execution Time

10 ms

Page Size

25

Current Page

318 / 978

Total Records

24441

Items per page: 25 50 100 200

Page 318 Results Showing 7926 - 7950 of 24441

ID Name Category Price Stock Rating Reviews SKU
8485 Bulk Product 69d98e68 Toys & Games $846.64 93 3.8 67 BULK-64f2e3cf
8486 Bulk Product cb1d793a Home & Garden $80.09 283 3.1 60 BULK-46f07cf9
8487 Bulk Product 53870df1 Clothing $563.21 426 3.6 2 BULK-cf007606
8488 Bulk Product a6b9fe5b Home & Garden $580.30 268 2.8 64 BULK-1b2c40f2
8489 Bulk Product cbb2d608 Toys & Games $377.47 420 4.4 89 BULK-2135a78f
8490 Bulk Product 908b6692 Home & Garden $286.88 102 2.9 41 BULK-99104c31
8491 Bulk Product 8ec74722 Electronics $689.58 291 2.1 19 BULK-9aa67d61
8492 Bulk Product 89d3b7c8 Clothing $824.13 409 4.5 71 BULK-c1e248b9
8493 Bulk Product e9ca9a27 Electronics $632.02 327 3.5 94 BULK-d0f04599
8494 Bulk Product f74348d5 Books $49.21 130 2.6 88 BULK-46e918dd
8495 Bulk Product 543f10b2 Sports & Outdoors $68.81 245 0.6 64 BULK-d5af1308
8496 Bulk Product ed620394 Electronics $719.93 164 3.1 96 BULK-aa9421da
8497 Bulk Product aabc2d15 Toys & Games $59.14 496 2.0 28 BULK-df480774
8498 Bulk Product 96e59f8f Electronics $948.21 454 0.7 90 BULK-239fabbf
8499 Bulk Product b3af1f04 Books $391.37 364 1.9 48 BULK-1db7a85a
8500 Bulk Product 35150534 Books $100.60 13 0.9 69 BULK-c7c9d769
8501 Bulk Product 49d25af4 Home & Garden $515.01 195 3.0 38 BULK-563780cd
8502 Bulk Product cd82095e Electronics $883.95 259 4.9 22 BULK-2f054719
8503 Bulk Product efdd877f Home & Garden $973.04 245 3.4 4 BULK-8dd78087
8504 Bulk Product 8a0eb471 Books $704.31 157 1.9 99 BULK-652d0c4b
8505 Bulk Product 18ebb467 Clothing $233.97 150 0.8 11 BULK-1506a15b
8506 Bulk Product 4619de55 Books $490.44 433 1.2 57 BULK-8e949750
8507 Bulk Product ec4a1927 Home & Garden $621.41 12 1.0 3 BULK-fcf281be
8508 Bulk Product f9b568ec Books $187.75 61 3.4 23 BULK-7dc82f26
8509 Bulk Product a2bd619d Home & Garden $919.91 474 3.6 63 BULK-f231d0b9
Implementation Code
// Efficient pagination with Skip and Take
public async Task<PaginatedResult<DemoProduct>> GetPaginatedProductsAsync(int page, int pageSize)
{
    // Get total count (cached if possible)
    var totalCount = await _context.DemoProducts.CountAsync(p => p.IsActive);
    
    // Get page of results
    var items = await _context.DemoProducts
        .Where(p => p.IsActive)
        .OrderBy(p => p.Id) // Important: Must have ORDER BY for consistent paging
        .Skip((page - 1) * pageSize) // OFFSET in SQL
        .Take(pageSize) // FETCH NEXT in SQL
        .AsNoTracking() // No tracking needed for read-only
        .ToListAsync();

    return new PaginatedResult<DemoProduct>
    {
        Items = items,
        TotalCount = totalCount,
        Page = page,
        PageSize = pageSize
    };
}
Pagination Best Practices
  • Always use OrderBy: Skip/Take require stable sorting for consistent results
  • Use AsNoTracking(): Pagination queries are typically read-only
  • Consider caching: Cache total count if dataset changes infrequently
  • Limit max page size: Prevent users from requesting too many records at once
  • Use indexed columns: Ensure ORDER BY columns are indexed for performance