Efficient Pagination with Skip/Take

Efficient pagination using OFFSET-FETCH on SQL Server.

Execution Time

45 ms

Page Size

25

Current Page

836 / 978

Total Records

24441

Items per page: 25 50 100 200

Page 836 Results Showing 20876 - 20900 of 24441

ID Name Category Price Stock Rating Reviews SKU
21435 Bulk Product 335ecbcf Toys & Games $261.15 53 0.6 87 BULK-eed53855
21436 Bulk Product a399f2cf Sports & Outdoors $665.08 150 3.4 37 BULK-77f3d546
21437 Bulk Product 6e12f6b1 Electronics $186.17 392 3.9 58 BULK-bd115e63
21438 Bulk Product 1c9c12e9 Home & Garden $653.96 21 4.7 69 BULK-031c977a
21439 Bulk Product c165b6dc Books $140.11 81 0.0 7 BULK-6c5ec1b7
21440 Bulk Product 03c9de00 Sports & Outdoors $554.98 315 0.0 60 BULK-e5a4fe37
21441 Bulk Product fa49f9c3 Clothing $263.95 395 3.0 78 BULK-4bff2318
21442 Bulk Product f8e3505e Books $194.28 301 2.8 12 BULK-c57c2096
21443 Bulk Product 4f3d59ed Sports & Outdoors $13.92 74 4.2 90 BULK-feae3e1e
21444 Bulk Product af2a6198 Sports & Outdoors $248.63 197 1.1 88 BULK-1017926a
21445 Bulk Product e47b2bab Books $756.77 400 1.4 63 BULK-b5ef45e6
21446 Bulk Product 221adb6e Clothing $668.73 17 3.4 41 BULK-dad3240e
21447 Bulk Product 89869b4e Clothing $435.82 122 1.7 11 BULK-17fb4e24
21448 Bulk Product 7a3b4242 Sports & Outdoors $424.48 301 3.5 48 BULK-6c6064a2
21449 Bulk Product 25f9cd33 Toys & Games $344.61 299 2.6 10 BULK-139807ae
21450 Bulk Product 8324bfa5 Home & Garden $289.27 458 4.2 82 BULK-f4492958
21451 Bulk Product 5e585c4c Sports & Outdoors $139.03 437 3.9 36 BULK-5380f61d
21452 Bulk Product 63f498ef Electronics $139.63 63 2.4 42 BULK-e5269597
21453 Bulk Product 4c284e66 Sports & Outdoors $848.17 367 1.9 43 BULK-92da236b
21454 Bulk Product b177fae3 Electronics $897.55 68 4.2 80 BULK-cdf443ed
21455 Bulk Product fec54dc3 Clothing $467.58 174 2.5 15 BULK-32ab67bd
21456 Bulk Product 4cc1c4a0 Home & Garden $662.73 304 2.8 39 BULK-2752ec15
21457 Bulk Product e721d35e Toys & Games $223.47 205 2.7 3 BULK-d34f181b
21458 Bulk Product e4435372 Electronics $423.36 253 0.3 78 BULK-56192047
21459 Bulk Product 9ef6912a Electronics $979.12 328 4.2 77 BULK-9076756d
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