Efficient Pagination with Skip/Take

Efficient pagination using OFFSET-FETCH on SQL Server.

Execution Time

15 ms

Page Size

25

Current Page

614 / 978

Total Records

24441

Items per page: 25 50 100 200

Page 614 Results Showing 15326 - 15350 of 24441

ID Name Category Price Stock Rating Reviews SKU
15885 Bulk Product 5717721d Home & Garden $477.16 16 1.9 8 BULK-ba637001
15886 Bulk Product 269d62ec Clothing $642.44 499 1.3 53 BULK-394a753e
15887 Bulk Product 13cbe0a5 Home & Garden $830.19 421 4.1 76 BULK-2e8d58de
15888 Bulk Product efd4987c Sports & Outdoors $649.52 62 3.0 79 BULK-e55f57aa
15889 Bulk Product 848fdb4e Sports & Outdoors $299.52 449 3.8 61 BULK-ffec493f
15890 Bulk Product bf798976 Sports & Outdoors $952.59 351 4.4 81 BULK-c86100ef
15891 Bulk Product 0bd269ff Clothing $691.26 181 4.4 81 BULK-eb0fd7d9
15892 Bulk Product 885be68e Clothing $233.58 189 3.7 39 BULK-e30d8a7b
15893 Bulk Product a08ca1c5 Electronics $830.42 41 2.6 3 BULK-0527e2bc
15894 Bulk Product d6ea61c9 Sports & Outdoors $280.72 409 4.1 15 BULK-bfda9422
15895 Bulk Product 79dd1f8c Sports & Outdoors $738.74 168 3.3 95 BULK-c072af3e
15896 Bulk Product 1ed3d3f5 Sports & Outdoors $513.37 451 4.1 1 BULK-0a56f76f
15897 Bulk Product 2595d3e1 Toys & Games $208.23 324 0.0 44 BULK-c3b3bfa4
15898 Bulk Product e60572b2 Toys & Games $989.46 281 2.3 99 BULK-ca663235
15899 Bulk Product 8a312baf Home & Garden $873.69 335 2.6 49 BULK-8886b5c5
15900 Bulk Product 529f9ea4 Home & Garden $884.84 40 3.9 53 BULK-64473645
15901 Bulk Product ebd4ebf7 Toys & Games $275.67 354 2.3 95 BULK-9963bec5
15902 Bulk Product 768c77de Electronics $661.33 83 0.5 44 BULK-cc1312a5
15903 Bulk Product b54db0cd Home & Garden $317.93 10 2.1 82 BULK-0a5fa1ed
15904 Bulk Product 08c4ce88 Clothing $101.90 297 3.4 86 BULK-dc7c49fa
15905 Bulk Product 0e5e71a2 Clothing $305.81 490 2.3 1 BULK-59c6e875
15906 Bulk Product b1621c8c Books $11.58 112 0.5 86 BULK-602a9f65
15907 Bulk Product 4211182f Electronics $877.34 413 2.8 5 BULK-ec6e68bb
15908 Bulk Product db500a5b Toys & Games $579.27 85 1.7 3 BULK-9ec322a3
15909 Bulk Product e4754c8d Books $208.58 192 0.9 66 BULK-7311e551
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