Efficient Pagination with Skip/Take

Efficient pagination using OFFSET-FETCH on SQL Server.

Execution Time

27 ms

Page Size

200

Current Page

123 / 123

Total Records

24441

Items per page: 25 50 100 200

Page 123 Results Showing 24401 - 24441 of 24441

ID Name Category Price Stock Rating Reviews SKU
24960 Bulk Product 93d13490 Books $383.62 199 0.5 36 BULK-11f23144
24961 Bulk Product cb73bcb1 Home & Garden $743.91 463 1.0 94 BULK-3baf6525
24962 Bulk Product b0bfb1ad Books $43.43 322 2.1 5 BULK-0ba67e89
24963 Bulk Product a6333e8c Home & Garden $526.18 52 0.9 80 BULK-6db6f6de
24964 Bulk Product ec0d0d84 Toys & Games $599.72 362 3.6 55 BULK-078c88cf
24965 Bulk Product 3be09855 Clothing $434.39 100 1.0 33 BULK-a73492c9
24966 Bulk Product a566a5a5 Home & Garden $160.41 61 2.3 86 BULK-171b10a4
24967 Bulk Product d2162b8e Electronics $355.24 78 4.0 42 BULK-e9d46a4e
24968 Bulk Product c7d3a373 Clothing $89.57 176 1.0 3 BULK-eddfd6cb
24969 Bulk Product f5fb1151 Books $917.35 433 0.2 86 BULK-72b16fef
24970 Bulk Product 150ad134 Sports & Outdoors $772.83 469 0.1 1 BULK-d626984b
24971 Bulk Product 7969e091 Sports & Outdoors $133.97 198 1.8 54 BULK-86318924
24972 Bulk Product e612ca24 Clothing $466.38 384 2.9 95 BULK-9ffd2f2e
24973 Bulk Product b1f5c3d0 Toys & Games $504.35 221 2.9 76 BULK-e2c15073
24974 Bulk Product 0927b634 Toys & Games $401.05 313 0.6 96 BULK-d09d6080
24975 Bulk Product f02387e0 Clothing $979.43 16 3.6 56 BULK-bd3f633a
24976 Bulk Product 64bdb131 Home & Garden $909.42 187 1.4 2 BULK-2e3ef8af
24977 Bulk Product a69e3706 Sports & Outdoors $589.53 165 4.9 55 BULK-e7101567
24978 Bulk Product 37397e27 Toys & Games $169.93 323 1.3 23 BULK-79be089b
24979 Bulk Product 7d97f37b Clothing $228.48 177 5.0 41 BULK-3ac26009
24980 Bulk Product fb7e0e33 Books $199.62 256 3.0 31 BULK-f4413e52
24981 Bulk Product cc1470ba Books $112.26 279 0.9 24 BULK-9f939258
24982 Bulk Product 35d42b17 Clothing $188.61 127 4.3 24 BULK-fa0a462f
24983 Bulk Product 10283697 Clothing $538.73 490 4.8 39 BULK-99b0877b
24984 Bulk Product e0892413 Home & Garden $896.28 293 3.1 47 BULK-62dc8578
24985 Bulk Product b39b5520 Home & Garden $16.12 100 0.9 14 BULK-99a56473
24986 Bulk Product 86c9718f Sports & Outdoors $83.97 450 1.8 33 BULK-1ccea3b8
24987 Bulk Product ef09aaab Sports & Outdoors $482.78 339 3.6 72 BULK-80dc527f
24988 Bulk Product fc346edc Home & Garden $890.94 484 0.9 8 BULK-f7c00ac9
24989 Bulk Product 231dc7a2 Clothing $417.94 419 3.1 80 BULK-43dbe707
24990 Bulk Product f20e3274 Sports & Outdoors $454.10 202 4.4 77 BULK-efb85147
24991 Bulk Product da93319e Books $919.16 244 3.8 69 BULK-cc1c37f5
24992 Bulk Product e0e774ec Toys & Games $881.11 80 4.1 18 BULK-caeddc6c
24993 Bulk Product 3fdc7f31 Clothing $514.46 120 0.7 32 BULK-0981347c
24994 Bulk Product 7d6cc982 Electronics $248.92 412 2.7 55 BULK-cdf65de2
24995 Bulk Product 05e65829 Sports & Outdoors $109.27 402 1.5 63 BULK-12cf1700
24996 Bulk Product 908bb789 Toys & Games $885.71 479 2.5 69 BULK-c044aa44
24997 Bulk Product 10e106e9 Home & Garden $303.92 169 2.8 44 BULK-ee7d2b37
24998 Bulk Product 427e1267 Electronics $505.68 88 0.9 89 BULK-b6059874
24999 Bulk Product 7cb08069 Electronics $800.30 29 3.2 73 BULK-0a14347d
25000 Bulk Product 44e65772 Electronics $599.69 35 3.0 73 BULK-91ba76a4
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