Efficient Pagination with Skip/Take

Efficient pagination using OFFSET-FETCH on SQL Server.

Execution Time

13 ms

Page Size

25

Current Page

470 / 978

Total Records

24441

Items per page: 25 50 100 200

Page 470 Results Showing 11726 - 11750 of 24441

ID Name Category Price Stock Rating Reviews SKU
12285 Bulk Product 1ddf22b2 Clothing $945.44 202 1.2 90 BULK-8031d582
12286 Bulk Product 0dbeeb84 Sports & Outdoors $825.58 430 2.4 97 BULK-b1625af8
12287 Bulk Product 11ad90ad Home & Garden $1,001.10 276 4.3 64 BULK-6ad2c8d3
12288 Bulk Product 6f57a9de Home & Garden $182.06 357 3.7 86 BULK-1991e256
12289 Bulk Product e45e0ec5 Clothing $804.04 427 3.5 34 BULK-c986face
12290 Bulk Product 471e14fe Toys & Games $106.12 259 3.8 58 BULK-41b283d8
12291 Bulk Product 3eb6cbc4 Books $285.61 326 3.8 34 BULK-33335781
12292 Bulk Product 1783dc4b Toys & Games $674.43 319 4.9 20 BULK-aa0b936e
12293 Bulk Product ccc206fb Clothing $998.65 433 0.3 31 BULK-103d8ea7
12294 Bulk Product f377939e Books $232.86 375 1.7 72 BULK-ec8e1550
12295 Bulk Product 789659f3 Electronics $784.44 471 0.0 83 BULK-280bcca6
12296 Bulk Product 5707fe19 Electronics $956.15 320 3.7 48 BULK-bca41d36
12297 Bulk Product 1c2de742 Books $852.14 415 1.6 90 BULK-c127207d
12298 Bulk Product 2faea5a6 Toys & Games $397.36 294 0.3 0 BULK-70c787ab
12299 Bulk Product 6ee4673e Books $959.82 487 4.6 44 BULK-401fbc35
12300 Bulk Product 81137a04 Sports & Outdoors $292.44 226 2.9 42 BULK-90949291
12301 Bulk Product 745a6f85 Toys & Games $558.30 393 3.2 64 BULK-5e54aa16
12302 Bulk Product 7b5b452e Books $936.28 1 0.5 27 BULK-7f0c0af7
12303 Bulk Product 8b390da5 Electronics $110.02 174 2.7 7 BULK-f93c8023
12304 Bulk Product 32e7f6fb Clothing $321.32 256 4.2 10 BULK-18eb39ce
12305 Bulk Product b989afe7 Clothing $652.62 374 3.6 77 BULK-41cc8022
12306 Bulk Product 2ba31d7c Electronics $696.06 55 1.1 33 BULK-fa239ba6
12307 Bulk Product 3ea5194e Sports & Outdoors $688.88 347 2.2 35 BULK-7dbf48d4
12308 Bulk Product 5f5bfd75 Books $543.51 300 2.6 38 BULK-f0f18862
12309 Bulk Product 5505dea0 Clothing $90.49 87 2.7 76 BULK-3a1459fe
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