Efficient Pagination with Skip/Take

Efficient pagination using OFFSET-FETCH on SQL Server.

Execution Time

15 ms

Page Size

25

Current Page

859 / 978

Total Records

24441

Items per page: 25 50 100 200

Page 859 Results Showing 21451 - 21475 of 24441

ID Name Category Price Stock Rating Reviews SKU
22010 Bulk Product c16d01d8 Toys & Games $355.24 439 2.0 70 BULK-5bb99ccc
22011 Bulk Product bf19dddc Toys & Games $287.11 461 4.3 86 BULK-3676969e
22012 Bulk Product 7ea5d8ef Home & Garden $417.48 438 1.5 28 BULK-9e5a5c35
22013 Bulk Product a353e3a2 Toys & Games $515.68 260 1.5 55 BULK-7ba0c4df
22014 Bulk Product 44b1cb42 Sports & Outdoors $289.74 55 1.7 47 BULK-6d762abd
22015 Bulk Product 7eff2d2c Electronics $742.35 191 2.0 10 BULK-ddff5bfd
22016 Bulk Product cdab6b77 Books $183.82 100 2.0 86 BULK-a1b10bc6
22017 Bulk Product ea6ab620 Clothing $763.88 310 4.1 68 BULK-df1e6ff5
22018 Bulk Product c948ac66 Home & Garden $317.88 419 1.1 38 BULK-3dc5e2ee
22019 Bulk Product 8398377c Books $460.59 313 0.7 22 BULK-742abe3b
22020 Bulk Product 4fa7f4ca Toys & Games $423.52 72 2.2 40 BULK-1e36a220
22021 Bulk Product 87477b5c Electronics $503.61 86 3.9 71 BULK-89834cad
22022 Bulk Product 141fd30e Electronics $898.35 207 3.6 79 BULK-dc3ca531
22023 Bulk Product 9c1121a5 Books $218.98 184 0.2 48 BULK-7166432b
22024 Bulk Product ea0b0bba Home & Garden $903.31 62 4.8 8 BULK-665b46cd
22025 Bulk Product 30f28323 Clothing $67.08 4 3.0 51 BULK-7c29e66c
22026 Bulk Product a7c4cf51 Electronics $181.34 224 1.4 73 BULK-e8a3a080
22027 Bulk Product 7e554423 Toys & Games $451.08 69 3.1 93 BULK-1ae57efd
22028 Bulk Product 2866b540 Clothing $736.09 455 0.3 47 BULK-b2ce1e35
22029 Bulk Product c7eca61e Clothing $128.92 8 0.4 19 BULK-69bcc5cf
22030 Bulk Product a3d0af43 Electronics $1,008.21 494 0.4 18 BULK-1757c656
22031 Bulk Product 5982d038 Clothing $794.59 433 3.9 76 BULK-75c21937
22032 Bulk Product b05e26b7 Electronics $602.25 63 3.2 58 BULK-08538a3a
22033 Bulk Product e1c7bf30 Electronics $206.56 215 0.8 0 BULK-2443d930
22034 Bulk Product afb4c16d Electronics $907.03 134 3.5 94 BULK-6b07ea0c
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