Efficient Pagination with Skip/Take

Efficient pagination using OFFSET-FETCH on SQL Server.

Execution Time

30 ms

Page Size

25

Current Page

313 / 978

Total Records

24441

Items per page: 25 50 100 200

Page 313 Results Showing 7801 - 7825 of 24441

ID Name Category Price Stock Rating Reviews SKU
8360 Bulk Product cac96103 Home & Garden $684.94 441 2.4 88 BULK-55498530
8361 Bulk Product bee47056 Home & Garden $885.81 414 1.9 23 BULK-78107119
8362 Bulk Product 23d50133 Clothing $920.18 252 1.7 52 BULK-0572f3b4
8363 Bulk Product 874fe029 Electronics $718.76 18 4.8 38 BULK-61dfee6f
8364 Bulk Product ffcc2cdc Clothing $983.68 217 1.3 8 BULK-d501e500
8365 Bulk Product 15ce6b16 Sports & Outdoors $203.40 30 0.7 8 BULK-0e3345d0
8366 Bulk Product 48699710 Electronics $668.18 122 3.7 30 BULK-df4adafa
8367 Bulk Product 0d146a67 Sports & Outdoors $345.44 333 4.1 25 BULK-c4feee84
8368 Bulk Product 982683e9 Toys & Games $866.44 132 3.4 82 BULK-70515a4c
8369 Bulk Product 65bc89c4 Toys & Games $925.42 308 1.7 59 BULK-5c01a548
8370 Bulk Product 00cd3f2e Clothing $104.19 236 0.2 37 BULK-76835fbc
8371 Bulk Product f7c4da70 Sports & Outdoors $681.12 390 2.1 60 BULK-15f99ca0
8372 Bulk Product 6ff55ec6 Home & Garden $437.07 282 3.7 93 BULK-bfe2a4aa
8373 Bulk Product 1e9aa303 Electronics $466.47 308 1.7 43 BULK-7027484b
8374 Bulk Product a2184da8 Home & Garden $876.57 115 0.3 13 BULK-65191c97
8375 Bulk Product 5efa1d0d Books $473.26 486 2.4 96 BULK-4a724b36
8376 Bulk Product 3061f4e4 Toys & Games $492.51 213 2.2 85 BULK-3e1d1df3
8377 Bulk Product 8d739fbb Books $996.75 186 3.0 1 BULK-16ac0fb6
8378 Bulk Product 11cfa337 Home & Garden $868.57 287 4.8 92 BULK-3fd6cb86
8379 Bulk Product 9b3a9d9a Clothing $18.77 353 3.5 85 BULK-3c25cbdf
8380 Bulk Product a87f400a Sports & Outdoors $586.00 281 4.7 25 BULK-6237ae5d
8381 Bulk Product 77a30f7f Books $374.17 477 2.4 54 BULK-47163ed4
8382 Bulk Product 10335ec6 Sports & Outdoors $460.57 298 1.6 8 BULK-3b02586e
8383 Bulk Product 0fd77d14 Toys & Games $306.07 422 3.4 25 BULK-7ab62fb7
8384 Bulk Product 557cf337 Toys & Games $865.85 459 1.2 84 BULK-2c7052eb
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