Efficient Pagination with Skip/Take

Efficient pagination using OFFSET-FETCH on SQL Server.

Execution Time

50 ms

Page Size

25

Current Page

953 / 978

Total Records

24441

Items per page: 25 50 100 200

Page 953 Results Showing 23801 - 23825 of 24441

ID Name Category Price Stock Rating Reviews SKU
24360 Bulk Product 7f683cbe Electronics $559.88 205 4.6 18 BULK-1feb3248
24361 Bulk Product 62385c39 Home & Garden $587.39 345 4.4 35 BULK-32e6dc20
24362 Bulk Product 917f4f0a Books $23.01 458 2.8 20 BULK-1e7efe09
24363 Bulk Product 08b0755d Home & Garden $934.14 434 1.3 16 BULK-30fcad63
24364 Bulk Product e1059dbd Home & Garden $814.16 353 0.3 73 BULK-51d91d98
24365 Bulk Product 511c2b5f Sports & Outdoors $1,008.16 386 1.6 27 BULK-525e13cf
24366 Bulk Product befbf5c1 Home & Garden $562.94 229 3.2 11 BULK-de1d443b
24367 Bulk Product b6e7d123 Electronics $79.20 168 1.8 67 BULK-90d88f49
24368 Bulk Product 09d33294 Sports & Outdoors $360.58 237 2.8 50 BULK-c11dfaba
24369 Bulk Product aef94ac7 Electronics $891.14 191 3.2 63 BULK-d778d135
24370 Bulk Product 9dbc004c Electronics $702.76 248 3.4 85 BULK-3eb103c4
24371 Bulk Product f90ad9b5 Toys & Games $456.48 151 4.6 77 BULK-d90521e6
24372 Bulk Product 5edd9ef2 Electronics $680.93 484 4.5 25 BULK-1cfed55c
24373 Bulk Product f64c2307 Electronics $286.27 155 0.7 97 BULK-d37e413f
24374 Bulk Product e7ae87fb Books $735.61 98 3.1 69 BULK-b9b58a11
24375 Bulk Product 59817090 Sports & Outdoors $310.73 345 3.5 10 BULK-15d5582c
24376 Bulk Product 418b24db Books $12.21 361 0.3 70 BULK-cd83bea1
24377 Bulk Product b2fbf543 Electronics $698.21 158 3.6 65 BULK-e9814d33
24378 Bulk Product 0d5af62c Clothing $421.91 143 4.7 17 BULK-26ed369e
24379 Bulk Product 64a4a832 Toys & Games $425.32 428 0.3 75 BULK-2851a9e5
24380 Bulk Product f96619e4 Toys & Games $79.22 379 0.3 3 BULK-6be8b6dd
24381 Bulk Product 655854c6 Clothing $961.99 178 4.0 10 BULK-3219e7a4
24382 Bulk Product b2b3188e Toys & Games $974.85 86 1.5 63 BULK-33a0e572
24383 Bulk Product 39fe08d4 Home & Garden $798.51 336 1.7 84 BULK-e3ba6e69
24384 Bulk Product 0c78f027 Clothing $364.00 78 1.3 40 BULK-bff167fd
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