Efficient Pagination with Skip/Take

Efficient pagination using OFFSET-FETCH on SQL Server.

Execution Time

21 ms

Page Size

25

Current Page

588 / 978

Total Records

24441

Items per page: 25 50 100 200

Page 588 Results Showing 14676 - 14700 of 24441

ID Name Category Price Stock Rating Reviews SKU
15235 Bulk Product ec60c44c Clothing $654.59 271 2.3 40 BULK-c08ec34a
15236 Bulk Product 051d30c2 Books $859.16 242 1.9 97 BULK-fc1a74b6
15237 Bulk Product e5ea121f Books $312.01 142 3.0 62 BULK-b260f36b
15238 Bulk Product 9bfff0f7 Toys & Games $143.36 463 3.6 96 BULK-76a9ea40
15239 Bulk Product bcddc142 Clothing $228.13 259 2.9 89 BULK-c638efe1
15240 Bulk Product 7d33e287 Books $174.47 403 4.2 90 BULK-8708fd8b
15241 Bulk Product 7525b6d8 Sports & Outdoors $187.17 294 3.0 12 BULK-98672f5a
15242 Bulk Product e630df6e Sports & Outdoors $465.42 66 4.0 12 BULK-52fc4df5
15243 Bulk Product 66d68c1c Clothing $77.43 385 2.7 13 BULK-4eb42c19
15244 Bulk Product 7ebae1f5 Home & Garden $382.47 230 4.3 38 BULK-f0e5c497
15245 Bulk Product 62d5ab1a Toys & Games $386.01 495 0.6 91 BULK-deee7b73
15246 Bulk Product c33c7e4a Electronics $846.45 52 0.6 40 BULK-12f57e4f
15247 Bulk Product 0e3b6e77 Clothing $850.51 230 1.1 16 BULK-76e3afdd
15248 Bulk Product 914b69e5 Clothing $528.85 183 2.2 23 BULK-30312bcb
15249 Bulk Product b41e4744 Books $429.31 146 2.1 95 BULK-fb4597bc
15250 Bulk Product 7a9c13de Books $346.87 191 3.8 28 BULK-fc263c2e
15251 Bulk Product 492962f2 Sports & Outdoors $871.71 485 4.8 58 BULK-bc647fb1
15252 Bulk Product 5f86a8b2 Toys & Games $498.53 59 4.7 74 BULK-7e7ac5e9
15253 Bulk Product 1f680562 Toys & Games $177.01 429 4.3 19 BULK-3ae77fa0
15254 Bulk Product 85261cd2 Toys & Games $798.88 131 0.6 61 BULK-d94400d1
15255 Bulk Product c484e30e Toys & Games $320.68 119 0.3 98 BULK-00f85356
15256 Bulk Product 520c1a7c Toys & Games $318.92 389 4.8 69 BULK-938b59cc
15257 Bulk Product a541f8f4 Sports & Outdoors $335.93 133 4.3 2 BULK-1151670b
15258 Bulk Product 4de4e597 Sports & Outdoors $106.95 243 2.1 63 BULK-7ff386f6
15259 Bulk Product 920fcc5c Clothing $340.53 403 4.7 75 BULK-d3a7b2cd
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