Efficient Pagination with Skip/Take

Efficient pagination using OFFSET-FETCH on SQL Server.

Execution Time

59 ms

Page Size

25

Current Page

916 / 978

Total Records

24441

Items per page: 25 50 100 200

Page 916 Results Showing 22876 - 22900 of 24441

ID Name Category Price Stock Rating Reviews SKU
23435 Bulk Product e5baf2a0 Clothing $662.17 350 1.0 9 BULK-e7b84cae
23436 Bulk Product 1b161fb7 Sports & Outdoors $547.51 205 4.5 81 BULK-76d4a596
23437 Bulk Product 013be468 Sports & Outdoors $303.13 466 4.3 74 BULK-71fd81ba
23438 Bulk Product 5fc6c5c9 Electronics $345.78 497 2.3 4 BULK-ea5dea3f
23439 Bulk Product fa39da86 Electronics $240.92 408 0.8 8 BULK-1ac5a305
23440 Bulk Product b548d7d7 Electronics $118.63 420 1.5 10 BULK-dd04fbb0
23441 Bulk Product 8a0a66a6 Sports & Outdoors $241.02 193 3.5 76 BULK-120cb0a7
23442 Bulk Product 0480b618 Books $960.57 169 2.7 74 BULK-217498a0
23443 Bulk Product 3b756b26 Home & Garden $915.39 346 3.0 99 BULK-23e25b9e
23444 Bulk Product 68dcb27c Home & Garden $334.41 375 3.9 43 BULK-2d5599ac
23445 Bulk Product ecb161b5 Clothing $431.27 433 2.0 61 BULK-cb98e0a8
23446 Bulk Product 01c1cb7a Toys & Games $537.16 314 1.9 2 BULK-8cfec9b9
23447 Bulk Product ddcd4187 Electronics $589.37 81 4.7 66 BULK-a12ca376
23448 Bulk Product 522525f0 Toys & Games $408.48 386 1.1 3 BULK-1923cc4b
23449 Bulk Product abb1c9c4 Electronics $264.48 290 0.5 50 BULK-f9303ff3
23450 Bulk Product d7dacd81 Books $230.42 205 4.2 14 BULK-c110713d
23451 Bulk Product 34b6505b Books $488.00 73 3.0 93 BULK-4545e5db
23452 Bulk Product dceb3145 Books $819.51 34 2.7 75 BULK-d561bd74
23453 Bulk Product 9f122b59 Toys & Games $603.59 360 3.6 99 BULK-be35c6a3
23454 Bulk Product 968cd355 Toys & Games $639.19 272 4.0 37 BULK-d625f948
23455 Bulk Product c27fb8ec Books $479.73 336 0.8 82 BULK-a1011663
23456 Bulk Product f73349d4 Books $242.44 169 3.5 14 BULK-0e7ccd4b
23457 Bulk Product 8fb4c971 Electronics $684.02 32 0.3 65 BULK-994ba0d8
23458 Bulk Product d2e9cfcb Clothing $933.25 379 2.4 46 BULK-4398c1f3
23459 Bulk Product 7d7d3049 Toys & Games $608.74 180 2.7 62 BULK-b02f8301
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