Efficient Pagination with Skip/Take

Efficient pagination using OFFSET-FETCH on SQL Server.

Execution Time

41 ms

Page Size

25

Current Page

590 / 978

Total Records

24441

Items per page: 25 50 100 200

Page 590 Results Showing 14726 - 14750 of 24441

ID Name Category Price Stock Rating Reviews SKU
15285 Bulk Product 50371ec0 Home & Garden $262.06 100 3.2 48 BULK-0ba327a1
15286 Bulk Product 60cc2537 Home & Garden $178.78 166 1.0 7 BULK-36a60f0f
15287 Bulk Product 2bf1c0ab Sports & Outdoors $83.10 384 4.2 26 BULK-3edf9748
15288 Bulk Product 2c674b42 Books $556.66 278 3.5 30 BULK-dfb8cfa1
15289 Bulk Product ffb4c686 Clothing $595.71 244 0.6 24 BULK-bc2b47d3
15290 Bulk Product 007d64fe Toys & Games $979.86 23 3.9 22 BULK-81685af7
15291 Bulk Product 64d53cc2 Toys & Games $780.46 48 1.4 39 BULK-18cb6d2f
15292 Bulk Product a6d89f20 Books $995.59 187 0.3 65 BULK-ed341288
15293 Bulk Product 3f010dd2 Electronics $708.24 124 4.1 79 BULK-9946af73
15294 Bulk Product dbc51369 Clothing $21.05 36 0.5 73 BULK-794f355d
15295 Bulk Product 87b23161 Books $823.97 363 2.2 35 BULK-cf3974c6
15296 Bulk Product 97e1136b Sports & Outdoors $501.23 216 0.0 97 BULK-68e87ac0
15297 Bulk Product 567535c6 Sports & Outdoors $492.51 343 1.4 14 BULK-9d1975e1
15298 Bulk Product 39fdc905 Clothing $491.32 271 4.6 42 BULK-c1c60028
15299 Bulk Product 78415387 Clothing $821.45 50 1.2 71 BULK-df0605d6
15300 Bulk Product 9a95f0e4 Sports & Outdoors $131.84 230 4.8 82 BULK-02916bd4
15301 Bulk Product b62ad1dd Sports & Outdoors $218.04 214 1.5 13 BULK-dce4049c
15302 Bulk Product b410523f Home & Garden $532.94 442 4.4 37 BULK-d543b4eb
15303 Bulk Product faf24a69 Electronics $786.09 150 1.8 59 BULK-f598bfa0
15304 Bulk Product f3d1db30 Electronics $596.44 89 1.5 28 BULK-47a4c836
15305 Bulk Product b40b8433 Electronics $122.02 440 1.6 14 BULK-9ba305d7
15306 Bulk Product daf3ea89 Clothing $657.70 222 2.1 1 BULK-1a924021
15307 Bulk Product 636e9722 Books $886.56 340 2.9 99 BULK-cd1e1f26
15308 Bulk Product 9997936f Home & Garden $885.78 481 1.1 47 BULK-59756d10
15309 Bulk Product 683d6e29 Clothing $532.63 278 2.4 45 BULK-fb1b24cf
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