Efficient Pagination with Skip/Take

Efficient pagination using OFFSET-FETCH on SQL Server.

Execution Time

35 ms

Page Size

25

Current Page

304 / 978

Total Records

24441

Items per page: 25 50 100 200

Page 304 Results Showing 7576 - 7600 of 24441

ID Name Category Price Stock Rating Reviews SKU
8135 Bulk Product 62416bab Clothing $233.08 311 0.5 85 BULK-7ebb9ab0
8136 Bulk Product faad0474 Clothing $492.23 202 0.9 96 BULK-292bdc2f
8137 Bulk Product 094e405c Clothing $322.31 265 1.0 2 BULK-8c0c3744
8138 Bulk Product 724ea731 Sports & Outdoors $845.40 290 4.4 36 BULK-45dce1b9
8139 Bulk Product fad006a7 Sports & Outdoors $102.61 322 0.1 70 BULK-635d668c
8140 Bulk Product 1665461a Sports & Outdoors $405.16 98 1.8 18 BULK-6b964037
8141 Bulk Product 869da72b Electronics $25.57 15 4.3 20 BULK-fd261091
8142 Bulk Product 6b2d5252 Sports & Outdoors $944.75 136 0.6 34 BULK-adee1653
8143 Bulk Product cca4f14d Electronics $985.86 222 2.3 92 BULK-097617b9
8144 Bulk Product 114e1a02 Sports & Outdoors $586.83 247 1.0 11 BULK-29d02eec
8145 Bulk Product d04b464c Home & Garden $381.74 91 0.3 91 BULK-14812afa
8146 Bulk Product ece29664 Sports & Outdoors $440.55 428 0.6 73 BULK-31950183
8147 Bulk Product 12898986 Toys & Games $79.16 267 2.0 28 BULK-3e049239
8148 Bulk Product 8538751e Clothing $488.35 48 1.3 52 BULK-8cd441df
8149 Bulk Product 9bb0048c Clothing $931.35 37 4.3 16 BULK-8738d772
8150 Bulk Product bb2c508f Electronics $918.58 383 2.3 23 BULK-309bec5d
8151 Bulk Product 14a8c159 Books $49.69 112 1.4 81 BULK-4517c1de
8152 Bulk Product 7f66364c Clothing $570.07 250 4.4 62 BULK-61681e51
8153 Bulk Product 4eca5033 Books $51.24 73 4.4 36 BULK-7c97a9da
8154 Bulk Product c790b071 Toys & Games $457.69 357 4.1 71 BULK-524eef5b
8155 Bulk Product 98626716 Electronics $282.84 12 1.1 83 BULK-3d219960
8156 Bulk Product 44153b1a Home & Garden $345.98 164 1.7 53 BULK-ffe4a208
8157 Bulk Product 7751d158 Toys & Games $122.06 442 0.5 42 BULK-18e64bf3
8158 Bulk Product e14a01b9 Clothing $706.89 137 4.5 16 BULK-4fce05ec
8159 Bulk Product d424efdc Clothing $219.68 241 3.7 4 BULK-5f646a76
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