Efficient Pagination with Skip/Take

Efficient pagination using OFFSET-FETCH on SQL Server.

Execution Time

19 ms

Page Size

25

Current Page

298 / 978

Total Records

24441

Items per page: 25 50 100 200

Page 298 Results Showing 7426 - 7450 of 24441

ID Name Category Price Stock Rating Reviews SKU
7985 Bulk Product bfd1da5e Home & Garden $872.25 51 1.5 90 BULK-3b4bd2cf
7986 Bulk Product 84906851 Books $831.18 473 4.6 70 BULK-0c932d2b
7987 Bulk Product 9b15827d Clothing $871.77 89 3.7 13 BULK-5b3f4fe3
7988 Bulk Product 74a48dfa Electronics $310.89 218 2.9 30 BULK-77d688d9
7989 Bulk Product 2e18829c Home & Garden $876.63 169 3.9 34 BULK-04f9876e
7990 Bulk Product e1f2d511 Books $20.72 332 4.0 37 BULK-f950de95
7991 Bulk Product 31392906 Toys & Games $263.36 221 1.3 53 BULK-9e9b99d4
7992 Bulk Product 7b239b00 Home & Garden $63.75 14 4.2 13 BULK-2fbbc1e2
7993 Bulk Product f8881ef7 Books $839.94 305 3.1 22 BULK-a19d5ddc
7994 Bulk Product 4c8a355c Books $73.38 427 2.5 91 BULK-64561678
7995 Bulk Product 191d60d4 Home & Garden $612.34 53 0.7 98 BULK-46f50640
7996 Bulk Product 9518c035 Home & Garden $873.10 249 1.9 87 BULK-40429307
7997 Bulk Product 37e15808 Toys & Games $12.61 18 0.6 45 BULK-dd14165e
7998 Bulk Product 4d2e7733 Electronics $480.36 82 3.1 70 BULK-4d824bc5
7999 Bulk Product 3a083b74 Clothing $228.29 303 1.0 28 BULK-0fd3a97a
8000 Bulk Product 2e3c7995 Books $238.93 350 4.9 23 BULK-403c7827
8001 Bulk Product 02d8774a Books $941.03 456 4.6 27 BULK-a54710e7
8002 Bulk Product 845370cf Books $833.53 443 0.3 69 BULK-e9393dfd
8003 Bulk Product 75daab32 Toys & Games $756.16 404 3.6 18 BULK-1227a1be
8004 Bulk Product 59dc250a Electronics $562.86 232 3.5 5 BULK-0271c0c8
8005 Bulk Product 0edec40b Toys & Games $37.35 187 4.8 66 BULK-d6ec1d8f
8006 Bulk Product 3bfa6512 Toys & Games $560.60 215 4.5 71 BULK-16620f19
8007 Bulk Product 1611c281 Electronics $299.30 210 4.9 13 BULK-25698713
8008 Bulk Product 468c8293 Clothing $407.13 45 3.6 39 BULK-06606503
8009 Bulk Product 5123c041 Electronics $372.93 179 3.0 46 BULK-4317176a
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