Efficient Pagination with Skip/Take

Efficient pagination using OFFSET-FETCH on SQL Server.

Execution Time

22 ms

Page Size

25

Current Page

385 / 978

Total Records

24441

Items per page: 25 50 100 200

Page 385 Results Showing 9601 - 9625 of 24441

ID Name Category Price Stock Rating Reviews SKU
10160 Bulk Product ad5a6ba4 Electronics $650.96 487 1.6 77 BULK-71fcf327
10161 Bulk Product 99a7435f Books $621.16 442 1.7 40 BULK-da62fcc2
10162 Bulk Product 7c6bbfaa Electronics $806.86 485 1.7 27 BULK-cf506b3e
10163 Bulk Product 15fc8bd0 Clothing $659.40 418 3.9 59 BULK-da370cc2
10164 Bulk Product b098ff50 Home & Garden $739.19 351 3.8 99 BULK-f9cf85f7
10165 Bulk Product fc6c23d1 Electronics $982.40 340 1.5 57 BULK-56e755bd
10166 Bulk Product 42467c07 Books $106.86 212 0.1 68 BULK-df34c6fd
10167 Bulk Product db97aae9 Home & Garden $377.74 492 4.8 53 BULK-4dd50262
10168 Bulk Product de35a92b Home & Garden $470.81 242 3.8 83 BULK-a7530d0e
10169 Bulk Product ee6adc55 Sports & Outdoors $260.55 30 2.8 41 BULK-3a6068c5
10170 Bulk Product 40fa0757 Books $616.80 341 2.7 87 BULK-a4037862
10171 Bulk Product 0ab6ff0a Electronics $59.93 211 1.0 52 BULK-c23b023f
10172 Bulk Product cf7d5b63 Home & Garden $661.06 44 3.9 35 BULK-51f51749
10173 Bulk Product f7d8e2f0 Home & Garden $112.20 200 0.4 19 BULK-39c6ed03
10174 Bulk Product 4a67fe33 Toys & Games $358.49 268 1.8 76 BULK-0a2ec4a5
10175 Bulk Product a46487f2 Toys & Games $314.41 258 2.8 9 BULK-0964b1ba
10176 Bulk Product 8521dcfa Toys & Games $55.70 199 0.1 62 BULK-d71c5dc1
10177 Bulk Product b3246f01 Electronics $251.91 464 4.0 56 BULK-3afad53e
10178 Bulk Product ea6da286 Sports & Outdoors $292.54 445 1.9 84 BULK-95b6d284
10179 Bulk Product 68421703 Clothing $313.29 93 0.5 60 BULK-bf34bfff
10180 Bulk Product 321bd90a Toys & Games $936.22 384 4.9 71 BULK-1d2e56c7
10181 Bulk Product b417f872 Electronics $953.45 209 2.8 18 BULK-39a00935
10182 Bulk Product 83c3b6a4 Books $154.50 201 3.9 6 BULK-83b98f55
10183 Bulk Product e9ad6bfe Home & Garden $662.74 19 0.2 39 BULK-88d0205d
10184 Bulk Product 6c2b0459 Clothing $55.77 99 4.2 33 BULK-d6a5c13a
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