Efficient Pagination with Skip/Take

Efficient pagination using OFFSET-FETCH on SQL Server.

Execution Time

25 ms

Page Size

25

Current Page

249 / 978

Total Records

24441

Items per page: 25 50 100 200

Page 249 Results Showing 6201 - 6225 of 24441

ID Name Category Price Stock Rating Reviews SKU
6760 Bulk Product f0f4d472 Books $349.87 349 1.7 40 BULK-46010ca0
6761 Bulk Product 653cf323 Home & Garden $520.55 140 3.1 48 BULK-23d60da7
6762 Bulk Product 9e50f60c Toys & Games $906.91 458 3.2 4 BULK-08e85e60
6763 Bulk Product bd46d611 Electronics $723.60 371 2.3 40 BULK-7a537d47
6764 Bulk Product 9ca43b9a Sports & Outdoors $556.85 351 3.5 42 BULK-bd3c1be2
6765 Bulk Product 2ef853ee Home & Garden $593.58 461 3.2 60 BULK-f7fb303d
6766 Bulk Product 9922231e Sports & Outdoors $972.89 304 2.5 31 BULK-46d86be9
6767 Bulk Product b6354522 Home & Garden $742.08 451 0.7 57 BULK-ceb7277c
6768 Bulk Product 4db792bd Electronics $727.93 75 3.6 16 BULK-2a0e4952
6769 Bulk Product 8f10f09c Toys & Games $667.01 357 2.9 65 BULK-96fc9545
6770 Bulk Product 2ce3ebb3 Electronics $687.25 99 4.4 94 BULK-614a8fb3
6771 Bulk Product dbc8f3c9 Books $922.81 463 3.7 27 BULK-2f0174eb
6772 Bulk Product 849ae420 Sports & Outdoors $648.23 107 3.2 83 BULK-63d102e6
6773 Bulk Product 93b6fbb1 Sports & Outdoors $1,001.36 331 4.4 96 BULK-0786a645
6774 Bulk Product 6bc5be9e Sports & Outdoors $830.36 122 2.9 43 BULK-6ba86789
6775 Bulk Product a24d63e0 Clothing $491.83 232 1.2 36 BULK-49ea10ce
6776 Bulk Product c0f76bae Clothing $65.72 386 1.7 3 BULK-f98dd8b6
6777 Bulk Product 4361d1cf Clothing $599.20 42 2.9 22 BULK-a2245436
6778 Bulk Product 46b3a1c1 Sports & Outdoors $597.03 482 2.4 77 BULK-8a020e20
6779 Bulk Product 27e674d9 Toys & Games $862.63 468 4.4 57 BULK-6c369bda
6780 Bulk Product 5890aab2 Books $118.39 178 5.0 67 BULK-dba277af
6781 Bulk Product 3cdf1fba Sports & Outdoors $663.22 275 1.0 74 BULK-fd6cbd47
6782 Bulk Product de74649a Books $156.76 416 2.0 83 BULK-bbe4dd71
6783 Bulk Product 7a6714ee Electronics $630.96 51 3.8 97 BULK-fe72082b
6784 Bulk Product 4d4bfce5 Clothing $608.97 182 0.9 14 BULK-17c83112
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