Efficient Pagination with Skip/Take

Efficient pagination using OFFSET-FETCH on SQL Server.

Execution Time

61 ms

Page Size

25

Current Page

690 / 978

Total Records

24441

Items per page: 25 50 100 200

Page 690 Results Showing 17226 - 17250 of 24441

ID Name Category Price Stock Rating Reviews SKU
17785 Bulk Product a1ca749a Books $369.89 299 4.5 56 BULK-8a5efe16
17786 Bulk Product 9159cc69 Home & Garden $956.11 247 4.4 66 BULK-eb4336a2
17787 Bulk Product 7c1803e8 Toys & Games $468.50 379 0.0 41 BULK-eac4f3ef
17788 Bulk Product 9bbb583d Books $436.51 186 2.1 50 BULK-33fa8c02
17789 Bulk Product 4b58f916 Electronics $857.60 38 0.4 61 BULK-ce420151
17790 Bulk Product 8f6aa0e1 Sports & Outdoors $286.36 15 4.9 97 BULK-75bdd88d
17791 Bulk Product d0837f97 Sports & Outdoors $475.01 401 2.7 51 BULK-31184c88
17792 Bulk Product e53b6dce Home & Garden $771.67 380 1.6 16 BULK-8f8a2b24
17793 Bulk Product 9ac1bb65 Clothing $170.11 413 4.0 42 BULK-62c7a17b
17794 Bulk Product f6de480d Clothing $268.87 277 5.0 96 BULK-8dcf65c0
17795 Bulk Product f24760e8 Toys & Games $839.41 345 1.6 44 BULK-d21ccfd3
17796 Bulk Product 97e907ea Toys & Games $567.28 455 0.2 15 BULK-63417457
17797 Bulk Product 54b0e310 Home & Garden $334.45 267 1.5 29 BULK-58f691ef
17798 Bulk Product 27509d55 Clothing $514.92 114 1.0 99 BULK-70979a00
17799 Bulk Product 1ff5b14e Electronics $379.01 102 1.4 47 BULK-b5c9d558
17800 Bulk Product fa82bae4 Books $723.08 292 0.6 59 BULK-51091306
17801 Bulk Product ef46d1a1 Electronics $952.33 452 3.9 88 BULK-062de311
17802 Bulk Product cb5e775a Home & Garden $342.97 355 2.0 67 BULK-60e40e12
17803 Bulk Product e69f9198 Sports & Outdoors $237.17 246 1.3 59 BULK-5e4d52dd
17804 Bulk Product 5f64f7eb Books $797.79 493 3.3 98 BULK-25fec8dd
17805 Bulk Product 9a465859 Electronics $142.74 423 1.5 27 BULK-496d6c03
17806 Bulk Product 588bf4da Clothing $672.13 448 4.8 37 BULK-a4b3eccb
17807 Bulk Product ffe5a619 Electronics $905.02 194 4.5 24 BULK-02d9309c
17808 Bulk Product 2486dbb1 Toys & Games $802.46 160 0.6 40 BULK-daf0ad47
17809 Bulk Product b2cc5246 Toys & Games $852.69 57 1.8 70 BULK-b3b76d6d
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