Efficient Pagination with Skip/Take

Efficient pagination using OFFSET-FETCH on SQL Server.

Execution Time

9 ms

Page Size

25

Current Page

226 / 978

Total Records

24441

Items per page: 25 50 100 200

Page 226 Results Showing 5626 - 5650 of 24441

ID Name Category Price Stock Rating Reviews SKU
6185 Bulk Product f99a3a53 Electronics $338.90 311 2.1 19 BULK-ee499a1c
6186 Bulk Product b735fb4b Home & Garden $743.35 434 3.8 93 BULK-cd82ef5a
6187 Bulk Product 6df9fce1 Home & Garden $65.16 44 3.6 74 BULK-25173daf
6188 Bulk Product 19f5c2d9 Clothing $762.95 401 3.8 4 BULK-6e7b6fef
6189 Bulk Product cc547410 Clothing $90.37 58 1.9 76 BULK-aadf4b51
6190 Bulk Product 1b59a603 Books $161.27 185 3.0 96 BULK-5ab9b713
6191 Bulk Product e808de3d Sports & Outdoors $118.36 243 1.5 7 BULK-f01ea699
6192 Bulk Product 0ef29261 Home & Garden $538.18 115 2.3 93 BULK-bb267c9a
6193 Bulk Product 63aa772b Books $764.78 3 1.4 39 BULK-79e433ff
6194 Bulk Product d119a250 Clothing $180.67 480 0.8 47 BULK-2dd16cac
6195 Bulk Product 9e7a1e90 Home & Garden $973.28 327 4.7 3 BULK-049571fe
6196 Bulk Product 95f077e2 Home & Garden $815.59 370 2.0 18 BULK-9abfd417
6197 Bulk Product 873eb4d1 Toys & Games $344.30 298 4.5 2 BULK-07dc20f0
6198 Bulk Product 153f5300 Home & Garden $205.08 326 0.2 50 BULK-b2edfa0b
6199 Bulk Product dbc686b9 Books $344.24 331 2.7 63 BULK-2075972f
6200 Bulk Product 2ffd2869 Electronics $853.25 30 2.4 16 BULK-063a3a81
6201 Bulk Product 301c87b2 Clothing $389.60 65 2.5 80 BULK-0f59bf05
6202 Bulk Product 0030e010 Electronics $96.64 349 1.8 35 BULK-eee0c523
6203 Bulk Product 8e39f505 Clothing $337.45 284 3.5 84 BULK-d0b0303b
6204 Bulk Product 61490773 Sports & Outdoors $326.00 175 3.4 86 BULK-e2f7fa07
6205 Bulk Product 6bd81a43 Toys & Games $457.06 360 2.9 18 BULK-1e2164d6
6206 Bulk Product effac110 Sports & Outdoors $896.11 368 3.9 0 BULK-475685d4
6207 Bulk Product 100aa787 Toys & Games $907.26 192 0.1 47 BULK-d23b28e1
6208 Bulk Product d62c1583 Home & Garden $162.57 325 3.2 91 BULK-d05cbc18
6209 Bulk Product 71c3749b Home & Garden $972.48 11 1.6 7 BULK-7e6691b0
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