Efficient Pagination with Skip/Take

Efficient pagination using OFFSET-FETCH on SQL Server.

Execution Time

139 ms

Page Size

25

Current Page

187 / 978

Total Records

24441

Items per page: 25 50 100 200

Page 187 Results Showing 4651 - 4675 of 24441

ID Name Category Price Stock Rating Reviews SKU
5210 Bulk Product ab2339f9 Electronics $334.30 132 3.5 13 BULK-9bd630e9
5211 Bulk Product 60688a50 Clothing $239.09 448 2.9 67 BULK-666b9297
5212 Bulk Product cd9f42a8 Books $259.75 79 0.2 78 BULK-5e115103
5213 Bulk Product 8e3743a9 Home & Garden $581.67 244 3.2 47 BULK-860386aa
5214 Bulk Product da7ef57b Toys & Games $342.54 331 1.4 20 BULK-f696e1f6
5215 Bulk Product 3e7b03b5 Toys & Games $128.54 223 2.9 59 BULK-d669dd81
5216 Bulk Product ccff7055 Home & Garden $774.33 79 1.2 65 BULK-a62cf6d5
5217 Bulk Product 642adfec Clothing $753.44 445 0.6 87 BULK-0ddaf125
5218 Bulk Product e14cecbe Books $713.28 109 4.7 14 BULK-8c8c4ffa
5219 Bulk Product 2bc6dae3 Toys & Games $604.04 271 1.9 73 BULK-80c73e7f
5220 Bulk Product 41869f30 Electronics $809.30 457 2.2 61 BULK-8e4d341a
5221 Bulk Product 2bb16f58 Toys & Games $291.47 353 2.6 37 BULK-5b3d055e
5222 Bulk Product c1f9e0f2 Sports & Outdoors $481.51 476 4.9 47 BULK-4b35cfbe
5223 Bulk Product 3c7a0ba3 Clothing $396.85 207 1.7 69 BULK-85826ef7
5224 Bulk Product 7d968f7e Sports & Outdoors $657.24 246 2.1 85 BULK-6202ae5e
5225 Bulk Product aa29e83f Home & Garden $970.66 89 1.6 90 BULK-f46e4d23
5226 Bulk Product 58770908 Books $241.91 424 4.9 0 BULK-2aedb8fa
5227 Bulk Product be196d1d Home & Garden $54.83 11 0.6 74 BULK-1e086c78
5228 Bulk Product f9a83148 Books $416.20 217 2.5 47 BULK-3e54515f
5229 Bulk Product 8bc83ea4 Clothing $187.68 410 1.9 88 BULK-db2cca0d
5230 Bulk Product c6d18956 Sports & Outdoors $374.63 76 2.8 95 BULK-4ac860ac
5231 Bulk Product dd9f79cc Toys & Games $916.24 402 1.9 91 BULK-ba614805
5232 Bulk Product b8969ce3 Toys & Games $827.16 416 4.2 13 BULK-366ad8dd
5233 Bulk Product 1698f913 Books $855.69 401 1.9 85 BULK-45380d67
5234 Bulk Product efd24e2e Books $205.92 93 3.3 31 BULK-7f5db1c0
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