Efficient Pagination with Skip/Take

Efficient pagination using OFFSET-FETCH on SQL Server.

Execution Time

33 ms

Page Size

25

Current Page

485 / 978

Total Records

24441

Items per page: 25 50 100 200

Page 485 Results Showing 12101 - 12125 of 24441

ID Name Category Price Stock Rating Reviews SKU
12660 Bulk Product 62a2a688 Clothing $561.85 110 0.6 33 BULK-8aab2c42
12661 Bulk Product e684fa3d Clothing $410.95 213 4.0 32 BULK-7e322318
12662 Bulk Product e9b7a7ce Home & Garden $662.25 411 4.5 61 BULK-8317c2d8
12663 Bulk Product 0366b8b1 Home & Garden $685.66 495 3.4 25 BULK-55257321
12664 Bulk Product eddd470a Home & Garden $710.59 264 2.5 43 BULK-06696538
12665 Bulk Product 54d2a653 Sports & Outdoors $161.49 192 4.4 57 BULK-85dd29c1
12666 Bulk Product 44ecad23 Toys & Games $862.15 139 1.4 85 BULK-6c3c5fd7
12667 Bulk Product 4c6d61f2 Electronics $707.84 170 1.7 78 BULK-bd40b791
12668 Bulk Product 03447bb1 Books $209.31 440 3.0 69 BULK-37d252fa
12669 Bulk Product f20ec70f Electronics $424.20 423 1.1 34 BULK-c1502f10
12670 Bulk Product c5be997d Clothing $160.71 254 0.5 81 BULK-9aa70d75
12671 Bulk Product 6781c3c8 Home & Garden $688.56 309 2.8 37 BULK-104aec82
12672 Bulk Product 2291571c Toys & Games $164.26 318 1.6 14 BULK-af46ed51
12673 Bulk Product 0c74a06f Sports & Outdoors $532.03 165 1.7 41 BULK-99e015d8
12674 Bulk Product 5dd425ab Electronics $289.04 238 0.6 50 BULK-3b19b16d
12675 Bulk Product 69e7aa0e Electronics $335.15 368 0.2 93 BULK-adaaa3b5
12676 Bulk Product b3f8cff1 Sports & Outdoors $637.40 434 0.4 38 BULK-99fac0fb
12677 Bulk Product 67d73611 Home & Garden $938.67 198 2.3 79 BULK-3781a31a
12678 Bulk Product 10fd6ada Sports & Outdoors $674.41 361 1.0 19 BULK-37622826
12679 Bulk Product 4d7e6c86 Toys & Games $264.43 450 2.8 18 BULK-0dbf513f
12680 Bulk Product b91124c3 Sports & Outdoors $296.79 285 2.6 31 BULK-e7279c7e
12681 Bulk Product ca2b5015 Sports & Outdoors $103.95 280 2.2 26 BULK-2005ee33
12682 Bulk Product f27e2962 Toys & Games $70.73 212 2.0 69 BULK-402f385b
12683 Bulk Product facd8069 Home & Garden $130.50 232 2.5 19 BULK-b07c53a6
12684 Bulk Product 6d32448f Books $291.32 327 3.0 96 BULK-cd38f787
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