Efficient Pagination with Skip/Take

Efficient pagination using OFFSET-FETCH on SQL Server.

Execution Time

37 ms

Page Size

25

Current Page

469 / 978

Total Records

24441

Items per page: 25 50 100 200

Page 469 Results Showing 11701 - 11725 of 24441

ID Name Category Price Stock Rating Reviews SKU
12260 Bulk Product cd09e17e Clothing $313.96 39 3.4 38 BULK-3c145c8b
12261 Bulk Product 31f66dc2 Home & Garden $608.94 220 1.1 43 BULK-45e10674
12262 Bulk Product 577c1ccb Books $922.66 44 3.2 12 BULK-a570223a
12263 Bulk Product 7483cf33 Electronics $809.23 180 2.9 53 BULK-e9d0f4ef
12264 Bulk Product 7a87ce86 Toys & Games $137.06 54 1.0 33 BULK-75dada9b
12265 Bulk Product c0803aca Sports & Outdoors $710.31 417 2.5 74 BULK-0af520ac
12266 Bulk Product 5d042cc9 Electronics $879.70 397 2.7 37 BULK-a7de9000
12267 Bulk Product 7a6c5d41 Clothing $50.42 18 4.5 77 BULK-b57a2574
12268 Bulk Product b5b8f565 Home & Garden $27.63 423 3.5 60 BULK-39304b42
12269 Bulk Product 07bf400a Home & Garden $910.40 391 0.3 64 BULK-986719f0
12270 Bulk Product d9330828 Home & Garden $33.87 496 4.1 68 BULK-3f58d197
12271 Bulk Product 3271737f Sports & Outdoors $106.36 176 2.4 10 BULK-0d7bfce5
12272 Bulk Product d37c8f5e Clothing $392.23 466 1.4 70 BULK-32e8b5c6
12273 Bulk Product 8d0c09a1 Home & Garden $164.82 123 2.3 91 BULK-1d59f2a6
12274 Bulk Product 6a426c8f Home & Garden $627.38 55 1.3 7 BULK-34d621a4
12275 Bulk Product 55cbecb8 Home & Garden $41.76 428 2.6 87 BULK-cf449704
12276 Bulk Product b54d6457 Sports & Outdoors $832.94 37 3.2 2 BULK-f8adc499
12277 Bulk Product 5dd5d5da Toys & Games $574.48 494 3.6 31 BULK-9337aa2d
12278 Bulk Product d633d9ed Books $910.23 145 4.2 42 BULK-d5a7cf42
12279 Bulk Product 2ccfa50b Home & Garden $653.84 374 0.8 16 BULK-9d84933d
12280 Bulk Product d2cf1049 Sports & Outdoors $25.30 163 4.4 67 BULK-6a153360
12281 Bulk Product c3348791 Toys & Games $357.08 399 2.6 41 BULK-b6b56c71
12282 Bulk Product a4b89d58 Books $251.28 86 2.5 73 BULK-7f5b0108
12283 Bulk Product a0a22aad Electronics $266.67 363 2.9 50 BULK-0b8eec1f
12284 Bulk Product 94e3a59e Books $804.67 382 2.2 76 BULK-8e758adb
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