Efficient Pagination with Skip/Take

Efficient pagination using OFFSET-FETCH on SQL Server.

Execution Time

114 ms

Page Size

25

Current Page

141 / 978

Total Records

24441

Items per page: 25 50 100 200

Page 141 Results Showing 3501 - 3525 of 24441

ID Name Category Price Stock Rating Reviews SKU
3932 Pro Sports & Outdoors Product Special Edition Sports & Outdoors $336.62 72 4.2 393 SKU-003932
3933 Economy Clothing Product Mini Clothing $523.55 39 4.4 796 SKU-003933
3934 Super Automotive Product Advanced Automotive $905.04 28 3.7 194 SKU-003934
3935 Mega Toys & Games Product Special Edition Toys & Games $874.44 160 4.9 128 SKU-003935
3936 Deluxe Sports & Outdoors Product Plus Sports & Outdoors $960.23 42 1.1 471 SKU-003936
3937 Premium Clothing Product Special Edition Clothing $333.48 307 2.7 768 SKU-003937
3938 Elite Automotive Product Classic Automotive $814.59 202 3.9 136 SKU-003938
3939 Premium Automotive Product Special Edition Automotive $45.03 391 2.5 159 SKU-003939
3940 Deluxe Food & Grocery Product Special Edition Food & Grocery $449.36 320 2.6 610 SKU-003940
3941 Super Office Supplies Product Max Office Supplies $775.86 149 3.6 199 SKU-003941
3942 Deluxe Office Supplies Product 2024 Office Supplies $736.20 223 3.4 619 SKU-003942
3943 Ultra Health & Beauty Product Plus Health & Beauty $285.40 97 2.2 756 SKU-003943
3944 Standard Home & Garden Product 2024 Home & Garden $914.12 266 4.8 64 SKU-003944
3945 Standard Sports & Outdoors Product Mini Sports & Outdoors $415.07 65 1.9 764 SKU-003945
3946 Pro Home & Garden Product Advanced Home & Garden $789.16 161 3.6 46 SKU-003946
3947 Premium Home & Garden Product Pro Home & Garden $643.29 424 2.5 547 SKU-003947
3948 Deluxe Clothing Product Plus Clothing $269.19 26 4.4 383 SKU-003948
3949 Mega Clothing Product Plus Clothing $421.15 486 3.1 815 SKU-003949
3950 Mega Electronics Product Mini Electronics $218.52 253 4.6 971 SKU-003950
3951 Mega Home & Garden Product XL Home & Garden $182.78 173 4.0 382 SKU-003951
3952 Super Home & Garden Product Plus Home & Garden $822.21 403 3.3 288 SKU-003952
3953 Premium Automotive Product Mini Automotive $109.40 230 1.8 945 SKU-003953
3954 Mega Clothing Product Lite Clothing $319.31 357 1.2 707 SKU-003954
3955 Standard Toys & Games Product Lite Toys & Games $410.59 480 3.0 823 SKU-003955
3956 Economy Clothing Product 2024 Clothing $392.41 386 3.4 548 SKU-003956
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