Efficient Pagination with Skip/Take

Efficient pagination using OFFSET-FETCH on SQL Server.

Execution Time

10 ms

Page Size

25

Current Page

426 / 978

Total Records

24441

Items per page: 25 50 100 200

Page 426 Results Showing 10626 - 10650 of 24441

ID Name Category Price Stock Rating Reviews SKU
11185 Bulk Product 59d7e8b0 Electronics $496.47 329 1.7 37 BULK-c3bdaf15
11186 Bulk Product 66fd03f3 Toys & Games $918.45 375 1.0 84 BULK-dd0c9df2
11187 Bulk Product 2bcf0594 Books $881.49 438 3.4 49 BULK-264b0773
11188 Bulk Product 99c873a9 Electronics $218.18 218 0.3 13 BULK-ee025786
11189 Bulk Product 7bbd5783 Clothing $753.56 476 4.6 28 BULK-3d1a9c1e
11190 Bulk Product e07617dc Home & Garden $600.56 26 2.7 26 BULK-d90c68eb
11191 Bulk Product 75da477d Books $803.71 465 3.5 94 BULK-7f692ea6
11192 Bulk Product 7e7a5229 Electronics $503.69 211 2.5 53 BULK-f97ee96f
11193 Bulk Product e0cba3c7 Books $262.33 479 0.9 13 BULK-5bedc8bd
11194 Bulk Product 93cf0345 Toys & Games $978.12 168 4.4 58 BULK-63a7b0fd
11195 Bulk Product 967d7e45 Sports & Outdoors $131.06 338 0.8 12 BULK-63098b45
11196 Bulk Product a71558f1 Books $147.31 295 0.2 92 BULK-598e0e4c
11197 Bulk Product 2284e18c Books $133.22 44 3.1 17 BULK-9d2608fa
11198 Bulk Product c5ca4bde Clothing $987.69 311 3.5 73 BULK-641e714c
11199 Bulk Product 88cbc6fe Books $767.70 218 2.0 43 BULK-abc4337c
11200 Bulk Product aa74a910 Home & Garden $583.53 453 3.6 95 BULK-4d87b94b
11201 Bulk Product aaf6acb0 Books $304.02 389 0.8 14 BULK-60a29e55
11202 Bulk Product e8902ddf Sports & Outdoors $364.19 156 3.4 1 BULK-21bb29cc
11203 Bulk Product 463e440e Home & Garden $53.49 405 2.5 5 BULK-6fc0a6cb
11204 Bulk Product da70cd0d Home & Garden $933.11 408 0.0 66 BULK-ebd6cbc4
11205 Bulk Product 62fa20c8 Electronics $527.87 125 0.4 73 BULK-ecd7cb56
11206 Bulk Product 64466b07 Home & Garden $942.49 411 4.0 86 BULK-58ef3f85
11207 Bulk Product c1e2802d Electronics $858.46 105 3.8 25 BULK-386aa87a
11208 Bulk Product 64e14617 Sports & Outdoors $104.17 174 3.7 37 BULK-7527bfbf
11209 Bulk Product d8cc54c4 Sports & Outdoors $667.71 473 4.0 94 BULK-6e93da93
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