Efficient Pagination with Skip/Take

Efficient pagination using OFFSET-FETCH on SQL Server.

Execution Time

19 ms

Page Size

25

Current Page

373 / 978

Total Records

24441

Items per page: 25 50 100 200

Page 373 Results Showing 9301 - 9325 of 24441

ID Name Category Price Stock Rating Reviews SKU
9860 Bulk Product 917b7467 Home & Garden $623.28 160 2.2 92 BULK-b43994a2
9861 Bulk Product 4a0faeac Electronics $941.66 406 0.9 54 BULK-43dcbf46
9862 Bulk Product 9d3e06e2 Electronics $158.22 98 4.9 32 BULK-be3599f9
9863 Bulk Product b052096d Home & Garden $230.07 183 3.5 2 BULK-68878aac
9864 Bulk Product e18da927 Home & Garden $877.09 27 0.9 40 BULK-bf87fade
9865 Bulk Product f774e1d9 Books $868.42 106 0.5 81 BULK-02500f01
9866 Bulk Product 2b5448a1 Home & Garden $656.93 182 2.4 63 BULK-6dd172f2
9867 Bulk Product 6a85471f Sports & Outdoors $790.42 190 0.6 50 BULK-9e51954d
9868 Bulk Product 808f17a7 Sports & Outdoors $734.07 355 2.8 26 BULK-b8bf560c
9869 Bulk Product 80eeb1f0 Toys & Games $300.57 229 2.4 99 BULK-f612dbf8
9870 Bulk Product 3eb8a534 Toys & Games $771.82 297 3.9 82 BULK-bfa7f562
9871 Bulk Product 4a8b33aa Books $625.22 374 0.1 84 BULK-262ce539
9872 Bulk Product 1bd5bb5c Home & Garden $455.81 474 2.0 24 BULK-e7ed8459
9873 Bulk Product 42b694e3 Home & Garden $457.05 450 3.3 83 BULK-7375c52c
9874 Bulk Product a4cee21f Home & Garden $942.37 62 1.8 69 BULK-0f4d47d1
9875 Bulk Product 9afd1627 Clothing $388.64 206 4.6 53 BULK-28d1864f
9876 Bulk Product 569b105c Books $282.93 379 0.7 33 BULK-38bc1ba9
9877 Bulk Product 4fc0434e Home & Garden $156.70 109 0.5 95 BULK-e399bd5e
9878 Bulk Product d28b6cb7 Home & Garden $101.67 336 4.9 79 BULK-28f8739a
9879 Bulk Product b1202684 Clothing $593.46 429 2.5 52 BULK-f4605d70
9880 Bulk Product d3619073 Books $543.30 457 1.6 53 BULK-69da34de
9881 Bulk Product df122972 Toys & Games $158.48 310 3.6 59 BULK-6d567e1a
9882 Bulk Product d362f7ad Home & Garden $814.40 423 1.0 96 BULK-8f7c52f7
9883 Bulk Product 3c8a44ca Toys & Games $623.57 176 3.7 11 BULK-ceeea988
9884 Bulk Product 21a85ed9 Sports & Outdoors $199.09 40 3.3 77 BULK-2472faf8
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