Efficient Pagination with Skip/Take

Efficient pagination using OFFSET-FETCH on SQL Server.

Execution Time

27 ms

Page Size

25

Current Page

894 / 978

Total Records

24441

Items per page: 25 50 100 200

Page 894 Results Showing 22326 - 22350 of 24441

ID Name Category Price Stock Rating Reviews SKU
22885 Bulk Product 13a7f271 Clothing $360.36 311 4.4 43 BULK-62adb7d5
22886 Bulk Product f9b9e622 Clothing $742.01 499 1.4 95 BULK-ecdfda02
22887 Bulk Product 50a5b2f9 Clothing $446.65 154 2.2 45 BULK-1768d4e0
22888 Bulk Product 1c02dbd8 Electronics $154.13 379 0.0 78 BULK-7c16d619
22889 Bulk Product feb2f8af Home & Garden $795.00 464 3.1 98 BULK-a9c8dabf
22890 Bulk Product e37400b9 Electronics $593.69 228 3.2 87 BULK-ee26d5fd
22891 Bulk Product c944aa8d Sports & Outdoors $281.83 6 0.7 23 BULK-34d0fb72
22892 Bulk Product 82f88c09 Sports & Outdoors $845.80 79 3.2 28 BULK-ea5dbac1
22893 Bulk Product 761a6223 Sports & Outdoors $485.07 4 3.7 6 BULK-d7b1827b
22894 Bulk Product cb157c4a Sports & Outdoors $836.40 354 2.6 37 BULK-11cd78f9
22895 Bulk Product ba80a0e0 Books $529.62 25 1.7 76 BULK-91bebc7d
22896 Bulk Product 6ed00e45 Home & Garden $735.71 371 2.4 44 BULK-269ed5c0
22897 Bulk Product ba81e032 Electronics $105.64 493 0.3 26 BULK-5c4f9483
22898 Bulk Product d75799ad Toys & Games $799.46 343 3.4 66 BULK-2b18da8d
22899 Bulk Product fe62c649 Electronics $474.56 283 1.5 45 BULK-b8a8ec4d
22900 Bulk Product 33026166 Sports & Outdoors $848.70 268 0.9 32 BULK-079df7ac
22901 Bulk Product 144131c0 Sports & Outdoors $901.47 331 2.3 31 BULK-954c79ba
22902 Bulk Product 87ff5ec6 Home & Garden $350.35 488 2.8 92 BULK-91b7f2dd
22903 Bulk Product 0486ace7 Clothing $578.90 461 0.9 93 BULK-aaf8b09a
22904 Bulk Product 77835a24 Clothing $1,008.14 216 1.4 65 BULK-6508e808
22905 Bulk Product c0231bb1 Electronics $720.08 461 0.2 84 BULK-595ab9ae
22906 Bulk Product 7c8b6847 Clothing $363.38 211 1.4 35 BULK-c37bf582
22907 Bulk Product 5bf376f3 Toys & Games $89.55 445 2.8 20 BULK-29b4cdbd
22908 Bulk Product d715941e Clothing $681.97 3 0.7 8 BULK-73860007
22909 Bulk Product 5f1e5bd0 Clothing $970.58 72 4.7 58 BULK-8b934b53
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