Efficient Pagination with Skip/Take

Efficient pagination using OFFSET-FETCH on SQL Server.

Execution Time

15 ms

Page Size

25

Current Page

473 / 978

Total Records

24441

Items per page: 25 50 100 200

Page 473 Results Showing 11801 - 11825 of 24441

ID Name Category Price Stock Rating Reviews SKU
12360 Bulk Product f040dc87 Home & Garden $882.85 235 0.6 90 BULK-8c201cf6
12361 Bulk Product 74d4efa0 Books $220.29 347 0.3 55 BULK-40c2b755
12362 Bulk Product a2ea268c Toys & Games $286.12 407 4.6 87 BULK-740221f6
12363 Bulk Product 97cea09f Clothing $694.98 250 2.0 18 BULK-f697f171
12364 Bulk Product 1e4bade1 Sports & Outdoors $272.84 312 3.1 34 BULK-89abbbe1
12365 Bulk Product 2e0fa4be Electronics $162.29 277 0.3 24 BULK-9352f089
12366 Bulk Product 8fc3d1f6 Toys & Games $339.71 147 2.8 8 BULK-50496bb7
12367 Bulk Product 3bd629ff Sports & Outdoors $737.50 455 0.6 40 BULK-52d89d47
12368 Bulk Product 2567334d Books $460.30 181 4.2 72 BULK-38f2f6bd
12369 Bulk Product b25ffd95 Books $174.49 71 4.6 76 BULK-f20985d8
12370 Bulk Product a8ad1703 Clothing $682.49 467 0.2 63 BULK-a1c5002f
12371 Bulk Product 7e1fc1d4 Home & Garden $496.60 146 3.1 90 BULK-31790896
12372 Bulk Product 9630a7c3 Toys & Games $786.19 426 2.3 27 BULK-4fbc615d
12373 Bulk Product 1969d346 Home & Garden $773.31 262 2.3 20 BULK-26e31564
12374 Bulk Product 0c5cdab8 Toys & Games $437.27 74 2.4 79 BULK-5948d857
12375 Bulk Product e4d24f1f Electronics $165.90 371 2.1 4 BULK-eedc1724
12376 Bulk Product 3b6e9680 Toys & Games $112.00 391 0.5 36 BULK-22c1203e
12377 Bulk Product 364856c1 Toys & Games $751.22 295 3.0 53 BULK-efcb3e1c
12378 Bulk Product b82e8a88 Sports & Outdoors $860.84 432 1.3 74 BULK-bd980fc7
12379 Bulk Product 252c8968 Electronics $840.93 486 1.0 91 BULK-c02c53c1
12380 Bulk Product 95d5de8e Clothing $632.96 49 4.6 18 BULK-d27f44d7
12381 Bulk Product 4d034188 Home & Garden $840.89 241 2.9 37 BULK-54abc85b
12382 Bulk Product 4cb99223 Home & Garden $325.50 465 1.7 44 BULK-9b668520
12383 Bulk Product 1b62fd60 Sports & Outdoors $424.31 387 0.4 68 BULK-8bf4dab0
12384 Bulk Product 10f6f6ce Electronics $844.81 16 0.2 29 BULK-e7e919f6
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