Efficient Pagination with Skip/Take

Efficient pagination using OFFSET-FETCH on SQL Server.

Execution Time

47 ms

Page Size

25

Current Page

902 / 978

Total Records

24441

Items per page: 25 50 100 200

Page 902 Results Showing 22526 - 22550 of 24441

ID Name Category Price Stock Rating Reviews SKU
23085 Bulk Product 565e70ab Electronics $210.42 138 2.6 52 BULK-d18726b3
23086 Bulk Product fef428dc Home & Garden $819.83 401 3.8 82 BULK-a83c56f9
23087 Bulk Product 88819e56 Home & Garden $800.46 454 3.2 23 BULK-ee8ce416
23088 Bulk Product f798292e Clothing $688.64 106 2.0 17 BULK-3d50339e
23089 Bulk Product 6a8efc92 Clothing $661.50 340 2.4 33 BULK-8304542a
23090 Bulk Product b149c84b Electronics $648.36 223 4.9 38 BULK-ecfe6ccb
23091 Bulk Product 91e187ce Sports & Outdoors $597.91 107 4.1 56 BULK-f12e0a3c
23092 Bulk Product a9f3162c Home & Garden $628.71 107 2.1 47 BULK-e723f96e
23093 Bulk Product 1f75a48b Books $323.23 144 2.7 56 BULK-ce48460d
23094 Bulk Product 31949c2c Electronics $280.91 192 4.5 38 BULK-380cd1ce
23095 Bulk Product dd46ccdf Books $664.29 449 4.1 47 BULK-988c7ffa
23096 Bulk Product bac21670 Sports & Outdoors $294.21 458 5.0 47 BULK-481f4780
23097 Bulk Product eac69f17 Home & Garden $934.99 382 4.4 69 BULK-6833880b
23098 Bulk Product 8be9daf8 Electronics $1,004.00 218 4.2 4 BULK-4adc8906
23099 Bulk Product 0a24b0b7 Books $858.97 23 1.1 91 BULK-f476cfaa
23100 Bulk Product 1d8994de Clothing $528.77 127 3.6 33 BULK-5230dc60
23101 Bulk Product 740273b8 Electronics $983.94 299 2.6 30 BULK-54dcd94e
23102 Bulk Product 423989ec Toys & Games $76.97 433 2.1 23 BULK-61b3ba47
23103 Bulk Product a974492c Toys & Games $289.22 196 0.2 83 BULK-c3d7220a
23104 Bulk Product e6086220 Home & Garden $636.40 384 2.6 86 BULK-4e3f079b
23105 Bulk Product 41d772e3 Electronics $373.48 41 0.6 50 BULK-1c9b6fff
23106 Bulk Product 8d994118 Toys & Games $752.62 1 0.5 52 BULK-c1050176
23107 Bulk Product f394a27b Sports & Outdoors $235.28 290 2.6 42 BULK-8775f296
23108 Bulk Product 4e740e48 Books $248.62 306 1.9 48 BULK-627d9475
23109 Bulk Product f34a7c01 Clothing $963.10 166 3.6 84 BULK-0f13fa4a
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