Efficient Pagination with Skip/Take

Efficient pagination using OFFSET-FETCH on SQL Server.

Execution Time

16 ms

Page Size

25

Current Page

853 / 978

Total Records

24441

Items per page: 25 50 100 200

Page 853 Results Showing 21301 - 21325 of 24441

ID Name Category Price Stock Rating Reviews SKU
21860 Bulk Product 73f2e5c3 Clothing $505.65 87 3.6 81 BULK-95e08792
21861 Bulk Product 2be860d0 Home & Garden $787.02 24 1.1 63 BULK-455d2d8b
21862 Bulk Product 67fac2a7 Books $798.30 313 2.4 37 BULK-90327b4b
21863 Bulk Product 2f8e624f Toys & Games $907.21 248 3.0 39 BULK-52bb2a18
21864 Bulk Product beb58275 Clothing $223.16 498 1.5 3 BULK-8e63441e
21865 Bulk Product fd1a7e14 Clothing $634.41 90 0.7 12 BULK-ae6a72e8
21866 Bulk Product f48095bf Books $373.57 237 1.8 53 BULK-3de5a521
21867 Bulk Product ff6a4a9f Toys & Games $967.43 47 0.6 25 BULK-f7fe882a
21868 Bulk Product 0ceb1c02 Books $904.67 205 2.9 7 BULK-5e80265b
21869 Bulk Product e450eb90 Books $498.80 377 4.0 81 BULK-7d0b509e
21870 Bulk Product 06a3adce Sports & Outdoors $158.13 302 2.7 72 BULK-121e250b
21871 Bulk Product 88c06253 Books $334.79 139 2.1 97 BULK-a759a629
21872 Bulk Product fad15c42 Clothing $743.33 333 1.5 19 BULK-8930218e
21873 Bulk Product 701bab67 Books $157.88 346 1.0 34 BULK-4079a905
21874 Bulk Product f8653464 Sports & Outdoors $822.94 490 4.1 23 BULK-cc0450d5
21875 Bulk Product c0080e90 Clothing $193.17 76 1.5 15 BULK-9128014b
21876 Bulk Product f2251685 Electronics $376.60 295 1.4 47 BULK-e84b8b13
21877 Bulk Product b872b221 Toys & Games $306.26 407 1.7 90 BULK-782e9e0e
21878 Bulk Product 9ea5dadd Sports & Outdoors $954.19 488 0.3 5 BULK-04baebf6
21879 Bulk Product 28cb7a4f Home & Garden $831.11 470 5.0 84 BULK-da4a8b49
21880 Bulk Product 1b607bcf Books $784.75 96 4.0 74 BULK-5f7ed500
21881 Bulk Product 709a581a Books $173.63 198 0.9 40 BULK-53c43bb8
21882 Bulk Product 4cfc2b26 Toys & Games $273.38 355 3.0 15 BULK-8cecd43e
21883 Bulk Product e07f9026 Sports & Outdoors $102.00 2 3.0 85 BULK-2419cc8e
21884 Bulk Product 25dbfd17 Sports & Outdoors $809.86 151 3.9 65 BULK-1cf22485
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