Efficient Pagination with Skip/Take

Efficient pagination using OFFSET-FETCH on SQL Server.

Execution Time

60 ms

Page Size

25

Current Page

652 / 978

Total Records

24441

Items per page: 25 50 100 200

Page 652 Results Showing 16276 - 16300 of 24441

ID Name Category Price Stock Rating Reviews SKU
16835 Bulk Product 8fe413d4 Sports & Outdoors $622.29 473 3.1 17 BULK-3b9dcbbc
16836 Bulk Product ab75cf03 Sports & Outdoors $236.56 327 3.9 66 BULK-c5b6fa43
16837 Bulk Product be7c5ac4 Electronics $10.70 101 3.6 27 BULK-4f24a81d
16838 Bulk Product 8db09980 Electronics $531.47 328 3.5 33 BULK-7f3f3a35
16839 Bulk Product 662a9d22 Electronics $590.21 266 0.6 62 BULK-06180d51
16840 Bulk Product 87381405 Toys & Games $105.47 393 1.6 91 BULK-554c1099
16841 Bulk Product 209ca85f Electronics $465.73 396 0.4 46 BULK-de1570b5
16842 Bulk Product 8f599b01 Electronics $21.57 387 2.8 86 BULK-a53a7fd1
16843 Bulk Product 4c48de08 Sports & Outdoors $538.67 126 3.1 72 BULK-56d1a42c
16844 Bulk Product e6eefaa1 Sports & Outdoors $533.37 263 2.2 40 BULK-794a44f9
16845 Bulk Product 2d63137e Books $296.90 105 1.1 15 BULK-db07b905
16846 Bulk Product 1f6ec3ca Sports & Outdoors $798.93 306 0.5 47 BULK-a7c3b57c
16847 Bulk Product 8c5e8c27 Toys & Games $15.54 397 1.7 57 BULK-a2a949ef
16848 Bulk Product 058a308b Toys & Games $209.36 415 1.3 76 BULK-bd9d88b9
16849 Bulk Product 5b5e741d Clothing $486.29 295 2.8 33 BULK-519bf9f2
16850 Bulk Product 7b14b390 Electronics $200.52 235 4.3 13 BULK-70e8d18b
16851 Bulk Product 6bde2ac7 Clothing $428.79 8 2.9 81 BULK-6bdc7235
16852 Bulk Product f346d2b3 Clothing $549.35 163 0.3 76 BULK-60cf96a9
16853 Bulk Product 9505bd4e Sports & Outdoors $923.58 164 2.7 79 BULK-18381e4c
16854 Bulk Product 266efcdb Sports & Outdoors $960.67 270 1.7 26 BULK-aa04147d
16855 Bulk Product 5ffcede1 Clothing $202.37 271 4.3 64 BULK-5bbfa498
16856 Bulk Product 76d27037 Home & Garden $347.09 191 0.8 43 BULK-1bcc3a40
16857 Bulk Product ccf15242 Toys & Games $685.47 40 4.0 81 BULK-1ad7e150
16858 Bulk Product b97a4b17 Books $681.33 208 0.1 31 BULK-0f81c7a4
16859 Bulk Product 7fb1c2ba Toys & Games $981.80 56 4.3 0 BULK-08f52788
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