Efficient Pagination with Skip/Take

Efficient pagination using OFFSET-FETCH on SQL Server.

Execution Time

13 ms

Page Size

25

Current Page

609 / 978

Total Records

24441

Items per page: 25 50 100 200

Page 609 Results Showing 15201 - 15225 of 24441

ID Name Category Price Stock Rating Reviews SKU
15760 Bulk Product ac9562c9 Toys & Games $276.68 194 3.9 12 BULK-d16b943d
15761 Bulk Product 942f9e4e Sports & Outdoors $645.08 393 2.6 29 BULK-c763e6ec
15762 Bulk Product e06cbcf1 Books $679.19 281 4.8 72 BULK-8090e393
15763 Bulk Product 7ea5a5f2 Toys & Games $416.04 375 2.0 20 BULK-80cf86c0
15764 Bulk Product d5eb5508 Electronics $566.66 25 1.4 31 BULK-9a26bbfa
15765 Bulk Product 51eb579a Home & Garden $937.16 345 1.6 12 BULK-62c83488
15766 Bulk Product f6ddb075 Sports & Outdoors $282.16 392 4.1 86 BULK-246ed610
15767 Bulk Product 95b8dc1c Books $862.33 147 1.8 3 BULK-05325756
15768 Bulk Product 931f325e Clothing $421.42 25 4.7 4 BULK-3d8ceca9
15769 Bulk Product fd80d942 Clothing $227.90 154 4.7 82 BULK-66c92b01
15770 Bulk Product 6dcd6f61 Sports & Outdoors $540.62 339 4.2 49 BULK-a0f58e77
15771 Bulk Product 4c2199d9 Toys & Games $590.77 469 0.3 49 BULK-63edcccc
15772 Bulk Product 22ff5477 Home & Garden $527.75 380 1.8 36 BULK-84000870
15773 Bulk Product f360a206 Sports & Outdoors $274.31 319 3.5 66 BULK-75cd586d
15774 Bulk Product d08aaa72 Books $504.51 99 4.6 95 BULK-10e17737
15775 Bulk Product bfd1eb43 Electronics $402.67 228 3.0 91 BULK-3577f396
15776 Bulk Product a1fb5f9e Clothing $606.59 118 1.0 9 BULK-e7f0c724
15777 Bulk Product f580c7ed Sports & Outdoors $599.49 57 4.8 26 BULK-f3c5db10
15778 Bulk Product b6125584 Home & Garden $113.60 346 4.0 81 BULK-1373c3bf
15779 Bulk Product aa0f05c6 Electronics $705.37 430 4.8 88 BULK-d8c433dc
15780 Bulk Product 89a0f9b0 Books $705.50 464 2.1 49 BULK-0bdd5ce4
15781 Bulk Product 9f6dad30 Toys & Games $281.61 277 1.1 47 BULK-8bccaecb
15782 Bulk Product b5083613 Clothing $597.90 83 4.3 66 BULK-46c3016f
15783 Bulk Product 6017901a Sports & Outdoors $45.28 319 3.0 5 BULK-b9e53e00
15784 Bulk Product 27f79338 Electronics $249.90 67 4.2 7 BULK-f809f70c
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