Efficient Pagination with Skip/Take

Efficient pagination using OFFSET-FETCH on SQL Server.

Execution Time

21 ms

Page Size

25

Current Page

589 / 978

Total Records

24441

Items per page: 25 50 100 200

Page 589 Results Showing 14701 - 14725 of 24441

ID Name Category Price Stock Rating Reviews SKU
15260 Bulk Product 4da05ff4 Sports & Outdoors $754.09 344 3.3 7 BULK-01ddc871
15261 Bulk Product 542fa7c2 Sports & Outdoors $482.51 212 2.7 99 BULK-b9114c06
15262 Bulk Product eb25a036 Books $508.72 398 2.8 40 BULK-7df78b1c
15263 Bulk Product e9d350b4 Sports & Outdoors $817.17 86 4.3 74 BULK-22ae5327
15264 Bulk Product 603e8796 Toys & Games $228.64 237 1.1 90 BULK-c652d0cb
15265 Bulk Product 3e718fdf Home & Garden $345.69 44 2.1 23 BULK-625176b0
15266 Bulk Product 89ac36a5 Books $350.78 165 1.4 77 BULK-21f07412
15267 Bulk Product e7e86beb Electronics $802.41 306 4.7 83 BULK-fd85144e
15268 Bulk Product 04fc9589 Sports & Outdoors $927.65 39 2.1 28 BULK-004f7d16
15269 Bulk Product 876ac946 Clothing $920.74 168 3.0 64 BULK-4c4d3802
15270 Bulk Product 8f5cb732 Toys & Games $414.88 320 0.2 16 BULK-36d7ccd7
15271 Bulk Product 75e4cd47 Clothing $398.36 364 2.9 17 BULK-4a09c52a
15272 Bulk Product baa01173 Electronics $71.37 225 1.6 96 BULK-edce2cc8
15273 Bulk Product f94bd48c Toys & Games $749.52 198 2.1 69 BULK-3d3b8949
15274 Bulk Product c396b096 Toys & Games $186.32 325 0.3 32 BULK-071982cc
15275 Bulk Product 07faeaf2 Home & Garden $512.38 371 4.0 34 BULK-c3e92bbe
15276 Bulk Product 6c8cfdb4 Home & Garden $603.83 127 1.9 43 BULK-78630bc3
15277 Bulk Product ed69c6e5 Home & Garden $85.34 344 2.9 33 BULK-ddfe256c
15278 Bulk Product 4c4c358f Home & Garden $515.14 286 1.3 49 BULK-b2ad5ec2
15279 Bulk Product aebe19e6 Home & Garden $498.41 271 3.8 92 BULK-1aab4fcc
15280 Bulk Product a27d8e61 Books $896.36 349 1.8 27 BULK-2f7d9a52
15281 Bulk Product 29a4854c Toys & Games $52.88 53 2.2 87 BULK-0ea49e7a
15282 Bulk Product 255e61fb Clothing $302.75 204 0.8 18 BULK-5090ad3b
15283 Bulk Product 67ef212e Home & Garden $434.31 477 1.8 37 BULK-354b9c59
15284 Bulk Product 1bb5d3c4 Toys & Games $236.95 96 4.2 31 BULK-9e7e9f96
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