Efficient Pagination with Skip/Take

Efficient pagination using OFFSET-FETCH on SQL Server.

Execution Time

9 ms

Page Size

25

Current Page

262 / 978

Total Records

24441

Items per page: 25 50 100 200

Page 262 Results Showing 6526 - 6550 of 24441

ID Name Category Price Stock Rating Reviews SKU
7085 Bulk Product 315bfcbb Electronics $830.89 244 1.2 3 BULK-47a74296
7086 Bulk Product efabada3 Clothing $46.26 20 1.5 56 BULK-639f5898
7087 Bulk Product e2970872 Toys & Games $776.52 210 3.5 91 BULK-1dad4c9d
7088 Bulk Product 04d39123 Home & Garden $943.00 444 1.8 45 BULK-f03c0fd2
7089 Bulk Product f4837baa Toys & Games $932.84 466 2.8 61 BULK-7d406f0a
7090 Bulk Product b47546b5 Books $506.18 409 2.2 0 BULK-9f612b38
7091 Bulk Product e5823cb4 Toys & Games $341.38 409 1.7 91 BULK-d6775870
7092 Bulk Product de05a96f Clothing $744.01 475 3.9 66 BULK-4144faad
7093 Bulk Product 7bb32e28 Toys & Games $977.99 307 3.6 66 BULK-f2855c9e
7094 Bulk Product 42987b8f Sports & Outdoors $611.61 290 0.8 70 BULK-65fd2106
7095 Bulk Product 5ba9f6df Toys & Games $19.90 382 3.3 49 BULK-2f4fe769
7096 Bulk Product e07a3d91 Home & Garden $935.85 230 4.9 3 BULK-9eecde34
7097 Bulk Product 72b1bc4f Sports & Outdoors $825.90 256 3.8 80 BULK-75afd3bd
7098 Bulk Product 5a6f392a Toys & Games $685.91 392 0.6 85 BULK-d17fe5d2
7099 Bulk Product 0232732c Toys & Games $481.38 74 3.2 24 BULK-dc60d715
7100 Bulk Product afb7130b Books $591.16 191 2.5 80 BULK-49147623
7101 Bulk Product 80ade4e1 Sports & Outdoors $478.43 234 3.1 60 BULK-b10bc14b
7102 Bulk Product a479fe53 Toys & Games $762.75 308 2.9 83 BULK-17c17ba3
7103 Bulk Product 5089f684 Clothing $467.52 231 2.0 15 BULK-2287a2a4
7104 Bulk Product 1aa1f971 Home & Garden $126.38 284 3.6 70 BULK-b7da7b90
7105 Bulk Product d6bb28ce Toys & Games $869.55 190 2.8 40 BULK-aeb385a2
7106 Bulk Product 92000234 Sports & Outdoors $553.54 174 3.7 31 BULK-92d360de
7107 Bulk Product 54acefee Home & Garden $600.53 145 4.0 42 BULK-2adede86
7108 Bulk Product 80aad70a Books $901.74 152 4.3 79 BULK-f7e0c024
7109 Bulk Product e42b2091 Electronics $663.05 147 2.7 1 BULK-f8e13599
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