Efficient Pagination with Skip/Take

Efficient pagination using OFFSET-FETCH on SQL Server.

Execution Time

12 ms

Page Size

25

Current Page

438 / 978

Total Records

24441

Items per page: 25 50 100 200

Page 438 Results Showing 10926 - 10950 of 24441

ID Name Category Price Stock Rating Reviews SKU
11485 Bulk Product 79088a58 Books $903.54 495 3.7 58 BULK-ddb5673a
11486 Bulk Product e318bb4c Clothing $1,008.88 425 4.5 10 BULK-0205bc72
11487 Bulk Product 8a3329c9 Sports & Outdoors $240.86 312 0.8 73 BULK-69408fcc
11488 Bulk Product 69ef518a Sports & Outdoors $157.65 399 2.6 36 BULK-4d5d7047
11489 Bulk Product 59e18f1e Electronics $488.29 177 1.8 30 BULK-67323238
11490 Bulk Product fe45e74a Home & Garden $561.47 180 1.6 85 BULK-3e142f8d
11491 Bulk Product 3fcbe004 Electronics $783.02 235 0.5 99 BULK-16f936a4
11492 Bulk Product 4e5382d8 Toys & Games $252.90 476 3.3 7 BULK-b8ba93d6
11493 Bulk Product a87a26e5 Books $387.14 294 1.7 67 BULK-1b2225e8
11494 Bulk Product 404e4fbe Toys & Games $238.11 89 2.9 48 BULK-f48a92df
11495 Bulk Product 480ff731 Sports & Outdoors $444.41 73 4.8 96 BULK-c69cca76
11496 Bulk Product ac461b02 Sports & Outdoors $80.12 422 3.3 96 BULK-8728bbb4
11497 Bulk Product 8fb378fc Books $471.56 293 0.5 31 BULK-028d60c4
11498 Bulk Product c95070c9 Home & Garden $863.53 103 2.8 65 BULK-60bbc42c
11499 Bulk Product 62ddb178 Electronics $787.36 213 3.2 2 BULK-fe33374e
11500 Bulk Product 7c18c0cc Clothing $551.35 311 2.7 42 BULK-e796191e
11501 Bulk Product ecca082e Books $59.27 198 3.4 82 BULK-6fb4f712
11502 Bulk Product 26f1a0c9 Books $282.83 257 3.6 50 BULK-c715a4be
11503 Bulk Product 3785f188 Books $450.39 178 0.9 89 BULK-c5bcad9f
11504 Bulk Product 33b22d6a Toys & Games $499.68 389 0.8 72 BULK-21a73b1c
11505 Bulk Product 49326c78 Toys & Games $732.87 8 1.7 75 BULK-c950a731
11506 Bulk Product 189ccfc5 Toys & Games $761.07 268 2.5 62 BULK-00f32000
11507 Bulk Product 7c113f07 Electronics $115.64 286 4.8 83 BULK-cbccff0d
11508 Bulk Product 0a93f9fc Home & Garden $504.85 431 4.6 63 BULK-9126d86b
11509 Bulk Product 197076eb Electronics $908.45 63 4.4 32 BULK-a6e387c6
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