Efficient Pagination with Skip/Take

Efficient pagination using OFFSET-FETCH on SQL Server.

Execution Time

46 ms

Page Size

25

Current Page

352 / 978

Total Records

24441

Items per page: 25 50 100 200

Page 352 Results Showing 8776 - 8800 of 24441

ID Name Category Price Stock Rating Reviews SKU
9335 Bulk Product 7e0efb57 Toys & Games $662.93 215 0.9 39 BULK-25646d4c
9336 Bulk Product 2b672755 Clothing $485.03 343 4.6 18 BULK-dbd49ec0
9337 Bulk Product a7129f35 Books $452.65 95 4.5 50 BULK-12873556
9338 Bulk Product 2645b657 Books $560.49 350 3.7 27 BULK-06f88605
9339 Bulk Product 1a852faa Clothing $599.36 359 0.4 96 BULK-91666d3c
9340 Bulk Product 8eeb96c8 Clothing $68.52 325 2.8 57 BULK-cebacb85
9341 Bulk Product ac68dc37 Electronics $617.50 465 1.7 7 BULK-b60eade2
9342 Bulk Product c282a4bb Toys & Games $748.14 22 1.3 12 BULK-fa7a3164
9343 Bulk Product 167cfcef Clothing $852.60 146 2.6 74 BULK-9680d011
9344 Bulk Product 735c7199 Clothing $904.94 65 1.2 19 BULK-a092d9ab
9345 Bulk Product 152c7030 Clothing $695.09 461 0.3 36 BULK-edcea634
9346 Bulk Product 9ec9b8fd Sports & Outdoors $837.04 222 2.7 82 BULK-3bb67723
9347 Bulk Product dc93ade5 Clothing $742.54 82 0.3 14 BULK-423c76dc
9348 Bulk Product 7a0ba3c2 Toys & Games $287.56 375 0.3 61 BULK-111e5dea
9349 Bulk Product 54463bf0 Clothing $916.03 268 1.1 56 BULK-40d8136d
9350 Bulk Product b261436a Sports & Outdoors $885.50 269 3.2 94 BULK-e3f9d481
9351 Bulk Product 90cbd7d7 Books $165.06 360 4.6 15 BULK-985c0bda
9352 Bulk Product 92b455c5 Sports & Outdoors $364.95 42 0.7 30 BULK-3fca1110
9353 Bulk Product 37e7bef4 Electronics $256.46 45 4.6 16 BULK-3a6a33b7
9354 Bulk Product 6ad42d0b Electronics $931.08 349 1.9 15 BULK-19b48401
9355 Bulk Product 78f0ad9c Toys & Games $10.12 15 3.8 67 BULK-780abea4
9356 Bulk Product e57360bc Sports & Outdoors $715.85 453 0.1 83 BULK-e792443a
9357 Bulk Product cdb89af4 Toys & Games $394.47 89 4.7 4 BULK-581dbe98
9358 Bulk Product 3e39c77b Home & Garden $822.74 214 2.3 74 BULK-de0a3c92
9359 Bulk Product 3b6d9f7a Clothing $504.62 123 0.8 87 BULK-312dd679
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