Efficient Pagination with Skip/Take

Efficient pagination using OFFSET-FETCH on SQL Server.

Execution Time

16 ms

Page Size

25

Current Page

804 / 978

Total Records

24441

Items per page: 25 50 100 200

Page 804 Results Showing 20076 - 20100 of 24441

ID Name Category Price Stock Rating Reviews SKU
20635 Bulk Product e2cc7158 Books $41.16 453 0.5 14 BULK-bf4c2ad9
20636 Bulk Product a8676493 Clothing $790.38 488 3.3 36 BULK-272a0a80
20637 Bulk Product 0aadcc77 Electronics $477.07 139 1.3 3 BULK-52ab9aaa
20638 Bulk Product 4522b3bc Clothing $480.23 276 3.3 33 BULK-2a7fc783
20639 Bulk Product f10df883 Home & Garden $672.80 305 1.4 7 BULK-4c825428
20640 Bulk Product 4e432f9b Clothing $261.60 174 1.2 41 BULK-245bb11b
20641 Bulk Product 9ba62620 Sports & Outdoors $763.03 75 3.2 3 BULK-cbdc5f42
20642 Bulk Product 8a8c3d53 Books $152.88 132 1.1 10 BULK-f33850d9
20643 Bulk Product 924874ba Sports & Outdoors $405.11 141 2.5 34 BULK-88f0265c
20644 Bulk Product 778ac829 Electronics $793.40 125 2.6 32 BULK-62376351
20645 Bulk Product cf8fb79f Home & Garden $125.68 218 2.3 66 BULK-d168f146
20646 Bulk Product c64825b7 Electronics $298.09 193 0.7 52 BULK-fb24dbdb
20647 Bulk Product 63e32765 Home & Garden $756.01 495 3.9 29 BULK-2920c7dd
20648 Bulk Product 2e427c05 Books $365.59 313 0.8 15 BULK-eaa10503
20649 Bulk Product 058d06c6 Electronics $809.11 97 2.9 67 BULK-63ad44d8
20650 Bulk Product cfd3e1e4 Home & Garden $1,002.86 420 1.8 62 BULK-e49635b0
20651 Bulk Product a8640d0a Clothing $558.36 73 0.3 63 BULK-1e188ffb
20652 Bulk Product 63785e03 Clothing $545.34 328 2.3 6 BULK-86d8ebbe
20653 Bulk Product 3e061976 Sports & Outdoors $904.67 338 4.7 5 BULK-330a0d68
20654 Bulk Product c7b951ad Toys & Games $829.32 170 2.3 23 BULK-bda3e517
20655 Bulk Product 004c5027 Electronics $113.22 339 1.8 36 BULK-95594048
20656 Bulk Product 011b1f89 Sports & Outdoors $827.96 94 4.5 68 BULK-a19119a6
20657 Bulk Product 97e89fe7 Home & Garden $367.96 151 4.6 87 BULK-0ba37b39
20658 Bulk Product ebce3917 Clothing $849.16 29 3.5 20 BULK-d97e3569
20659 Bulk Product fd08f8fa Home & Garden $631.77 109 3.7 98 BULK-1585ab40
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