Efficient Pagination with Skip/Take

Efficient pagination using OFFSET-FETCH on SQL Server.

Execution Time

44 ms

Page Size

25

Current Page

950 / 978

Total Records

24441

Items per page: 25 50 100 200

Page 950 Results Showing 23726 - 23750 of 24441

ID Name Category Price Stock Rating Reviews SKU
24285 Bulk Product 226c99f9 Books $991.65 159 3.6 86 BULK-ed7a45e8
24286 Bulk Product 2fe64224 Books $699.25 239 3.7 45 BULK-e0a20f37
24287 Bulk Product d7dbbb89 Clothing $417.88 3 4.9 87 BULK-e85e20de
24288 Bulk Product 3f9f7470 Electronics $561.99 461 3.2 62 BULK-cf3516e4
24289 Bulk Product a47cc51d Books $384.25 495 2.4 41 BULK-c7a1fdfb
24290 Bulk Product cd8a7338 Home & Garden $484.88 194 2.7 32 BULK-a1ff757e
24291 Bulk Product 1436ad57 Toys & Games $331.11 182 1.0 10 BULK-263abc7f
24292 Bulk Product 080eb84a Books $232.98 358 2.5 0 BULK-2a2bfb6f
24293 Bulk Product c0a64dcd Books $63.72 355 3.2 55 BULK-4646cf43
24294 Bulk Product b231010d Books $790.39 41 1.3 50 BULK-42a23fef
24295 Bulk Product efc4af1e Clothing $596.30 201 3.2 45 BULK-baf2be24
24296 Bulk Product 39536f70 Toys & Games $341.22 406 4.2 55 BULK-9e33c2df
24297 Bulk Product 046078c8 Home & Garden $976.05 283 1.7 38 BULK-7cc41044
24298 Bulk Product 66bd7e78 Electronics $680.84 235 2.0 14 BULK-f20819f3
24299 Bulk Product 450d4f03 Sports & Outdoors $903.30 104 1.2 62 BULK-e214706b
24300 Bulk Product b3d2794c Toys & Games $843.28 416 3.6 1 BULK-f5d8bd0e
24301 Bulk Product b619120d Clothing $530.53 336 4.8 89 BULK-221505f8
24302 Bulk Product 89f4d20f Toys & Games $708.17 471 3.3 49 BULK-a2c13e38
24303 Bulk Product a3f8c96d Sports & Outdoors $547.49 71 1.2 86 BULK-7c76a846
24304 Bulk Product df3a352a Toys & Games $525.62 294 0.8 78 BULK-fba345d3
24305 Bulk Product b1afc906 Home & Garden $408.09 336 3.5 4 BULK-2c8278d2
24306 Bulk Product 8621e84e Clothing $720.92 336 1.1 54 BULK-81709226
24307 Bulk Product 9e558d5e Clothing $567.30 270 2.0 75 BULK-d4f9f30c
24308 Bulk Product ef39ca9a Toys & Games $870.70 54 0.9 49 BULK-c6d0c43d
24309 Bulk Product 55dfb6ab Home & Garden $117.43 149 1.8 87 BULK-b749bed5
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