Efficient Pagination with Skip/Take

Efficient pagination using OFFSET-FETCH on SQL Server.

Execution Time

19 ms

Page Size

25

Current Page

662 / 978

Total Records

24441

Items per page: 25 50 100 200

Page 662 Results Showing 16526 - 16550 of 24441

ID Name Category Price Stock Rating Reviews SKU
17085 Bulk Product 12437b89 Toys & Games $758.31 371 1.6 83 BULK-6fad5b9a
17086 Bulk Product 3af003e2 Toys & Games $974.38 55 3.1 29 BULK-2819b0ee
17087 Bulk Product 61fef914 Electronics $233.92 161 1.3 1 BULK-e79d9c85
17088 Bulk Product ff9b2f09 Books $331.32 460 2.7 77 BULK-8b30760f
17089 Bulk Product 95c1ab7e Home & Garden $814.08 250 0.2 57 BULK-1649f534
17090 Bulk Product 349ea894 Home & Garden $807.28 173 0.9 90 BULK-99d690fb
17091 Bulk Product d765a242 Electronics $745.12 104 0.8 26 BULK-06013061
17092 Bulk Product aec6f212 Books $488.31 195 4.9 31 BULK-7fb7a064
17093 Bulk Product 43e4c30a Books $354.97 339 0.3 4 BULK-5372f1dd
17094 Bulk Product b8edf1fa Clothing $935.49 63 4.4 20 BULK-f199d0b5
17095 Bulk Product 3b3defae Clothing $243.50 459 2.5 7 BULK-03728f8d
17096 Bulk Product 740e7271 Toys & Games $91.03 266 3.2 51 BULK-b3d9bd13
17097 Bulk Product 0fd6ed1c Electronics $580.59 457 2.7 29 BULK-c1ae9197
17098 Bulk Product 485aedb6 Sports & Outdoors $940.98 33 3.0 84 BULK-51384ddf
17099 Bulk Product ebab7b37 Clothing $132.36 434 2.6 46 BULK-c6643b66
17100 Bulk Product 05b69357 Books $871.54 296 1.6 63 BULK-9b9f0606
17101 Bulk Product e11537f5 Home & Garden $878.60 247 2.6 39 BULK-1eeba0c4
17102 Bulk Product 26be712b Clothing $547.41 306 0.6 19 BULK-f4ab1ee9
17103 Bulk Product b3d11630 Books $384.11 492 1.8 1 BULK-f2eacbb5
17104 Bulk Product fce3bd7f Clothing $102.22 339 2.2 46 BULK-2ed38aed
17105 Bulk Product 9cb804e5 Clothing $532.49 489 0.9 67 BULK-8a6bdd72
17106 Bulk Product 0699483b Books $864.75 440 3.2 2 BULK-6d55fd00
17107 Bulk Product 5bcc637d Home & Garden $441.24 456 0.7 69 BULK-5a974d9f
17108 Bulk Product b41ace59 Electronics $44.70 153 3.6 91 BULK-112036f8
17109 Bulk Product 028f1852 Home & Garden $868.52 200 3.5 61 BULK-44f5d1b6
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