Efficient Pagination with Skip/Take

Efficient pagination using OFFSET-FETCH on SQL Server.

Execution Time

15 ms

Page Size

25

Current Page

944 / 978

Total Records

24441

Items per page: 25 50 100 200

Page 944 Results Showing 23576 - 23600 of 24441

ID Name Category Price Stock Rating Reviews SKU
24135 Bulk Product 54563912 Toys & Games $72.85 275 4.0 95 BULK-96c05051
24136 Bulk Product e62e573e Electronics $840.03 242 4.0 32 BULK-0249959d
24137 Bulk Product 6218b968 Sports & Outdoors $614.92 351 0.6 7 BULK-177279bd
24138 Bulk Product 11068e81 Clothing $100.21 310 0.9 55 BULK-d8c726fb
24139 Bulk Product 8afa563b Toys & Games $304.13 282 2.7 49 BULK-ed01502e
24140 Bulk Product 5e466b3e Electronics $443.28 294 3.4 51 BULK-4f6f5c67
24141 Bulk Product dd4c9d0d Clothing $672.59 18 0.9 3 BULK-acf66e3b
24142 Bulk Product 4bedb915 Sports & Outdoors $589.07 307 4.7 71 BULK-aedab8e9
24143 Bulk Product 639d7fb9 Books $954.85 422 1.1 54 BULK-4d201366
24144 Bulk Product ece4f6ab Books $786.53 352 0.2 48 BULK-80f7e385
24145 Bulk Product 19a5a402 Toys & Games $148.29 92 3.0 51 BULK-46dcc005
24146 Bulk Product 4c79969f Electronics $884.31 52 3.6 11 BULK-ddfd98dc
24147 Bulk Product 0d4a1014 Electronics $106.51 397 1.4 11 BULK-85594fa3
24148 Bulk Product 12f83cd4 Toys & Games $22.70 75 0.0 19 BULK-4ec61b42
24149 Bulk Product f9d734dd Sports & Outdoors $234.41 36 0.6 69 BULK-26aabbab
24150 Bulk Product bdb72032 Clothing $719.45 125 4.2 8 BULK-de8859b1
24151 Bulk Product e5ca74a8 Electronics $373.15 463 3.9 75 BULK-b502be15
24152 Bulk Product 74507607 Sports & Outdoors $161.38 419 1.9 68 BULK-7613ac2e
24153 Bulk Product 8537836a Sports & Outdoors $949.61 21 1.1 69 BULK-b28b334f
24154 Bulk Product ee59fe38 Clothing $232.50 259 1.8 67 BULK-c389d4bf
24155 Bulk Product 1ea6fb2d Sports & Outdoors $168.28 316 4.5 76 BULK-ba3844ce
24156 Bulk Product 4fab751e Electronics $714.92 490 0.5 65 BULK-70f45d16
24157 Bulk Product 5681a0ef Toys & Games $190.46 110 3.9 0 BULK-25c4fa2d
24158 Bulk Product 00a89c7f Sports & Outdoors $915.97 44 0.2 3 BULK-76295047
24159 Bulk Product fbb7cc39 Electronics $250.69 185 4.3 50 BULK-d63cc160
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