Efficient Pagination with Skip/Take

Efficient pagination using OFFSET-FETCH on SQL Server.

Execution Time

19 ms

Page Size

25

Current Page

499 / 978

Total Records

24441

Items per page: 25 50 100 200

Page 499 Results Showing 12451 - 12475 of 24441

ID Name Category Price Stock Rating Reviews SKU
13010 Bulk Product 4b983315 Toys & Games $459.67 104 1.3 21 BULK-95d91878
13011 Bulk Product ada58740 Sports & Outdoors $844.06 87 4.2 20 BULK-c639055e
13012 Bulk Product ccdee71e Books $133.75 190 1.9 90 BULK-b511e501
13013 Bulk Product a3607e3c Home & Garden $25.41 183 0.1 82 BULK-95d782a1
13014 Bulk Product 0d46a9f8 Books $409.00 271 2.4 28 BULK-1e8e2cbc
13015 Bulk Product c598f317 Home & Garden $247.39 126 0.1 82 BULK-05d9ea8b
13016 Bulk Product 2c3dcd79 Books $540.53 112 4.4 47 BULK-b5c92c0e
13017 Bulk Product 0a7f8f32 Electronics $622.06 95 2.8 98 BULK-1343919a
13018 Bulk Product 41226d6e Electronics $165.84 203 4.1 33 BULK-04f33bae
13019 Bulk Product 2f0be871 Home & Garden $919.27 36 3.1 25 BULK-fc5d5dad
13020 Bulk Product 6206dd8a Toys & Games $380.03 351 1.0 72 BULK-2d92ed09
13021 Bulk Product 5faca416 Electronics $753.22 393 4.4 66 BULK-2f29dfba
13022 Bulk Product d5e5c7fa Sports & Outdoors $383.92 456 4.5 65 BULK-d5c9fa07
13023 Bulk Product 57b903ba Electronics $211.40 202 2.8 15 BULK-bc2c31ca
13024 Bulk Product 5fac1852 Electronics $916.96 323 0.6 63 BULK-a01b9431
13025 Bulk Product dd0cf7be Clothing $704.46 172 3.4 61 BULK-51eb201b
13026 Bulk Product 8f3347e9 Electronics $236.76 72 4.9 72 BULK-75b1d184
13027 Bulk Product f8dd8d9e Toys & Games $638.53 430 3.6 60 BULK-f128a299
13028 Bulk Product 8b3fcae6 Sports & Outdoors $426.14 324 0.7 36 BULK-7a659b2d
13029 Bulk Product f27fced7 Clothing $524.73 475 1.6 3 BULK-9941432a
13030 Bulk Product afd532b9 Home & Garden $719.48 366 4.4 93 BULK-b276c269
13031 Bulk Product c8232db3 Books $405.89 358 1.5 94 BULK-f8dff380
13032 Bulk Product ec6ec617 Electronics $709.99 259 2.3 32 BULK-19e732f0
13033 Bulk Product 66ff9a26 Electronics $1,009.41 24 4.3 88 BULK-df8edf42
13034 Bulk Product a195b0be Clothing $638.99 348 1.7 92 BULK-640a70b8
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