Efficient Pagination with Skip/Take

Efficient pagination using OFFSET-FETCH on SQL Server.

Execution Time

23 ms

Page Size

25

Current Page

658 / 978

Total Records

24441

Items per page: 25 50 100 200

Page 658 Results Showing 16426 - 16450 of 24441

ID Name Category Price Stock Rating Reviews SKU
16985 Bulk Product 915af732 Sports & Outdoors $263.92 249 0.8 33 BULK-a07cd370
16986 Bulk Product e7c1510b Sports & Outdoors $705.18 430 1.5 55 BULK-0afbcf4c
16987 Bulk Product e6a71f13 Clothing $947.79 3 0.8 34 BULK-47b5c5ac
16988 Bulk Product 9cde905b Electronics $275.74 80 4.4 10 BULK-52b507c0
16989 Bulk Product e774f9e6 Electronics $44.21 266 2.0 40 BULK-196523e0
16990 Bulk Product 569701d0 Books $641.96 332 4.9 17 BULK-1b49eea9
16991 Bulk Product f1ff29dd Home & Garden $462.69 62 4.0 82 BULK-26628007
16992 Bulk Product e37c326c Toys & Games $915.71 160 3.4 2 BULK-efe295e0
16993 Bulk Product 683219bd Electronics $458.88 249 1.5 53 BULK-5e98bee8
16994 Bulk Product 29ba2435 Books $945.45 390 4.2 95 BULK-a26f6bae
16995 Bulk Product 83118733 Books $939.75 63 0.6 15 BULK-174248cb
16996 Bulk Product 75a7bfe5 Clothing $888.97 450 4.5 86 BULK-bdec3126
16997 Bulk Product 1321a006 Books $593.40 132 1.8 77 BULK-5b2a0661
16998 Bulk Product 9ccf082d Toys & Games $411.46 149 3.1 99 BULK-f3f708b1
16999 Bulk Product 7e283425 Sports & Outdoors $948.29 138 1.2 36 BULK-16e3f71c
17000 Bulk Product 6b510787 Toys & Games $383.52 115 3.5 31 BULK-e719acb7
17001 Bulk Product b7a5f626 Clothing $114.93 238 2.8 29 BULK-21474803
17002 Bulk Product d44ce237 Sports & Outdoors $92.97 59 3.7 71 BULK-570aa120
17003 Bulk Product dc7ec25d Clothing $60.66 139 3.7 32 BULK-5a65bab4
17004 Bulk Product dba1242c Books $171.86 412 0.4 85 BULK-5254569b
17005 Bulk Product 1a15a77c Home & Garden $591.28 9 0.2 50 BULK-115a43e7
17006 Bulk Product 74e3fbd2 Home & Garden $995.10 178 2.8 99 BULK-ae072415
17007 Bulk Product 2258d1c1 Books $870.69 464 3.8 89 BULK-85edb5db
17008 Bulk Product c6440b2a Books $985.00 102 4.5 54 BULK-91fde486
17009 Bulk Product f8419ae3 Electronics $962.37 470 3.8 11 BULK-aeaf02de
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