Efficient Pagination with Skip/Take

Efficient pagination using OFFSET-FETCH on SQL Server.

Execution Time

43 ms

Page Size

25

Current Page

854 / 978

Total Records

24441

Items per page: 25 50 100 200

Page 854 Results Showing 21326 - 21350 of 24441

ID Name Category Price Stock Rating Reviews SKU
21885 Bulk Product f8dcb9d3 Books $852.52 353 0.9 13 BULK-b7bde4e8
21886 Bulk Product 1ddbc4e3 Clothing $1,007.12 38 1.4 68 BULK-4cc598fc
21887 Bulk Product 5df5e20a Books $938.89 227 1.4 79 BULK-646164b9
21888 Bulk Product 67805143 Books $411.46 367 4.7 49 BULK-a59139a6
21889 Bulk Product 9c90305b Toys & Games $973.45 324 0.5 17 BULK-51f5a803
21890 Bulk Product e1837a6b Toys & Games $197.51 492 2.8 83 BULK-055ec6b6
21891 Bulk Product 9ff6720a Sports & Outdoors $925.46 271 2.2 98 BULK-30f5cac0
21892 Bulk Product cbd6c15a Sports & Outdoors $985.49 341 4.5 20 BULK-87396aa6
21893 Bulk Product d437db45 Toys & Games $1,002.09 315 2.6 42 BULK-a902f993
21894 Bulk Product 00264272 Sports & Outdoors $258.16 221 1.4 83 BULK-6f05d6bd
21895 Bulk Product 3b0bf6c2 Clothing $140.82 231 2.9 25 BULK-a2994bac
21896 Bulk Product b2c92560 Sports & Outdoors $504.51 387 1.9 17 BULK-cb0faa9a
21897 Bulk Product dbe0340f Toys & Games $176.57 23 0.0 3 BULK-ff0e178a
21898 Bulk Product f3bada2d Books $107.79 309 3.3 73 BULK-70ebe7eb
21899 Bulk Product 722063ef Books $312.78 469 4.4 15 BULK-714b995e
21900 Bulk Product 0748d381 Sports & Outdoors $413.49 376 3.4 25 BULK-fbee13cf
21901 Bulk Product 8cec9cbc Electronics $647.37 80 2.3 6 BULK-6df401d3
21902 Bulk Product e7e0c7b8 Clothing $84.39 259 2.4 54 BULK-abf7a8f4
21903 Bulk Product e5093aa4 Sports & Outdoors $459.59 246 1.9 0 BULK-9706e80f
21904 Bulk Product ee6cc8c1 Clothing $213.45 135 1.5 29 BULK-e3ca9322
21905 Bulk Product c01cb66d Toys & Games $871.66 473 2.2 78 BULK-6cd27bc9
21906 Bulk Product 34fe20dc Books $344.94 469 1.8 38 BULK-4a69a714
21907 Bulk Product 1f75d1e7 Clothing $743.16 307 3.3 96 BULK-9494ad75
21908 Bulk Product c9f7aab1 Clothing $617.68 123 2.4 42 BULK-866f47a4
21909 Bulk Product d8e8984a Electronics $104.59 456 2.9 30 BULK-11dc55af
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