Efficient Pagination with Skip/Take

Efficient pagination using OFFSET-FETCH on SQL Server.

Execution Time

16 ms

Page Size

25

Current Page

692 / 978

Total Records

24441

Items per page: 25 50 100 200

Page 692 Results Showing 17276 - 17300 of 24441

ID Name Category Price Stock Rating Reviews SKU
17835 Bulk Product a807ae15 Clothing $448.44 150 0.3 89 BULK-b05255f3
17836 Bulk Product 5d9b0008 Clothing $259.35 382 0.8 67 BULK-60352f00
17837 Bulk Product 8094995f Clothing $228.06 342 3.8 75 BULK-dbf2e930
17838 Bulk Product f66190a2 Books $564.61 102 4.5 92 BULK-a62c16fd
17839 Bulk Product 326eccb4 Home & Garden $862.06 185 2.2 89 BULK-47c89a34
17840 Bulk Product 6c5112b8 Electronics $564.40 73 0.1 46 BULK-bf38669f
17841 Bulk Product 812c06ba Home & Garden $725.44 159 4.8 45 BULK-8e2477ae
17842 Bulk Product 37153f84 Books $235.01 180 0.2 51 BULK-73940d8a
17843 Bulk Product 0e9a741e Toys & Games $1,006.86 234 4.0 60 BULK-89076c35
17844 Bulk Product 49b34a42 Electronics $474.90 209 2.8 93 BULK-7e86be02
17845 Bulk Product d12999f7 Home & Garden $310.68 416 0.1 99 BULK-903372fd
17846 Bulk Product bcabff93 Electronics $505.45 244 3.8 86 BULK-c511e9f3
17847 Bulk Product 9bc09709 Clothing $698.90 258 0.6 37 BULK-940f569b
17848 Bulk Product 90c956fa Sports & Outdoors $897.80 313 0.3 29 BULK-eb29aa85
17849 Bulk Product 89ff54cb Books $500.24 155 3.8 70 BULK-6f2623ac
17850 Bulk Product 08f8252f Clothing $301.13 225 3.6 43 BULK-4ce2ff1c
17851 Bulk Product d4ec4274 Home & Garden $266.97 73 4.3 81 BULK-a4a3c6f5
17852 Bulk Product c0542603 Clothing $421.49 200 3.7 94 BULK-40d58a8a
17853 Bulk Product aa1d7881 Sports & Outdoors $757.88 89 3.2 97 BULK-f36872ed
17854 Bulk Product 476c76be Sports & Outdoors $898.15 355 2.6 77 BULK-c00b38d5
17855 Bulk Product 5e5de3a3 Books $203.98 4 3.7 2 BULK-f7886fb6
17856 Bulk Product 18b03ba0 Clothing $93.05 429 0.9 7 BULK-4da67144
17857 Bulk Product 8b434758 Home & Garden $178.01 477 0.5 49 BULK-693c9439
17858 Bulk Product feb2e2d0 Toys & Games $485.24 324 4.5 19 BULK-093b1118
17859 Bulk Product 310a69af Electronics $561.32 378 2.2 7 BULK-c51f0268
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