Efficient Pagination with Skip/Take

Efficient pagination using OFFSET-FETCH on SQL Server.

Execution Time

35 ms

Page Size

25

Current Page

874 / 978

Total Records

24441

Items per page: 25 50 100 200

Page 874 Results Showing 21826 - 21850 of 24441

ID Name Category Price Stock Rating Reviews SKU
22385 Bulk Product 64671ebb Home & Garden $784.72 165 1.7 32 BULK-66c4cb67
22386 Bulk Product e7ea2a20 Home & Garden $825.48 442 1.7 13 BULK-3d725b5c
22387 Bulk Product 676d7bfb Sports & Outdoors $290.28 144 2.4 29 BULK-77fd1945
22388 Bulk Product 7b693645 Books $758.35 29 0.9 12 BULK-3da2a527
22389 Bulk Product 02ac81e6 Sports & Outdoors $900.17 288 0.6 57 BULK-70b51967
22390 Bulk Product cb0b5386 Sports & Outdoors $734.34 149 5.0 19 BULK-08fa0ee4
22391 Bulk Product aeff88b2 Home & Garden $535.21 315 2.7 88 BULK-609730b6
22392 Bulk Product 6750bbc1 Electronics $791.54 344 0.2 85 BULK-76b7898d
22393 Bulk Product c4abcc25 Toys & Games $834.16 44 1.1 54 BULK-074c73d0
22394 Bulk Product d40abd27 Clothing $163.76 68 2.0 24 BULK-a7ad3c88
22395 Bulk Product 5115310d Sports & Outdoors $708.19 17 1.0 95 BULK-21610bda
22396 Bulk Product 4176b518 Books $477.91 174 1.9 84 BULK-beb1ae58
22397 Bulk Product 956711bb Electronics $217.26 176 2.9 93 BULK-2e064554
22398 Bulk Product f66caff0 Sports & Outdoors $187.01 32 4.2 8 BULK-56905712
22399 Bulk Product f1db03a0 Electronics $685.40 460 2.3 18 BULK-98208ab6
22400 Bulk Product e4385f70 Books $534.48 215 1.1 98 BULK-3a9c3273
22401 Bulk Product 3cb876ed Electronics $841.49 183 1.1 59 BULK-02119e6e
22402 Bulk Product 81a9de46 Books $52.26 101 4.6 21 BULK-2ccd9ece
22403 Bulk Product 9bacf477 Electronics $623.57 445 0.6 22 BULK-12832faa
22404 Bulk Product b4bac8b0 Home & Garden $903.33 263 3.3 25 BULK-91e602cb
22405 Bulk Product ac70a787 Sports & Outdoors $34.13 179 1.1 18 BULK-a131763e
22406 Bulk Product 9d944e47 Sports & Outdoors $615.78 455 2.0 47 BULK-183df85b
22407 Bulk Product ab7f4bd0 Sports & Outdoors $206.82 18 2.8 31 BULK-3b3e2c5f
22408 Bulk Product 8f82adca Home & Garden $88.19 400 5.0 64 BULK-46d44fa4
22409 Bulk Product 75047d89 Books $48.08 67 1.1 49 BULK-0b3d66e5
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