Efficient Pagination with Skip/Take

Efficient pagination using OFFSET-FETCH on SQL Server.

Execution Time

28 ms

Page Size

25

Current Page

864 / 978

Total Records

24441

Items per page: 25 50 100 200

Page 864 Results Showing 21576 - 21600 of 24441

ID Name Category Price Stock Rating Reviews SKU
22135 Bulk Product 46a93283 Clothing $140.03 456 3.7 94 BULK-91722076
22136 Bulk Product 69955b5c Books $387.68 409 3.7 11 BULK-3efbc494
22137 Bulk Product 80baf613 Toys & Games $880.20 117 1.4 39 BULK-f47180c8
22138 Bulk Product ecf377d1 Clothing $283.74 357 3.4 67 BULK-f4fbbe2c
22139 Bulk Product 8db70f43 Sports & Outdoors $513.84 489 2.6 89 BULK-90749d9b
22140 Bulk Product 0232b5fc Clothing $898.29 481 0.4 28 BULK-61f4ddd9
22141 Bulk Product 9785a22d Home & Garden $140.53 190 1.0 43 BULK-06038946
22142 Bulk Product 7de51ad0 Clothing $27.50 450 0.9 66 BULK-f7da1b60
22143 Bulk Product c3802e3f Toys & Games $518.38 203 3.6 27 BULK-c4084dab
22144 Bulk Product fd4dc0dc Home & Garden $577.64 387 1.7 9 BULK-9c417027
22145 Bulk Product 6787ec64 Clothing $375.31 178 0.3 61 BULK-1e9e5a6a
22146 Bulk Product a5941530 Books $33.77 182 0.5 78 BULK-342985b6
22147 Bulk Product 8738adcd Books $269.61 15 4.9 72 BULK-f71e607e
22148 Bulk Product 54a84ee2 Clothing $897.56 331 1.1 72 BULK-8caf4785
22149 Bulk Product 87616a6e Toys & Games $160.86 461 3.6 68 BULK-bc6e397a
22150 Bulk Product 34e24dd4 Toys & Games $757.24 427 2.8 32 BULK-3bb37847
22151 Bulk Product 6364018a Home & Garden $496.20 406 3.2 86 BULK-88efa7d9
22152 Bulk Product 2e08bb0e Clothing $279.42 26 3.8 34 BULK-f1bfbc77
22153 Bulk Product 40f8ad40 Sports & Outdoors $19.80 144 1.5 50 BULK-d3d53a38
22154 Bulk Product 868de3c0 Books $331.35 33 0.9 55 BULK-78b84b2e
22155 Bulk Product dbb6e0c2 Toys & Games $68.25 226 1.6 67 BULK-413d47f3
22156 Bulk Product ab38992f Toys & Games $805.83 361 0.5 96 BULK-cbaa475e
22157 Bulk Product 6a481a3b Electronics $540.23 58 5.0 13 BULK-00262124
22158 Bulk Product b600ef1a Books $18.10 99 3.0 67 BULK-e41781d0
22159 Bulk Product e083d88f Sports & Outdoors $1,004.76 411 3.4 59 BULK-49ccd4d6
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