Efficient Pagination with Skip/Take

Efficient pagination using OFFSET-FETCH on SQL Server.

Execution Time

15 ms

Page Size

25

Current Page

578 / 978

Total Records

24441

Items per page: 25 50 100 200

Page 578 Results Showing 14426 - 14450 of 24441

ID Name Category Price Stock Rating Reviews SKU
14985 Bulk Product 4818f993 Toys & Games $177.83 289 4.6 71 BULK-e2920273
14986 Bulk Product d8b3e894 Clothing $92.82 130 3.7 60 BULK-692a6866
14987 Bulk Product e094eef8 Sports & Outdoors $57.75 72 2.5 80 BULK-ccbb332d
14988 Bulk Product ad41d3d0 Toys & Games $677.90 458 4.2 4 BULK-a57f67c6
14989 Bulk Product 8a8e30e4 Toys & Games $161.79 270 3.9 39 BULK-01cf4575
14990 Bulk Product e14182bc Books $719.01 54 4.0 13 BULK-2820381d
14991 Bulk Product c9cc88d6 Clothing $70.47 453 0.6 1 BULK-9d77566f
14992 Bulk Product 988f2418 Books $626.91 205 4.4 89 BULK-78677dd0
14993 Bulk Product 21df42f4 Clothing $381.90 493 3.3 17 BULK-2ebeb586
14994 Bulk Product 69adbbf8 Clothing $544.45 174 0.8 97 BULK-053fba91
14995 Bulk Product 56ee7b47 Sports & Outdoors $169.45 376 4.5 32 BULK-5996ab93
14996 Bulk Product 8535100f Toys & Games $837.19 36 1.3 53 BULK-492d3eb9
14997 Bulk Product ffbabbee Clothing $53.42 75 4.1 38 BULK-9af35a54
14998 Bulk Product f8235142 Sports & Outdoors $188.23 146 1.5 0 BULK-bc901d9a
14999 Bulk Product 18bd47a3 Electronics $360.27 445 1.2 52 BULK-d7a339be
15000 Bulk Product f6d9262e Sports & Outdoors $485.65 51 1.3 61 BULK-abd130df
15001 Bulk Product db23f154 Sports & Outdoors $25.71 479 3.0 29 BULK-518950cd
15002 Bulk Product 95a8eba7 Toys & Games $658.99 356 2.6 6 BULK-ae81f62b
15003 Bulk Product a4f5ec6c Sports & Outdoors $311.51 323 3.9 10 BULK-56bc8e69
15004 Bulk Product 4e468d13 Toys & Games $127.67 468 4.6 70 BULK-22f22e37
15005 Bulk Product 0b1d32f1 Books $265.85 263 3.4 53 BULK-d3a9985a
15006 Bulk Product e21258aa Sports & Outdoors $929.41 282 3.0 65 BULK-b06948ed
15007 Bulk Product c2f60c5e Electronics $614.61 139 2.5 11 BULK-fc6f67ad
15008 Bulk Product 748c07f9 Electronics $259.07 275 0.4 43 BULK-5b83885e
15009 Bulk Product bd876624 Clothing $453.97 205 0.9 99 BULK-ba931649
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