Efficient Pagination with Skip/Take

Efficient pagination using OFFSET-FETCH on SQL Server.

Execution Time

13 ms

Page Size

25

Current Page

702 / 978

Total Records

24441

Items per page: 25 50 100 200

Page 702 Results Showing 17526 - 17550 of 24441

ID Name Category Price Stock Rating Reviews SKU
18085 Bulk Product 3310cff8 Books $639.49 284 2.6 69 BULK-a444a327
18086 Bulk Product 488c9e71 Toys & Games $747.03 407 4.4 27 BULK-c357bd50
18087 Bulk Product 6ea8eb0a Toys & Games $805.81 369 2.0 24 BULK-c1427d9d
18088 Bulk Product bf1c946b Sports & Outdoors $24.19 222 0.4 9 BULK-6a819391
18089 Bulk Product 8a585ea5 Clothing $55.96 233 4.3 34 BULK-39f98115
18090 Bulk Product 7e0f1c94 Books $341.58 293 2.7 57 BULK-8eb963de
18091 Bulk Product 7c747065 Books $944.45 346 4.4 7 BULK-81240f4d
18092 Bulk Product 4721f7a9 Toys & Games $85.34 430 0.4 50 BULK-29c8a4e7
18093 Bulk Product 7c637dcd Books $39.62 181 1.0 91 BULK-614106d1
18094 Bulk Product dcbe68b4 Toys & Games $68.24 138 3.7 65 BULK-604f2322
18095 Bulk Product 75013b92 Home & Garden $130.24 227 2.3 8 BULK-a45f22e1
18096 Bulk Product 59b0cb8e Clothing $310.10 322 0.2 79 BULK-d5d607d3
18097 Bulk Product db20ad26 Clothing $88.12 110 0.6 72 BULK-f76e3a6e
18098 Bulk Product 0f1c718a Electronics $66.06 314 4.7 8 BULK-abd8df72
18099 Bulk Product d728fc8a Clothing $268.36 401 0.9 83 BULK-9c8d77b6
18100 Bulk Product 184a984f Toys & Games $778.90 318 3.6 24 BULK-5b42df87
18101 Bulk Product f5c6f530 Sports & Outdoors $330.29 380 1.3 5 BULK-0bac474f
18102 Bulk Product 7cfcb0e3 Toys & Games $20.68 127 0.6 42 BULK-4b834ce4
18103 Bulk Product 45e39a7f Electronics $987.74 118 1.6 67 BULK-01d31b51
18104 Bulk Product 27f19df3 Books $762.71 81 3.6 79 BULK-085a61d2
18105 Bulk Product db3e8371 Toys & Games $217.36 342 4.1 95 BULK-1436d3e9
18106 Bulk Product 09729dbf Electronics $469.18 275 0.5 16 BULK-4ace17bc
18107 Bulk Product 102f44d3 Sports & Outdoors $47.52 128 3.1 36 BULK-178127cf
18108 Bulk Product 5601c0cb Toys & Games $876.69 338 3.2 91 BULK-f0516329
18109 Bulk Product b4113b63 Sports & Outdoors $432.94 7 4.7 6 BULK-fd9f30be
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