Efficient Pagination with Skip/Take

Efficient pagination using OFFSET-FETCH on SQL Server.

Execution Time

46 ms

Page Size

50

Current Page

293 / 489

Total Records

24441

Items per page: 25 50 100 200

Page 293 Results Showing 14601 - 14650 of 24441

ID Name Category Price Stock Rating Reviews SKU
15160 Bulk Product 594bb818 Toys & Games $970.12 420 1.1 9 BULK-e5aa92a4
15161 Bulk Product 78cdbf5b Clothing $528.91 38 0.8 31 BULK-44718f80
15162 Bulk Product a39d402f Electronics $178.96 417 4.0 68 BULK-c5b7c197
15163 Bulk Product ed65c5f0 Books $84.57 468 1.3 6 BULK-752d638a
15164 Bulk Product b2a437e6 Electronics $945.14 219 3.3 71 BULK-6a630476
15165 Bulk Product 1aa42d4e Toys & Games $462.17 206 3.2 52 BULK-359e5632
15166 Bulk Product 5f6451e1 Home & Garden $267.45 311 2.5 58 BULK-6027ce20
15167 Bulk Product 1c18b70d Toys & Games $412.41 83 4.6 0 BULK-66125dd8
15168 Bulk Product f517840b Electronics $728.78 101 0.7 20 BULK-b3dced10
15169 Bulk Product f3c14080 Clothing $39.24 158 1.9 11 BULK-5bca717a
15170 Bulk Product 93e5f0e6 Clothing $97.12 29 2.4 94 BULK-524f0883
15171 Bulk Product 48232f94 Toys & Games $517.14 418 3.2 93 BULK-19451ccf
15172 Bulk Product 36cee84a Toys & Games $42.74 237 3.0 46 BULK-72287b55
15173 Bulk Product adf94e3a Books $766.85 427 2.6 90 BULK-9e7985f2
15174 Bulk Product 5787c46e Home & Garden $442.44 377 2.9 52 BULK-04a11f95
15175 Bulk Product 926163cb Electronics $78.85 319 2.3 80 BULK-f7960967
15176 Bulk Product 52bd86c8 Electronics $995.74 364 2.4 73 BULK-64dcc896
15177 Bulk Product ba4dbeb9 Clothing $946.90 496 3.3 12 BULK-5f7b0af9
15178 Bulk Product 8fcb8054 Home & Garden $172.37 33 2.9 57 BULK-3cbbc1ac
15179 Bulk Product 956c3406 Electronics $964.91 109 4.3 81 BULK-b1579eb0
15180 Bulk Product bd61ad33 Clothing $911.23 338 0.4 28 BULK-2855ddfa
15181 Bulk Product fed8dc47 Sports & Outdoors $288.62 278 2.8 11 BULK-55b342f4
15182 Bulk Product 6293783f Sports & Outdoors $886.76 347 3.2 59 BULK-758abde1
15183 Bulk Product d9c4018c Books $93.33 44 2.5 24 BULK-fd82041f
15184 Bulk Product 5140f825 Toys & Games $846.47 409 2.8 86 BULK-70257014
15185 Bulk Product ed97ad07 Home & Garden $806.64 286 4.4 83 BULK-d143ec69
15186 Bulk Product 13b4a7d7 Electronics $386.46 124 1.1 2 BULK-750adafd
15187 Bulk Product 863bf04c Books $463.26 498 3.5 86 BULK-51d37477
15188 Bulk Product d9eb0054 Home & Garden $574.77 16 0.3 71 BULK-d70aa196
15189 Bulk Product 9045cd10 Clothing $693.74 291 4.3 91 BULK-7118fac5
15190 Bulk Product 13dd6ee8 Toys & Games $213.45 21 1.0 29 BULK-44ac589f
15191 Bulk Product d02e3310 Clothing $541.70 179 4.7 14 BULK-0cd6f996
15192 Bulk Product ef11f1b7 Clothing $254.41 153 4.4 99 BULK-f4151ca8
15193 Bulk Product 210e8b3a Sports & Outdoors $140.80 486 0.3 49 BULK-aa67bf98
15194 Bulk Product b332c9eb Toys & Games $750.84 215 0.9 88 BULK-fd374d82
15195 Bulk Product 293ed38c Sports & Outdoors $617.58 488 4.5 42 BULK-7af6557c
15196 Bulk Product 7bc5745b Toys & Games $594.51 486 3.6 32 BULK-8fed494d
15197 Bulk Product 471191e8 Electronics $941.34 460 0.5 65 BULK-bf7763dd
15198 Bulk Product 3b93f20e Home & Garden $519.33 438 0.6 26 BULK-47e9a0a1
15199 Bulk Product a9377909 Electronics $577.24 490 1.0 23 BULK-0af8bb04
15200 Bulk Product 76a79166 Home & Garden $70.25 328 1.3 65 BULK-b3597208
15201 Bulk Product 94d8d473 Home & Garden $224.88 33 2.0 28 BULK-be4cd495
15202 Bulk Product 9cb78823 Electronics $288.30 403 0.2 30 BULK-dfc7cf23
15203 Bulk Product d86e5aac Sports & Outdoors $962.27 318 1.1 85 BULK-463ef150
15204 Bulk Product a62d5793 Toys & Games $578.24 187 0.1 3 BULK-1a922c0c
15205 Bulk Product fcec15ef Toys & Games $443.06 329 3.3 54 BULK-e26c0280
15206 Bulk Product f10f79f7 Toys & Games $414.39 164 4.2 80 BULK-77551a95
15207 Bulk Product 3eb69c11 Clothing $226.48 462 0.6 98 BULK-6ac924ae
15208 Bulk Product 5818ca4d Clothing $396.01 296 3.4 96 BULK-412c4663
15209 Bulk Product a75ffe73 Books $725.15 302 1.7 12 BULK-d20eb7cd
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