Efficient Pagination with Skip/Take

Efficient pagination using OFFSET-FETCH on SQL Server.

Execution Time

13 ms

Page Size

25

Current Page

626 / 978

Total Records

24441

Items per page: 25 50 100 200

Page 626 Results Showing 15626 - 15650 of 24441

ID Name Category Price Stock Rating Reviews SKU
16185 Bulk Product 3d31bf9d Toys & Games $12.37 492 3.7 54 BULK-06d887ef
16186 Bulk Product 3db71040 Home & Garden $267.40 190 3.1 0 BULK-0fc77337
16187 Bulk Product dab3d42d Books $409.05 30 2.0 8 BULK-58664b04
16188 Bulk Product d3026bf1 Home & Garden $813.74 219 1.4 51 BULK-24a7db57
16189 Bulk Product 14ceb246 Toys & Games $132.29 278 0.1 93 BULK-95855935
16190 Bulk Product 54aa4210 Books $902.42 311 2.4 43 BULK-cf386219
16191 Bulk Product d4426c6e Books $777.03 236 4.0 5 BULK-128b799d
16192 Bulk Product 09385ec9 Clothing $479.40 93 2.9 61 BULK-1b77249e
16193 Bulk Product 0d5eca35 Toys & Games $477.03 171 3.0 29 BULK-a412d360
16194 Bulk Product d76ae05f Clothing $23.06 67 3.5 57 BULK-dd274cc8
16195 Bulk Product f39ff8c2 Books $866.58 312 1.6 7 BULK-d98f87d6
16196 Bulk Product 9db99b16 Electronics $213.17 468 4.6 20 BULK-a408dfed
16197 Bulk Product 1a3cc789 Books $725.65 299 0.2 13 BULK-061becbb
16198 Bulk Product 754ae368 Books $964.66 13 4.0 19 BULK-f80ec3f4
16199 Bulk Product 9f5d8572 Home & Garden $687.53 132 1.7 68 BULK-63beb459
16200 Bulk Product b6a19087 Toys & Games $953.86 32 1.1 48 BULK-019ecafb
16201 Bulk Product ba35f7fe Electronics $948.15 22 4.9 26 BULK-fee03da0
16202 Bulk Product 0efaf83e Home & Garden $567.18 325 4.7 10 BULK-b1569e17
16203 Bulk Product 3d450496 Clothing $916.68 338 2.2 90 BULK-38c98ab2
16204 Bulk Product 7c43d58c Books $794.37 285 3.4 79 BULK-70788fa7
16205 Bulk Product 1db89d4a Sports & Outdoors $287.83 257 2.8 56 BULK-373ec2f8
16206 Bulk Product 537f322a Electronics $99.32 470 1.3 72 BULK-a005c8d0
16207 Bulk Product 6e8ce6a8 Books $872.59 401 0.3 52 BULK-df03b67f
16208 Bulk Product 3176f3c3 Clothing $763.44 390 0.1 24 BULK-03af6f95
16209 Bulk Product 8800e8cc Books $697.12 486 1.6 33 BULK-348f1d8e
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