Efficient Pagination with Skip/Take

Efficient pagination using OFFSET-FETCH on SQL Server.

Execution Time

11 ms

Page Size

25

Current Page

481 / 978

Total Records

24441

Items per page: 25 50 100 200

Page 481 Results Showing 12001 - 12025 of 24441

ID Name Category Price Stock Rating Reviews SKU
12560 Bulk Product 92d57a2a Sports & Outdoors $807.58 282 2.4 18 BULK-a01967b1
12561 Bulk Product 08e285e9 Toys & Games $892.74 24 1.7 65 BULK-a9dbda5f
12562 Bulk Product 41491195 Clothing $972.99 459 4.4 32 BULK-b3244fd2
12563 Bulk Product b8724056 Toys & Games $778.30 375 4.9 57 BULK-6ecd9461
12564 Bulk Product 006d27ba Books $968.88 336 2.4 96 BULK-3e6630b9
12565 Bulk Product 5480fbab Books $670.26 325 0.1 29 BULK-56a6d497
12566 Bulk Product 28feeaec Clothing $293.03 241 2.5 78 BULK-67d8fa29
12567 Bulk Product c9cec84e Clothing $342.41 321 4.6 31 BULK-9b224257
12568 Bulk Product 7f3fe303 Books $625.23 417 3.2 57 BULK-7ff41028
12569 Bulk Product e808205b Toys & Games $220.47 68 3.6 76 BULK-271a8347
12570 Bulk Product 377af80e Toys & Games $885.86 250 0.8 51 BULK-25090672
12571 Bulk Product c603a653 Home & Garden $384.55 392 2.9 16 BULK-2e938a3d
12572 Bulk Product e0fa2ce5 Sports & Outdoors $285.63 261 1.3 12 BULK-2a8e5c60
12573 Bulk Product b598ff63 Sports & Outdoors $218.96 111 1.9 3 BULK-d67a538b
12574 Bulk Product 54c69b42 Toys & Games $982.15 170 4.5 68 BULK-af458ecb
12575 Bulk Product b26801a4 Clothing $259.04 96 1.1 57 BULK-5259079d
12576 Bulk Product c27622a4 Sports & Outdoors $12.92 237 1.0 7 BULK-d10c1dcc
12577 Bulk Product 0fc1daa1 Books $260.62 81 4.2 83 BULK-5e938c86
12578 Bulk Product 5681d034 Sports & Outdoors $525.74 59 2.0 41 BULK-830927ea
12579 Bulk Product a56867bb Clothing $606.25 472 1.6 63 BULK-10f120e6
12580 Bulk Product f725c62d Clothing $292.35 214 0.2 99 BULK-1eaed2dd
12581 Bulk Product 40de0cc4 Electronics $240.65 397 2.4 37 BULK-cc093b3c
12582 Bulk Product 265ebd15 Books $781.29 278 1.3 97 BULK-1629a05c
12583 Bulk Product 683daf10 Home & Garden $835.84 444 0.2 64 BULK-e61d2179
12584 Bulk Product cbbacf88 Sports & Outdoors $886.55 418 3.9 19 BULK-cb177b05
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