Efficient Pagination with Skip/Take

Efficient pagination using OFFSET-FETCH on SQL Server.

Execution Time

14 ms

Page Size

25

Current Page

913 / 978

Total Records

24441

Items per page: 25 50 100 200

Page 913 Results Showing 22801 - 22825 of 24441

ID Name Category Price Stock Rating Reviews SKU
23360 Bulk Product 07b04a6f Sports & Outdoors $187.88 128 1.3 37 BULK-24f32fba
23361 Bulk Product 8faa660c Electronics $747.11 375 2.7 52 BULK-7cc7be94
23362 Bulk Product f04467ce Sports & Outdoors $709.99 123 1.9 96 BULK-2c8bc0c2
23363 Bulk Product 715188c1 Toys & Games $891.25 497 0.9 14 BULK-ee82f59c
23364 Bulk Product 81f580f6 Home & Garden $740.75 439 3.4 66 BULK-f11c56c0
23365 Bulk Product 02c8954e Home & Garden $617.21 263 0.7 51 BULK-6553e769
23366 Bulk Product e9baeb76 Clothing $198.28 446 4.5 15 BULK-2ab7de3a
23367 Bulk Product 694deb16 Toys & Games $727.68 269 2.0 81 BULK-53e1a9fc
23368 Bulk Product 1a76a8ec Toys & Games $177.45 307 1.2 2 BULK-6a6a0b9d
23369 Bulk Product 2f73f9cc Clothing $200.41 489 3.7 93 BULK-567faa5a
23370 Bulk Product 61d44884 Clothing $171.41 330 1.8 30 BULK-728d168a
23371 Bulk Product 79001d7c Books $791.86 349 1.6 47 BULK-1870da5c
23372 Bulk Product b13b3f70 Books $437.91 211 2.2 66 BULK-c2e7cef7
23373 Bulk Product af775332 Sports & Outdoors $244.18 219 1.7 8 BULK-a6f79f30
23374 Bulk Product 599ee0fd Home & Garden $377.71 168 3.7 0 BULK-c7beed42
23375 Bulk Product 4c715bdc Sports & Outdoors $490.05 269 2.0 84 BULK-7999433e
23376 Bulk Product f144ff4b Books $945.79 409 1.6 57 BULK-a2978386
23377 Bulk Product 1c8074be Sports & Outdoors $203.84 264 1.5 59 BULK-24a55664
23378 Bulk Product abe3be53 Toys & Games $269.24 154 2.4 13 BULK-7c841dd5
23379 Bulk Product a77f1012 Electronics $889.12 265 2.1 55 BULK-b09dcba5
23380 Bulk Product 54676cf8 Books $765.98 496 3.3 99 BULK-270d3753
23381 Bulk Product 57fc9144 Electronics $627.51 359 1.7 87 BULK-1f0242fa
23382 Bulk Product bb8f453d Clothing $677.88 292 3.4 73 BULK-0ef42105
23383 Bulk Product 87c51ece Home & Garden $446.33 113 4.6 2 BULK-9820989b
23384 Bulk Product fb4278bc Books $95.88 198 4.9 5 BULK-97c74f11
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