Efficient Pagination with Skip/Take

Efficient pagination using OFFSET-FETCH on SQL Server.

Execution Time

27 ms

Page Size

25

Current Page

270 / 978

Total Records

24441

Items per page: 25 50 100 200

Page 270 Results Showing 6726 - 6750 of 24441

ID Name Category Price Stock Rating Reviews SKU
7285 Bulk Product 2c7dd0cf Electronics $548.11 402 4.6 34 BULK-693257cb
7286 Bulk Product ae4a80a5 Clothing $891.98 417 0.5 50 BULK-b0b440a1
7287 Bulk Product 720faf0c Books $281.09 70 4.7 74 BULK-7e1a9045
7288 Bulk Product 69282b0a Toys & Games $160.51 331 0.8 55 BULK-b4cc235d
7289 Bulk Product 63e90773 Clothing $530.76 208 4.1 34 BULK-7006aef5
7290 Bulk Product db06fc40 Books $699.93 291 0.5 84 BULK-7a106289
7291 Bulk Product 39619199 Sports & Outdoors $223.23 104 3.1 75 BULK-cfde1c1c
7292 Bulk Product cddec67d Electronics $858.32 186 0.7 5 BULK-2cb53b7e
7293 Bulk Product dc9f3582 Electronics $374.94 458 1.2 33 BULK-5629b7af
7294 Bulk Product 57150b1e Toys & Games $206.46 190 4.3 25 BULK-9d6f526e
7295 Bulk Product cf34afab Home & Garden $326.85 268 2.7 75 BULK-11bedb41
7296 Bulk Product 2581ba70 Clothing $463.47 321 4.1 92 BULK-8591671d
7297 Bulk Product aaea1d16 Books $762.98 461 3.5 82 BULK-01d4f3e4
7298 Bulk Product da770956 Clothing $895.08 120 4.9 46 BULK-7ee34d03
7299 Bulk Product 9bdc6565 Books $696.71 147 4.5 58 BULK-a3827fb1
7300 Bulk Product cb160b7e Clothing $222.85 453 2.0 10 BULK-26fa522f
7301 Bulk Product 10f65b79 Home & Garden $971.25 41 3.6 45 BULK-964e1953
7302 Bulk Product 016ee2b4 Electronics $404.43 366 1.8 51 BULK-48724907
7303 Bulk Product 9d14007c Home & Garden $517.51 209 2.3 53 BULK-bf59ec7e
7304 Bulk Product 40d86876 Clothing $633.92 240 4.8 81 BULK-5cf6fbb1
7305 Bulk Product 8918e71b Electronics $102.79 80 4.3 30 BULK-200a09be
7306 Bulk Product c0faf08d Home & Garden $296.25 8 0.5 98 BULK-ce0de386
7307 Bulk Product 84870cc5 Home & Garden $497.08 212 4.1 75 BULK-4a4f9ba8
7308 Bulk Product 37f5d7d4 Home & Garden $807.67 428 0.2 85 BULK-249ab547
7309 Bulk Product f0929b4c Clothing $838.45 367 3.8 28 BULK-7efed8d1
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