Efficient Pagination with Skip/Take

Efficient pagination using OFFSET-FETCH on SQL Server.

Execution Time

21 ms

Page Size

25

Current Page

940 / 978

Total Records

24441

Items per page: 25 50 100 200

Page 940 Results Showing 23476 - 23500 of 24441

ID Name Category Price Stock Rating Reviews SKU
24035 Bulk Product 547cdbd1 Clothing $931.66 478 1.8 62 BULK-47650ced
24036 Bulk Product dd1d9166 Home & Garden $460.93 21 2.4 4 BULK-af063190
24037 Bulk Product 1488b477 Toys & Games $510.95 24 0.9 33 BULK-dda3c7d4
24038 Bulk Product 8f9eddf2 Home & Garden $419.88 122 0.5 81 BULK-dcd2a88e
24039 Bulk Product ad56fab8 Clothing $918.25 260 0.4 7 BULK-dcc1743f
24040 Bulk Product 2f8b9bbc Clothing $482.65 72 4.5 48 BULK-0eb5f4cc
24041 Bulk Product 4d2551ff Electronics $964.35 204 3.4 55 BULK-8e3af9c5
24042 Bulk Product 2f6fd52e Toys & Games $109.49 318 4.2 61 BULK-72ca7cd2
24043 Bulk Product 78064d5e Sports & Outdoors $848.16 361 3.7 44 BULK-fd898395
24044 Bulk Product fd5452b2 Books $176.78 116 5.0 27 BULK-55d60f09
24045 Bulk Product d5dc28bc Books $123.98 495 2.9 57 BULK-b3c236b7
24046 Bulk Product 1e68cb78 Home & Garden $938.16 388 1.8 32 BULK-2f34a484
24047 Bulk Product 2513e4e8 Electronics $212.64 426 1.8 45 BULK-9733c4bd
24048 Bulk Product ae25bb25 Electronics $513.01 168 4.7 95 BULK-9e9c1fc3
24049 Bulk Product 2902ecbf Sports & Outdoors $1,008.69 13 4.0 17 BULK-ac22a9da
24050 Bulk Product ee82c1a4 Sports & Outdoors $729.75 433 4.3 14 BULK-3f5276be
24051 Bulk Product 34da4dd3 Toys & Games $831.26 365 2.9 1 BULK-d91a2013
24052 Bulk Product 1f3285ad Clothing $847.66 255 2.0 78 BULK-7ab8155a
24053 Bulk Product 16e638da Books $910.98 472 0.1 65 BULK-82488bb9
24054 Bulk Product d0d149aa Sports & Outdoors $481.73 18 3.4 78 BULK-b1650ac8
24055 Bulk Product 3ccaee98 Books $474.91 386 1.5 98 BULK-d728db2a
24056 Bulk Product 96e20169 Books $72.26 408 0.6 77 BULK-4103131c
24057 Bulk Product 8d8a634b Electronics $833.32 438 0.3 9 BULK-576976a1
24058 Bulk Product fad56c23 Electronics $152.52 46 4.0 70 BULK-8d42c351
24059 Bulk Product 391825d2 Home & Garden $930.34 302 1.0 91 BULK-549c7de9
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