Efficient Pagination with Skip/Take

Efficient pagination using OFFSET-FETCH on SQL Server.

Execution Time

11 ms

Page Size

25

Current Page

388 / 978

Total Records

24441

Items per page: 25 50 100 200

Page 388 Results Showing 9676 - 9700 of 24441

ID Name Category Price Stock Rating Reviews SKU
10235 Bulk Product c9c2611f Electronics $860.86 383 1.9 96 BULK-7e4b656e
10236 Bulk Product 7e086b0c Sports & Outdoors $298.79 43 1.0 73 BULK-50fc4ccc
10237 Bulk Product 11cba711 Home & Garden $587.44 191 2.8 72 BULK-996bde4a
10238 Bulk Product 55750478 Home & Garden $498.90 23 1.0 81 BULK-5de07c7c
10239 Bulk Product bcb38cf4 Home & Garden $825.54 171 2.3 27 BULK-5c979eef
10240 Bulk Product 91fd3104 Toys & Games $88.76 432 4.6 30 BULK-bc939fd5
10241 Bulk Product cbc2f550 Home & Garden $859.02 318 3.5 31 BULK-cfbd8d87
10242 Bulk Product 92553691 Electronics $38.17 257 4.3 13 BULK-7a6f37fc
10243 Bulk Product 47ea56b0 Sports & Outdoors $339.90 484 4.2 27 BULK-034d1983
10244 Bulk Product fa33b2ba Home & Garden $84.36 236 3.9 59 BULK-b61ce790
10245 Bulk Product 95524e0e Clothing $759.13 299 4.1 82 BULK-9265b25d
10246 Bulk Product 0038a894 Sports & Outdoors $403.48 315 1.6 54 BULK-21b8eae8
10247 Bulk Product 0ac516aa Clothing $772.62 312 3.4 97 BULK-a7d9e19c
10248 Bulk Product 597f808e Books $178.90 261 2.1 64 BULK-b26255af
10249 Bulk Product e9a26dfb Clothing $713.45 485 4.2 7 BULK-bd918e23
10250 Bulk Product ec847099 Sports & Outdoors $984.49 30 2.0 34 BULK-ec90091a
10251 Bulk Product 45ccd930 Home & Garden $781.67 135 0.0 66 BULK-768efd4a
10252 Bulk Product ecc7d117 Toys & Games $1,006.64 251 1.5 66 BULK-d9605823
10253 Bulk Product 291e08c4 Home & Garden $536.64 480 0.8 53 BULK-52c2165e
10254 Bulk Product 725c4f1c Clothing $592.87 5 3.6 90 BULK-61ddcf67
10255 Bulk Product c68f50cc Sports & Outdoors $454.40 232 0.2 54 BULK-6910e815
10256 Bulk Product 9cf48da6 Electronics $803.18 29 3.6 27 BULK-bfe07fba
10257 Bulk Product 4e3e23eb Clothing $380.68 247 2.9 50 BULK-3c7240b3
10258 Bulk Product 03888040 Books $365.62 61 1.3 61 BULK-5feeb930
10259 Bulk Product 7c51d0d5 Clothing $161.46 227 2.6 14 BULK-343613ba
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