Efficient Pagination with Skip/Take

Efficient pagination using OFFSET-FETCH on SQL Server.

Execution Time

40 ms

Page Size

25

Current Page

922 / 978

Total Records

24441

Items per page: 25 50 100 200

Page 922 Results Showing 23026 - 23050 of 24441

ID Name Category Price Stock Rating Reviews SKU
23585 Bulk Product 680cc18e Books $415.74 18 0.9 65 BULK-adea5d7c
23586 Bulk Product 886b0d07 Sports & Outdoors $648.33 5 1.7 42 BULK-91b672c3
23587 Bulk Product fe2c2f8c Home & Garden $504.03 377 3.0 26 BULK-be920bae
23588 Bulk Product 9111f587 Home & Garden $210.99 111 1.2 39 BULK-41bb7c32
23589 Bulk Product 18fea742 Home & Garden $379.41 42 1.8 23 BULK-01dc19e3
23590 Bulk Product 86005d4e Clothing $88.61 12 1.2 65 BULK-522d85e3
23591 Bulk Product d87f7154 Home & Garden $416.97 368 4.2 65 BULK-d02a870c
23592 Bulk Product e52de770 Electronics $175.24 386 4.2 49 BULK-510fb183
23593 Bulk Product 354b63c6 Toys & Games $773.90 6 1.1 36 BULK-68a018d9
23594 Bulk Product c7591ab4 Home & Garden $498.05 440 1.8 94 BULK-3f2553a1
23595 Bulk Product ad5d39e9 Home & Garden $455.64 239 2.6 78 BULK-c3733c8e
23596 Bulk Product 78044209 Toys & Games $64.40 166 1.4 15 BULK-a8f8ab37
23597 Bulk Product 09dab022 Toys & Games $104.33 407 3.2 34 BULK-df9cf0c1
23598 Bulk Product 529c173f Toys & Games $235.65 113 0.4 11 BULK-664b092f
23599 Bulk Product 03b7319e Clothing $818.00 244 3.6 82 BULK-6c317f6e
23600 Bulk Product 4cc680a5 Books $144.01 250 2.9 94 BULK-ba098c33
23601 Bulk Product 378a3b74 Home & Garden $122.79 210 4.6 83 BULK-81bb00a3
23602 Bulk Product 4d34e9eb Toys & Games $344.03 244 4.2 54 BULK-f1f9c99a
23603 Bulk Product 76bda0dd Home & Garden $904.67 330 4.7 38 BULK-d73ae36a
23604 Bulk Product da8e5997 Sports & Outdoors $257.04 457 3.2 16 BULK-b9671b49
23605 Bulk Product 398098ff Clothing $289.22 349 1.7 18 BULK-63db83d8
23606 Bulk Product ba25c54a Toys & Games $615.25 444 1.5 43 BULK-71730a60
23607 Bulk Product f164e48a Toys & Games $649.49 181 1.2 89 BULK-59dcb08b
23608 Bulk Product 26674403 Sports & Outdoors $531.15 368 4.5 68 BULK-f50db60e
23609 Bulk Product 535bdeb5 Home & Garden $310.44 35 2.9 61 BULK-e62555a2
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