Efficient Pagination with Skip/Take

Efficient pagination using OFFSET-FETCH on SQL Server.

Execution Time

71 ms

Page Size

25

Current Page

925 / 978

Total Records

24441

Items per page: 25 50 100 200

Page 925 Results Showing 23101 - 23125 of 24441

ID Name Category Price Stock Rating Reviews SKU
23660 Bulk Product 0cd568bf Clothing $647.07 473 4.8 34 BULK-366bbaaf
23661 Bulk Product d99c4bca Home & Garden $940.19 467 1.2 91 BULK-26f00dac
23662 Bulk Product ee4e507e Home & Garden $588.46 494 0.3 20 BULK-ba4555b5
23663 Bulk Product 7ba6d674 Clothing $493.54 499 2.3 93 BULK-8f399ed9
23664 Bulk Product 5ea84272 Electronics $558.57 235 1.1 27 BULK-753c9d91
23665 Bulk Product 88ee48d7 Clothing $707.86 216 1.2 99 BULK-e119b028
23666 Bulk Product 5dacadc6 Sports & Outdoors $1,002.18 393 0.9 97 BULK-35f9ecfd
23667 Bulk Product 24365987 Sports & Outdoors $828.64 374 4.8 17 BULK-3472a5e9
23668 Bulk Product 956616a4 Clothing $121.64 163 3.4 60 BULK-f18bab18
23669 Bulk Product e872383c Books $874.60 186 3.8 57 BULK-f696770a
23670 Bulk Product 08199fcd Clothing $805.43 447 1.7 18 BULK-8cf79b1d
23671 Bulk Product 4d1e508a Books $976.28 88 3.5 88 BULK-c489461e
23672 Bulk Product 437d894b Home & Garden $330.19 78 1.7 83 BULK-645dd178
23673 Bulk Product 110a948b Books $450.82 189 3.9 25 BULK-f9940e46
23674 Bulk Product 77f4502d Electronics $645.55 228 0.5 32 BULK-59f1f8c6
23675 Bulk Product 0d21ed75 Sports & Outdoors $985.94 211 2.8 95 BULK-74ab1412
23676 Bulk Product b50e5426 Electronics $700.46 136 2.4 49 BULK-c559c15e
23677 Bulk Product 9eaaa0b5 Sports & Outdoors $117.37 439 1.6 19 BULK-8c2d538b
23678 Bulk Product 2c005a83 Clothing $192.01 142 0.5 23 BULK-864d7c01
23679 Bulk Product 51378778 Electronics $275.99 335 4.5 14 BULK-e4c9d106
23680 Bulk Product e714ef28 Sports & Outdoors $571.55 225 1.8 99 BULK-03a8938d
23681 Bulk Product a7b2a90c Clothing $349.00 426 2.5 47 BULK-a70d2046
23682 Bulk Product c77f32b8 Books $384.53 112 4.1 17 BULK-6addbf92
23683 Bulk Product b0462c6f Toys & Games $166.42 452 4.5 19 BULK-21077b17
23684 Bulk Product 740b8bc7 Clothing $806.72 485 2.1 29 BULK-3d010f09
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