Efficient Pagination with Skip/Take

Efficient pagination using OFFSET-FETCH on SQL Server.

Execution Time

15 ms

Page Size

25

Current Page

920 / 978

Total Records

24441

Items per page: 25 50 100 200

Page 920 Results Showing 22976 - 23000 of 24441

ID Name Category Price Stock Rating Reviews SKU
23535 Bulk Product 3797f749 Toys & Games $46.06 297 3.5 42 BULK-df2b1b52
23536 Bulk Product 7b728df7 Electronics $228.28 464 2.1 13 BULK-4551ce61
23537 Bulk Product 4471fc17 Home & Garden $492.66 94 3.7 11 BULK-d10e8bc5
23538 Bulk Product f43450f2 Sports & Outdoors $235.54 460 1.6 73 BULK-0e985cf2
23539 Bulk Product 471d0c68 Clothing $559.59 70 1.2 62 BULK-2ab96db1
23540 Bulk Product eef76ad3 Books $260.90 225 0.4 35 BULK-becac8a4
23541 Bulk Product 8d30e158 Home & Garden $977.45 264 4.0 18 BULK-598a8813
23542 Bulk Product 32a0af4c Toys & Games $172.99 49 4.5 55 BULK-2562e7c4
23543 Bulk Product 78d6eb37 Toys & Games $806.58 92 1.3 19 BULK-339a6898
23544 Bulk Product 0ee0364e Clothing $864.16 418 0.2 24 BULK-34538537
23545 Bulk Product 3bedde81 Clothing $531.53 436 4.2 35 BULK-b9ccce2e
23546 Bulk Product 2605481f Toys & Games $745.27 221 1.6 40 BULK-412e6f0a
23547 Bulk Product 25ee3129 Books $44.45 246 0.6 40 BULK-25897c62
23548 Bulk Product 524a8a9c Sports & Outdoors $652.59 291 0.3 91 BULK-7eb2ba07
23549 Bulk Product fe3d5d1a Home & Garden $756.79 255 0.3 25 BULK-4837f5ce
23550 Bulk Product 2ed10240 Books $188.71 342 0.4 93 BULK-866efdca
23551 Bulk Product fbfafb8e Home & Garden $215.23 202 0.7 0 BULK-69019265
23552 Bulk Product dc456086 Home & Garden $24.49 333 2.8 11 BULK-af5d5642
23553 Bulk Product 2eba078f Electronics $338.39 91 2.5 71 BULK-f104261b
23554 Bulk Product 52284ede Sports & Outdoors $767.75 448 2.7 99 BULK-057c46ef
23555 Bulk Product bf3f8b95 Sports & Outdoors $841.13 268 1.4 93 BULK-47d10d24
23556 Bulk Product a41ddd21 Clothing $33.70 273 2.1 57 BULK-19668847
23557 Bulk Product d2285aad Electronics $876.90 221 0.2 8 BULK-6cdf7a59
23558 Bulk Product ec860144 Books $707.59 221 0.3 43 BULK-dc18c954
23559 Bulk Product 0408a7b6 Home & Garden $550.43 440 2.6 89 BULK-9b208be8
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