Efficient Pagination with Skip/Take

Efficient pagination using OFFSET-FETCH on SQL Server.

Execution Time

55 ms

Page Size

25

Current Page

949 / 978

Total Records

24441

Items per page: 25 50 100 200

Page 949 Results Showing 23701 - 23725 of 24441

ID Name Category Price Stock Rating Reviews SKU
24260 Bulk Product d2080169 Sports & Outdoors $829.53 476 0.3 19 BULK-7e93ffcc
24261 Bulk Product 4272137c Home & Garden $628.80 375 0.5 79 BULK-25ac654b
24262 Bulk Product cf851bcb Toys & Games $30.50 349 3.6 32 BULK-edefc1ea
24263 Bulk Product b96e8818 Clothing $53.85 291 2.2 31 BULK-f4312e68
24264 Bulk Product 1421b459 Sports & Outdoors $321.38 248 0.4 62 BULK-ca02a933
24265 Bulk Product 47c86741 Sports & Outdoors $976.69 282 1.7 41 BULK-416a57ea
24266 Bulk Product d3372d17 Electronics $75.54 115 4.9 44 BULK-8d02b67f
24267 Bulk Product 0e2a0d7b Home & Garden $138.72 54 2.3 68 BULK-932eec8f
24268 Bulk Product c26d0201 Books $293.01 370 2.7 38 BULK-2cffa2d5
24269 Bulk Product db4a36db Home & Garden $224.45 68 1.1 41 BULK-ba646713
24270 Bulk Product c7bb35e7 Clothing $886.65 396 4.0 56 BULK-a166c04e
24271 Bulk Product b41ed421 Books $493.62 179 4.5 65 BULK-82fe2fca
24272 Bulk Product d373fb3f Electronics $332.96 42 3.4 58 BULK-1f4a69bd
24273 Bulk Product 3eea6b8e Electronics $91.93 75 4.8 61 BULK-5b4b933c
24274 Bulk Product 8195dfc6 Sports & Outdoors $427.78 361 1.9 58 BULK-b4f6fdf2
24275 Bulk Product 71b454e3 Clothing $118.99 338 5.0 0 BULK-bb03bee6
24276 Bulk Product 8e4e8538 Electronics $168.08 243 0.4 6 BULK-8aa15f9a
24277 Bulk Product 7fbae816 Home & Garden $669.40 357 2.9 41 BULK-d45c398f
24278 Bulk Product 342cff71 Clothing $957.81 359 2.7 68 BULK-7be4fc11
24279 Bulk Product 66149958 Clothing $598.37 77 1.5 33 BULK-d1cedff7
24280 Bulk Product 47a356e2 Clothing $462.03 74 0.6 65 BULK-e0f9e1c2
24281 Bulk Product 1f43bce8 Sports & Outdoors $412.58 37 3.6 48 BULK-1e2c17bc
24282 Bulk Product 735db58b Toys & Games $419.15 71 3.6 60 BULK-89c8cda5
24283 Bulk Product a5920cb7 Electronics $817.38 403 2.4 22 BULK-9a6f0f01
24284 Bulk Product 94b0a4ff Electronics $680.07 480 3.7 97 BULK-b357998f
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