Efficient Pagination with Skip/Take

Efficient pagination using OFFSET-FETCH on SQL Server.

Execution Time

24 ms

Page Size

25

Current Page

635 / 978

Total Records

24441

Items per page: 25 50 100 200

Page 635 Results Showing 15851 - 15875 of 24441

ID Name Category Price Stock Rating Reviews SKU
16410 Bulk Product d8f13b55 Books $160.81 287 4.9 60 BULK-29e2516a
16411 Bulk Product d61df048 Books $489.96 481 3.2 57 BULK-c77b5c6f
16412 Bulk Product 3ab0d9fb Home & Garden $892.44 461 1.4 34 BULK-bd65b8ff
16413 Bulk Product ef7f67ca Home & Garden $79.95 99 1.4 27 BULK-8cd59c5b
16414 Bulk Product a536dd6a Toys & Games $35.56 215 4.5 57 BULK-457a64af
16415 Bulk Product 793759e8 Clothing $625.77 20 1.2 45 BULK-3c959ed7
16416 Bulk Product 855c429b Electronics $596.90 54 4.1 32 BULK-387ca0f7
16417 Bulk Product e29471be Sports & Outdoors $484.64 278 4.4 25 BULK-9668a6d7
16418 Bulk Product 599a0a2c Books $28.01 133 4.7 28 BULK-aed145e5
16419 Bulk Product 9f1d532c Home & Garden $119.08 379 4.6 74 BULK-31e64ae8
16420 Bulk Product 798f6f0b Toys & Games $308.66 313 4.5 7 BULK-f6f35ebb
16421 Bulk Product f6aea849 Books $467.51 93 1.9 89 BULK-25a6bdfc
16422 Bulk Product 6d4935ad Sports & Outdoors $560.32 488 3.8 23 BULK-d3686051
16423 Bulk Product 188b6876 Sports & Outdoors $460.56 208 2.2 41 BULK-84141aa9
16424 Bulk Product e658c851 Books $313.59 415 3.5 79 BULK-b6f22e63
16425 Bulk Product 50fbd3c4 Sports & Outdoors $699.91 217 1.5 16 BULK-c0f9761b
16426 Bulk Product 2278576d Sports & Outdoors $851.12 147 2.7 14 BULK-bcbeb784
16427 Bulk Product 1fa72e6a Clothing $841.76 432 0.7 60 BULK-10a87de0
16428 Bulk Product f432eb3d Sports & Outdoors $233.51 14 4.3 7 BULK-18255058
16429 Bulk Product cc883c79 Electronics $29.58 385 4.3 81 BULK-3a7bee13
16430 Bulk Product 94997174 Sports & Outdoors $302.89 121 4.0 99 BULK-e6e1c32d
16431 Bulk Product 74eb83d9 Electronics $207.92 374 4.9 2 BULK-70a1c409
16432 Bulk Product c7bfb509 Sports & Outdoors $57.66 71 1.6 13 BULK-a14d37e1
16433 Bulk Product 370722ba Books $877.71 14 3.9 75 BULK-f504861d
16434 Bulk Product 7ec960de Home & Garden $713.58 50 0.3 28 BULK-1892302f
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