Efficient Pagination with Skip/Take

Efficient pagination using OFFSET-FETCH on SQL Server.

Execution Time

31 ms

Page Size

25

Current Page

676 / 978

Total Records

24441

Items per page: 25 50 100 200

Page 676 Results Showing 16876 - 16900 of 24441

ID Name Category Price Stock Rating Reviews SKU
17435 Bulk Product 18ed66a6 Toys & Games $235.89 469 4.6 64 BULK-fe782c3f
17436 Bulk Product 44685a39 Home & Garden $526.83 150 3.2 10 BULK-b9610791
17437 Bulk Product 76944305 Books $927.24 45 4.7 34 BULK-d141a0bb
17438 Bulk Product 0d7684c5 Home & Garden $742.37 350 2.3 71 BULK-fb953f2c
17439 Bulk Product a52e61f1 Sports & Outdoors $452.98 279 3.5 66 BULK-03353584
17440 Bulk Product 485a35a3 Toys & Games $552.04 307 2.5 51 BULK-f702f630
17441 Bulk Product f184d5f3 Electronics $372.88 46 2.1 13 BULK-7ee2b1be
17442 Bulk Product 1d0f0371 Electronics $655.73 219 2.7 19 BULK-4be79c9a
17443 Bulk Product c7fb0b21 Home & Garden $721.59 35 4.5 98 BULK-16128347
17444 Bulk Product c5865f6a Toys & Games $110.02 491 3.7 89 BULK-b3280d65
17445 Bulk Product f874746c Sports & Outdoors $850.48 151 0.3 44 BULK-26144613
17446 Bulk Product 41fd1ace Toys & Games $325.73 102 0.5 1 BULK-51078631
17447 Bulk Product 0867a1e1 Clothing $895.28 464 0.0 74 BULK-12754282
17448 Bulk Product 712bf094 Clothing $467.70 372 1.0 94 BULK-6ed787b1
17449 Bulk Product 6922426f Books $444.48 68 1.0 69 BULK-59e066c2
17450 Bulk Product 46426676 Clothing $602.66 262 3.1 49 BULK-6d3fa0bf
17451 Bulk Product c9a7442d Electronics $895.56 150 2.2 20 BULK-b16720d1
17452 Bulk Product d6b29891 Electronics $71.23 396 0.7 85 BULK-7e0a97d2
17453 Bulk Product ab9d0069 Toys & Games $141.43 96 1.8 56 BULK-46be7ed9
17454 Bulk Product 85eb628f Home & Garden $220.23 272 3.5 10 BULK-6c787c2c
17455 Bulk Product 64cd93b2 Home & Garden $134.02 326 1.2 51 BULK-9c1af4fa
17456 Bulk Product 28b6818d Electronics $689.83 459 3.8 71 BULK-6d16b617
17457 Bulk Product 8db49c63 Toys & Games $813.74 377 2.9 17 BULK-93b6e7cb
17458 Bulk Product 24c6dd33 Toys & Games $652.16 197 1.5 79 BULK-14cc69d4
17459 Bulk Product 01b5cded Home & Garden $822.33 472 2.6 7 BULK-e3ebaa37
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