Efficient Pagination with Skip/Take

Efficient pagination using OFFSET-FETCH on SQL Server.

Execution Time

22 ms

Page Size

25

Current Page

565 / 978

Total Records

24441

Items per page: 25 50 100 200

Page 565 Results Showing 14101 - 14125 of 24441

ID Name Category Price Stock Rating Reviews SKU
14660 Bulk Product 7f2b5af0 Books $355.21 202 4.0 87 BULK-be03611d
14661 Bulk Product 879f3243 Clothing $828.83 193 1.0 28 BULK-0c423ab1
14662 Bulk Product 9021267a Electronics $201.70 117 0.8 64 BULK-b565c352
14663 Bulk Product a8f1b322 Home & Garden $757.11 437 1.8 1 BULK-fea7a7f5
14664 Bulk Product bbb856b5 Clothing $574.89 121 0.8 9 BULK-d8d86a15
14665 Bulk Product b7259614 Electronics $678.18 419 2.3 6 BULK-e37e6806
14666 Bulk Product 04f0448c Home & Garden $292.08 90 2.0 47 BULK-46fcb6bf
14667 Bulk Product c40c8965 Books $355.91 419 0.7 70 BULK-7a0a5c44
14668 Bulk Product 0a82040f Clothing $471.96 388 3.6 45 BULK-e058c89d
14669 Bulk Product 60c9e7e9 Electronics $147.27 25 2.6 30 BULK-07e357b9
14670 Bulk Product ffe5f5af Toys & Games $904.88 21 3.7 39 BULK-a46c5aa8
14671 Bulk Product 311ff81c Books $754.05 429 0.4 3 BULK-03e06ff6
14672 Bulk Product da183bbb Electronics $844.85 374 1.9 19 BULK-71cb70a5
14673 Bulk Product fd0de20a Home & Garden $585.45 313 4.0 10 BULK-32a1bcaa
14674 Bulk Product 4e20a516 Clothing $913.78 63 1.4 57 BULK-130459e2
14675 Bulk Product a1943475 Electronics $45.00 37 3.0 92 BULK-bc338c5d
14676 Bulk Product 87fde99d Clothing $906.44 391 5.0 95 BULK-77fb047c
14677 Bulk Product be38dcd8 Home & Garden $706.70 444 2.6 29 BULK-a8c02a7d
14678 Bulk Product cf14da67 Sports & Outdoors $44.04 4 4.2 94 BULK-094a5a81
14679 Bulk Product 0244242d Sports & Outdoors $740.81 150 4.7 97 BULK-d34371ef
14680 Bulk Product ed8c4d8c Toys & Games $357.64 269 2.4 77 BULK-598c973c
14681 Bulk Product 18d60195 Sports & Outdoors $115.89 413 0.1 10 BULK-5de6ef27
14682 Bulk Product bd95c796 Books $985.71 149 0.7 6 BULK-f17f6b51
14683 Bulk Product 4402aaf8 Books $323.01 401 2.3 63 BULK-31a9993f
14684 Bulk Product 9fed4032 Clothing $621.30 231 4.4 43 BULK-9bcc4c84
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