Efficient Pagination with Skip/Take

Efficient pagination using OFFSET-FETCH on SQL Server.

Execution Time

10 ms

Page Size

25

Current Page

224 / 978

Total Records

24441

Items per page: 25 50 100 200

Page 224 Results Showing 5576 - 5600 of 24441

ID Name Category Price Stock Rating Reviews SKU
6135 Bulk Product d249498c Clothing $60.37 260 2.1 63 BULK-e0649424
6136 Bulk Product 8f902e49 Books $52.52 142 0.4 64 BULK-bf748c16
6137 Bulk Product 49951bb8 Books $710.71 243 4.7 31 BULK-0854a45e
6138 Bulk Product 69de915d Home & Garden $915.33 198 0.1 84 BULK-a4786241
6139 Bulk Product 9e02198e Electronics $528.17 378 1.5 22 BULK-3a260ca4
6140 Bulk Product 3c9fc747 Toys & Games $150.56 445 0.2 80 BULK-70819bd7
6141 Bulk Product b26bbad8 Electronics $615.39 291 1.9 40 BULK-df3290bf
6142 Bulk Product f985c6c2 Home & Garden $786.66 47 1.6 64 BULK-3ea17635
6143 Bulk Product fab39cad Home & Garden $728.45 362 1.5 11 BULK-e491bd40
6144 Bulk Product ec857b86 Books $67.06 377 2.1 76 BULK-769aaac1
6145 Bulk Product 80a105aa Clothing $173.78 204 2.5 50 BULK-de96f201
6146 Bulk Product 11f306e7 Clothing $589.59 161 1.5 42 BULK-d858e1ab
6147 Bulk Product f7e9f93c Home & Garden $952.61 429 4.4 41 BULK-f94ed27d
6148 Bulk Product ce88e0b0 Books $976.69 334 2.3 77 BULK-02e434ab
6149 Bulk Product 16518b3f Sports & Outdoors $940.95 447 4.8 27 BULK-41d17710
6150 Bulk Product 185599f5 Sports & Outdoors $502.82 216 5.0 56 BULK-e497b627
6151 Bulk Product 865be29d Clothing $954.24 484 2.4 15 BULK-e238deb8
6152 Bulk Product 5f341ad4 Electronics $319.52 114 0.6 58 BULK-d0e86527
6153 Bulk Product 94362009 Home & Garden $798.09 190 0.4 61 BULK-3a0f85aa
6154 Bulk Product a1a0455e Books $587.52 454 2.1 12 BULK-f250d189
6155 Bulk Product 847d0cd8 Home & Garden $637.34 112 1.7 24 BULK-4eb5f35c
6156 Bulk Product 009fa058 Clothing $523.39 227 1.5 70 BULK-9f3c8937
6157 Bulk Product e240b20c Electronics $590.70 462 1.4 11 BULK-225e829f
6158 Bulk Product 11709eee Clothing $314.32 94 1.2 99 BULK-7026247d
6159 Bulk Product adcd3301 Home & Garden $127.81 424 1.2 90 BULK-8bc096d2
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