Efficient Pagination with Skip/Take

Efficient pagination using OFFSET-FETCH on SQL Server.

Execution Time

54 ms

Page Size

25

Current Page

417 / 978

Total Records

24441

Items per page: 25 50 100 200

Page 417 Results Showing 10401 - 10425 of 24441

ID Name Category Price Stock Rating Reviews SKU
10960 Bulk Product b87bba46 Electronics $523.39 498 1.7 44 BULK-c053a810
10961 Bulk Product ea4fb768 Electronics $178.00 437 3.4 80 BULK-865b0e6e
10962 Bulk Product 2cb28d02 Toys & Games $434.65 291 3.9 65 BULK-da224ff0
10963 Bulk Product 0067ee0b Home & Garden $181.91 161 2.4 48 BULK-c4c88348
10964 Bulk Product 3e747241 Toys & Games $702.30 427 3.4 21 BULK-ee6ca055
10965 Bulk Product 169d7c96 Sports & Outdoors $295.73 120 3.3 28 BULK-135ff2ae
10966 Bulk Product 8e828d3e Clothing $868.99 304 1.3 61 BULK-e1f53705
10967 Bulk Product 75e9156d Clothing $377.33 143 2.9 71 BULK-69bea66b
10968 Bulk Product 4208053b Home & Garden $124.90 320 4.1 46 BULK-52582fb3
10969 Bulk Product 45790b89 Sports & Outdoors $897.03 194 0.7 36 BULK-1daa61a5
10970 Bulk Product 26898b66 Electronics $775.00 85 2.9 87 BULK-47f06f77
10971 Bulk Product c3666a5e Home & Garden $813.75 55 0.1 67 BULK-4a4dc80b
10972 Bulk Product aea910ba Home & Garden $122.29 159 3.0 83 BULK-9da3e7e5
10973 Bulk Product 668451df Toys & Games $401.20 167 1.9 58 BULK-bf681679
10974 Bulk Product 3b69a947 Electronics $605.65 221 4.7 80 BULK-f2846ce8
10975 Bulk Product 2c67c2aa Clothing $555.75 443 2.3 28 BULK-bd6d3bc9
10976 Bulk Product 3c873361 Clothing $716.50 191 1.1 82 BULK-b426e74e
10977 Bulk Product 6b3aaa17 Clothing $752.10 144 0.4 36 BULK-6f509203
10978 Bulk Product 619a3306 Electronics $244.98 136 1.0 25 BULK-d5e47789
10979 Bulk Product b54df76a Clothing $894.30 245 3.8 99 BULK-4f60be9f
10980 Bulk Product b31a9ba4 Toys & Games $741.31 120 1.8 59 BULK-cc6b9f00
10981 Bulk Product 78121325 Electronics $161.50 389 2.1 24 BULK-f96d0c91
10982 Bulk Product e0dd6765 Home & Garden $351.05 138 1.3 71 BULK-8a9389a3
10983 Bulk Product 620b0ccd Books $516.47 447 2.1 21 BULK-6a961a64
10984 Bulk Product 394784a9 Clothing $737.79 403 4.6 95 BULK-1b8bd9b0
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