Efficient Pagination with Skip/Take

Efficient pagination using OFFSET-FETCH on SQL Server.

Execution Time

28 ms

Page Size

25

Current Page

317 / 978

Total Records

24441

Items per page: 25 50 100 200

Page 317 Results Showing 7901 - 7925 of 24441

ID Name Category Price Stock Rating Reviews SKU
8460 Bulk Product 660bddf6 Sports & Outdoors $842.55 190 2.4 61 BULK-0001d920
8461 Bulk Product a7e7158d Electronics $640.07 135 4.3 31 BULK-56be211d
8462 Bulk Product ea2d29ca Sports & Outdoors $86.50 324 1.5 99 BULK-4739d3ab
8463 Bulk Product 26f3b77c Books $590.33 146 2.2 30 BULK-e54df95c
8464 Bulk Product d69e64b0 Home & Garden $420.04 247 3.4 42 BULK-8f8eab48
8465 Bulk Product eaa726f8 Toys & Games $916.48 355 0.6 0 BULK-9ccf1b56
8466 Bulk Product 3756145b Clothing $289.87 135 4.0 39 BULK-3f75874a
8467 Bulk Product 5022c10c Home & Garden $307.24 172 3.5 43 BULK-4dec7da9
8468 Bulk Product 9a5da0b4 Clothing $651.60 492 0.8 62 BULK-9464ef51
8469 Bulk Product 1e9cbca4 Home & Garden $20.12 455 2.7 36 BULK-6af44307
8470 Bulk Product 2f6ca383 Clothing $518.65 201 0.8 69 BULK-0e5bc8a8
8471 Bulk Product e51c9339 Electronics $928.91 331 0.2 72 BULK-cddb762f
8472 Bulk Product b3ba96eb Clothing $394.37 409 4.8 32 BULK-b391a409
8473 Bulk Product 8701430c Toys & Games $855.44 451 1.3 47 BULK-e7db9c43
8474 Bulk Product 2ff96911 Sports & Outdoors $742.40 5 0.9 47 BULK-27cca103
8475 Bulk Product d3be0b5c Electronics $125.45 137 3.6 40 BULK-cf6b3d78
8476 Bulk Product 913c74c1 Toys & Games $11.77 293 3.2 60 BULK-ae3540dd
8477 Bulk Product 2dabf0d1 Home & Garden $597.75 239 1.7 99 BULK-c0eeb2ea
8478 Bulk Product 54b4913d Toys & Games $671.62 271 0.3 7 BULK-bc253e2e
8479 Bulk Product 2f6cd81e Books $502.03 186 0.5 25 BULK-a9dcfc5b
8480 Bulk Product 60391ad1 Books $659.29 397 2.1 47 BULK-a068e47f
8481 Bulk Product 37e265b7 Home & Garden $955.82 59 1.4 46 BULK-e1d45a0e
8482 Bulk Product e79379d6 Books $666.09 66 0.4 65 BULK-87a4418c
8483 Bulk Product 8e249151 Toys & Games $854.80 351 4.9 88 BULK-45fb2489
8484 Bulk Product c5f32749 Clothing $333.60 137 2.8 3 BULK-a39e9263
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