Efficient Pagination with Skip/Take

Efficient pagination using OFFSET-FETCH on SQL Server.

Execution Time

134 ms

Page Size

25

Current Page

303 / 978

Total Records

24441

Items per page: 25 50 100 200

Page 303 Results Showing 7551 - 7575 of 24441

ID Name Category Price Stock Rating Reviews SKU
8110 Bulk Product 84f345fe Electronics $192.24 225 4.8 6 BULK-b3e57705
8111 Bulk Product b278f88c Clothing $573.71 414 1.8 37 BULK-e555cc7f
8112 Bulk Product 1ea877b4 Sports & Outdoors $814.51 23 2.8 9 BULK-e360b601
8113 Bulk Product 42d4fa08 Clothing $754.37 348 4.5 51 BULK-56357d6d
8114 Bulk Product 64feaf6d Toys & Games $787.22 132 2.7 66 BULK-3a7b96d5
8115 Bulk Product a18f30f6 Sports & Outdoors $207.42 452 4.1 48 BULK-8e7cefa0
8116 Bulk Product f2286837 Toys & Games $320.47 79 2.8 19 BULK-ba807b40
8117 Bulk Product 9b280fd2 Home & Garden $557.82 455 2.7 28 BULK-d4ffee0b
8118 Bulk Product 8dad3ee1 Home & Garden $772.53 334 2.9 62 BULK-81a89a0f
8119 Bulk Product 0449e06c Books $280.12 154 3.7 79 BULK-bdfe21f2
8120 Bulk Product cf52dbf3 Toys & Games $265.08 321 1.6 67 BULK-039de548
8121 Bulk Product f60387a2 Sports & Outdoors $170.61 99 0.4 7 BULK-dce7ff57
8122 Bulk Product 0f44aac4 Toys & Games $516.69 305 2.5 57 BULK-2eea087d
8123 Bulk Product 7cede6d3 Electronics $939.94 112 2.5 72 BULK-02563ee6
8124 Bulk Product e7870026 Toys & Games $763.20 183 4.5 30 BULK-92b5c7d5
8125 Bulk Product 9f5b7cf5 Sports & Outdoors $351.06 252 1.5 53 BULK-8d09a3aa
8126 Bulk Product c4d2a5fb Home & Garden $547.76 78 3.2 30 BULK-a59f37af
8127 Bulk Product ba5b986a Clothing $805.27 362 1.3 4 BULK-76a497f0
8128 Bulk Product f2d233ce Sports & Outdoors $1,000.02 176 4.2 46 BULK-aeae45c1
8129 Bulk Product 16eb5960 Electronics $127.26 305 1.7 97 BULK-e1115384
8130 Bulk Product 56380e3d Home & Garden $208.56 199 0.8 31 BULK-0a603da2
8131 Bulk Product 98ca9a24 Toys & Games $383.44 90 4.0 19 BULK-edfabbdd
8132 Bulk Product 98a92313 Toys & Games $1,001.34 237 2.5 4 BULK-a1ad1f6c
8133 Bulk Product 6b8091f3 Home & Garden $810.69 113 2.3 14 BULK-b9ca91a7
8134 Bulk Product 7f7dec69 Electronics $74.40 99 3.8 18 BULK-d200965c
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