Efficient Pagination with Skip/Take

Efficient pagination using OFFSET-FETCH on SQL Server.

Execution Time

85 ms

Page Size

25

Current Page

240 / 978

Total Records

24441

Items per page: 25 50 100 200

Page 240 Results Showing 5976 - 6000 of 24441

ID Name Category Price Stock Rating Reviews SKU
6535 Bulk Product 3c23ee90 Clothing $590.40 223 2.2 69 BULK-ed49430e
6536 Bulk Product b3f8d236 Toys & Games $839.98 375 3.3 11 BULK-5e914b75
6537 Bulk Product 784e8514 Clothing $163.42 195 0.7 51 BULK-67866c9d
6538 Bulk Product 9794c401 Sports & Outdoors $677.69 423 4.3 60 BULK-72fbefb2
6539 Bulk Product ba77fbf1 Toys & Games $68.50 23 3.8 50 BULK-ea7db789
6540 Bulk Product ee069193 Toys & Games $60.85 401 3.1 76 BULK-66d5bd54
6541 Bulk Product 842b4b90 Toys & Games $950.86 371 2.4 40 BULK-ea505b06
6542 Bulk Product 9d37840e Electronics $24.74 266 3.2 71 BULK-a9235f78
6543 Bulk Product bcd1e7c2 Home & Garden $109.86 394 2.0 69 BULK-7fa819b3
6544 Bulk Product b1349d55 Sports & Outdoors $703.92 244 4.6 37 BULK-4913ba58
6545 Bulk Product 2a0661e0 Sports & Outdoors $224.21 309 3.3 90 BULK-56bb0e9d
6546 Bulk Product 2289882e Books $557.24 342 1.2 99 BULK-eb69664c
6547 Bulk Product 885d70b2 Home & Garden $513.51 452 4.2 55 BULK-0753184e
6548 Bulk Product a63c5511 Clothing $116.53 292 1.2 32 BULK-9c9fe78c
6549 Bulk Product 9f1c6d96 Clothing $449.13 117 3.1 34 BULK-7a07c2a7
6550 Bulk Product 7d5682a5 Sports & Outdoors $570.68 288 3.2 60 BULK-86e4670c
6551 Bulk Product 427e6ad9 Clothing $217.61 191 1.8 42 BULK-507bfed6
6552 Bulk Product 1b46af9f Sports & Outdoors $657.20 152 1.6 29 BULK-a5ed0d30
6553 Bulk Product 45d4547b Sports & Outdoors $274.04 122 1.8 75 BULK-de6a25a5
6554 Bulk Product 219a76ae Books $521.98 360 0.6 84 BULK-bbafa65c
6555 Bulk Product adc7cbfd Books $688.93 367 1.1 5 BULK-ca1c50bd
6556 Bulk Product eb96641f Sports & Outdoors $976.74 215 1.0 24 BULK-a9d3ab5d
6557 Bulk Product 75d78b93 Home & Garden $253.12 287 3.6 39 BULK-2b05cbe5
6558 Bulk Product e4091ec3 Sports & Outdoors $380.30 145 4.3 53 BULK-6ad59639
6559 Bulk Product 3287bfae Toys & Games $918.82 155 1.4 26 BULK-c8e53804
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