Efficient Pagination with Skip/Take

Efficient pagination using OFFSET-FETCH on SQL Server.

Execution Time

14 ms

Page Size

25

Current Page

857 / 978

Total Records

24441

Items per page: 25 50 100 200

Page 857 Results Showing 21401 - 21425 of 24441

ID Name Category Price Stock Rating Reviews SKU
21960 Bulk Product 8fd91477 Sports & Outdoors $882.17 238 0.6 60 BULK-8dede372
21961 Bulk Product 5b91acf6 Home & Garden $854.46 318 4.6 21 BULK-d59eedbd
21962 Bulk Product 4ebd6460 Books $436.10 403 2.0 65 BULK-888ee995
21963 Bulk Product 75c9f099 Sports & Outdoors $117.46 253 0.0 65 BULK-7161a337
21964 Bulk Product 1268963c Toys & Games $708.60 145 2.3 5 BULK-c326939e
21965 Bulk Product 76845f42 Toys & Games $768.78 82 4.6 97 BULK-a68aab06
21966 Bulk Product 1fbb32d2 Home & Garden $176.57 388 1.7 11 BULK-11f2ce35
21967 Bulk Product 2839dbd5 Sports & Outdoors $221.34 262 0.2 77 BULK-ac7a7537
21968 Bulk Product 6eded686 Home & Garden $789.04 137 4.2 48 BULK-12efcac6
21969 Bulk Product e651d577 Toys & Games $121.59 0 2.1 41 BULK-19bc1ab1
21970 Bulk Product b4ee0992 Clothing $149.65 364 1.8 26 BULK-d59c65b7
21971 Bulk Product 73c8ab12 Sports & Outdoors $676.09 444 0.4 20 BULK-81efcae3
21972 Bulk Product c60d7e3b Toys & Games $423.99 117 2.0 8 BULK-4cb7ed08
21973 Bulk Product 51af23ab Clothing $1,006.53 318 1.2 96 BULK-9f39ff09
21974 Bulk Product e7c8e6a3 Toys & Games $487.07 466 3.6 23 BULK-be2a25a1
21975 Bulk Product a5638b7d Electronics $43.69 325 3.9 88 BULK-13f9dff3
21976 Bulk Product 943d985e Home & Garden $241.79 120 2.2 17 BULK-39b192a6
21977 Bulk Product ccac318b Books $240.01 483 4.1 31 BULK-49463970
21978 Bulk Product 969368cf Toys & Games $149.27 484 2.0 55 BULK-95472062
21979 Bulk Product f0b99d9a Toys & Games $355.50 163 0.2 21 BULK-99232f2b
21980 Bulk Product 34413962 Sports & Outdoors $794.47 216 0.6 5 BULK-a57af6b9
21981 Bulk Product 1f53b27d Electronics $593.65 112 1.5 17 BULK-ee5eee91
21982 Bulk Product 07a4ee89 Toys & Games $719.63 321 4.2 10 BULK-44126580
21983 Bulk Product 74edbe22 Home & Garden $796.35 212 3.2 57 BULK-cfaea4b6
21984 Bulk Product 427beb30 Electronics $29.01 80 4.6 67 BULK-827f12e6
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