Efficient Pagination with Skip/Take

Efficient pagination using OFFSET-FETCH on SQL Server.

Execution Time

41 ms

Page Size

50

Current Page

128 / 489

Total Records

24441

Items per page: 25 50 100 200

Page 128 Results Showing 6351 - 6400 of 24441

ID Name Category Price Stock Rating Reviews SKU
6910 Bulk Product 26158e6c Clothing $774.63 335 3.2 73 BULK-2dc2ef3f
6911 Bulk Product b7c4775b Books $445.79 23 4.7 53 BULK-743f963a
6912 Bulk Product e9c67fab Clothing $981.41 172 0.8 2 BULK-efa03f0e
6913 Bulk Product 106d7464 Clothing $478.36 45 3.0 67 BULK-b4bb7b84
6914 Bulk Product 249df042 Home & Garden $686.88 191 2.7 30 BULK-3571b4be
6915 Bulk Product 96a7f7f4 Clothing $240.20 7 2.3 10 BULK-2ec26a49
6916 Bulk Product c2ed4c6c Toys & Games $492.43 61 0.5 19 BULK-f68753b2
6917 Bulk Product 7cc7fade Books $910.37 89 4.7 78 BULK-f6a001c4
6918 Bulk Product fe880078 Sports & Outdoors $177.76 86 2.1 31 BULK-253aea60
6919 Bulk Product 923b3eec Clothing $225.10 444 3.0 76 BULK-f4a7ebe5
6920 Bulk Product e37198b8 Clothing $284.66 274 1.8 46 BULK-2586bf11
6921 Bulk Product 532be370 Sports & Outdoors $854.53 320 1.7 63 BULK-949d24f8
6922 Bulk Product 18600889 Electronics $238.89 117 4.4 31 BULK-bdebf47a
6923 Bulk Product ff68e64e Electronics $881.82 462 2.4 61 BULK-b8166512
6924 Bulk Product 7bacb107 Clothing $475.85 134 0.6 38 BULK-ad411868
6925 Bulk Product c6195279 Clothing $904.70 74 1.6 10 BULK-6d74287f
6926 Bulk Product 4ebc1afe Electronics $155.06 207 1.3 25 BULK-de8cdb84
6927 Bulk Product 21cd0b45 Home & Garden $222.09 461 1.3 55 BULK-82add4d5
6928 Bulk Product 0428bc94 Home & Garden $582.97 68 1.7 57 BULK-78052b7e
6929 Bulk Product a7cc13bf Toys & Games $50.84 70 3.1 50 BULK-d9cc939a
6930 Bulk Product e822fbbf Books $748.58 64 0.3 36 BULK-84165a6a
6931 Bulk Product b4b71b7d Clothing $401.96 296 4.3 81 BULK-5d5a2350
6932 Bulk Product 22ba7bb3 Electronics $808.77 92 4.7 28 BULK-fb319150
6933 Bulk Product 3425c67a Clothing $272.53 450 4.0 61 BULK-288a8c1e
6934 Bulk Product 1a21145c Electronics $677.67 23 3.1 25 BULK-940a6c8f
6935 Bulk Product 2696e42e Sports & Outdoors $901.14 34 0.7 15 BULK-89d80d3a
6936 Bulk Product ae600b2e Clothing $196.53 407 1.7 48 BULK-9da41933
6937 Bulk Product 14339a8b Sports & Outdoors $440.46 483 0.0 96 BULK-ad34f0f9
6938 Bulk Product bc071f5f Home & Garden $111.37 326 1.2 37 BULK-ef177441
6939 Bulk Product cbf0b61b Toys & Games $933.08 16 3.8 78 BULK-166dfef5
6940 Bulk Product ea1b5d33 Sports & Outdoors $472.41 115 1.6 25 BULK-28fae47f
6941 Bulk Product 23316cee Home & Garden $959.34 211 1.8 96 BULK-d15ceae8
6942 Bulk Product 716cd788 Clothing $287.58 208 2.5 30 BULK-159907a1
6943 Bulk Product fc9fd896 Clothing $536.37 374 1.5 70 BULK-1be937c4
6944 Bulk Product 86f2ba11 Sports & Outdoors $759.56 311 3.9 42 BULK-776d4181
6945 Bulk Product d41a9150 Toys & Games $516.54 141 3.6 64 BULK-8ab6a5ac
6946 Bulk Product 899b5172 Toys & Games $707.43 237 2.0 64 BULK-270a56d4
6947 Bulk Product 13b1bf02 Sports & Outdoors $215.97 5 0.3 65 BULK-29a13f0f
6948 Bulk Product 378c893c Clothing $309.22 135 0.4 97 BULK-6b8c879c
6949 Bulk Product 69710434 Sports & Outdoors $901.02 445 0.6 11 BULK-8a8960b3
6950 Bulk Product 95add044 Books $754.91 177 0.9 56 BULK-f4ee8d38
6951 Bulk Product b9ef3b19 Toys & Games $588.56 131 2.9 97 BULK-58f942b6
6952 Bulk Product 1757eccf Books $307.57 303 2.3 55 BULK-2849424b
6953 Bulk Product 2ff53b7e Toys & Games $143.09 385 3.6 11 BULK-f15105ea
6954 Bulk Product be6b73e8 Toys & Games $448.23 73 3.1 95 BULK-9a893acd
6955 Bulk Product ba47267a Clothing $639.97 452 2.3 59 BULK-5efa696e
6956 Bulk Product 2543cdb3 Clothing $549.56 313 2.5 30 BULK-2b376164
6957 Bulk Product ec46e1de Clothing $866.40 399 3.7 28 BULK-a64ab6cb
6958 Bulk Product 3db2505f Home & Garden $868.72 485 4.2 47 BULK-e1e5451b
6959 Bulk Product 858b9906 Toys & Games $139.26 33 2.5 4 BULK-2e6dab74
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