Efficient Pagination with Skip/Take

Efficient pagination using OFFSET-FETCH on SQL Server.

Execution Time

15 ms

Page Size

50

Current Page

409 / 489

Total Records

24441

Items per page: 25 50 100 200

Page 409 Results Showing 20401 - 20450 of 24441

ID Name Category Price Stock Rating Reviews SKU
20960 Bulk Product de6d1c2f Electronics $992.62 82 0.2 17 BULK-e2bb4a37
20961 Bulk Product 5882f8a9 Sports & Outdoors $527.76 365 5.0 65 BULK-92a60d7a
20962 Bulk Product 78139ed4 Books $268.40 16 1.9 24 BULK-55978a8b
20963 Bulk Product 19414eb0 Toys & Games $853.45 229 4.0 12 BULK-cb8ce5fc
20964 Bulk Product fb545955 Toys & Games $273.76 232 4.6 72 BULK-20d6b9ff
20965 Bulk Product df678e6e Books $160.43 163 1.1 11 BULK-006473d3
20966 Bulk Product 12a1e0ec Toys & Games $343.78 473 1.7 96 BULK-0e1e54db
20967 Bulk Product a92b483e Sports & Outdoors $938.84 230 2.6 94 BULK-36f9c97a
20968 Bulk Product b183ce4a Clothing $259.75 95 1.7 36 BULK-1d83ad16
20969 Bulk Product 92b51eff Sports & Outdoors $413.38 252 3.9 90 BULK-db21f823
20970 Bulk Product 6d1516eb Toys & Games $536.14 332 4.5 36 BULK-094ee347
20971 Bulk Product d7f6c6bb Electronics $211.48 277 0.0 63 BULK-40303c8b
20972 Bulk Product 3b871800 Electronics $399.85 452 0.8 34 BULK-dd6af2e2
20973 Bulk Product 43ba8ffd Electronics $730.22 160 0.6 66 BULK-3247d1c1
20974 Bulk Product 4e34e199 Home & Garden $951.12 158 3.5 95 BULK-82cba27e
20975 Bulk Product 7696a4de Books $843.42 292 3.1 33 BULK-cf58ed31
20976 Bulk Product b5a1a618 Sports & Outdoors $253.95 417 1.8 31 BULK-d9142e10
20977 Bulk Product a959a1e2 Clothing $891.19 344 1.1 87 BULK-24e99c56
20978 Bulk Product 303ccce6 Electronics $665.88 110 0.5 96 BULK-8c8bf425
20979 Bulk Product 6ce173f1 Home & Garden $725.82 23 2.0 10 BULK-4a4628a9
20980 Bulk Product 07db1424 Electronics $523.49 428 2.5 76 BULK-13f1c0b9
20981 Bulk Product 692149cb Electronics $278.72 106 0.4 35 BULK-72bf37d5
20982 Bulk Product 22744e77 Books $405.14 398 1.2 2 BULK-c0f2ada0
20983 Bulk Product 01b1d8c1 Electronics $106.85 130 4.4 76 BULK-4dcc5f8c
20984 Bulk Product d391eb5d Books $581.39 236 1.8 49 BULK-030e6ea3
20985 Bulk Product aa29d732 Home & Garden $881.22 248 1.2 52 BULK-43f8faa2
20986 Bulk Product eff5bba7 Books $454.63 2 2.8 16 BULK-15c23ddc
20987 Bulk Product db2f1075 Books $921.82 41 2.9 27 BULK-8e7d5df2
20988 Bulk Product f0aa8d6e Books $685.01 201 5.0 7 BULK-dc27a138
20989 Bulk Product 0b87fa4a Toys & Games $902.32 399 1.0 64 BULK-e4149553
20990 Bulk Product d03a87d7 Toys & Games $1,006.58 73 4.7 82 BULK-d61c2430
20991 Bulk Product 312c5b0f Clothing $882.31 220 1.3 55 BULK-3ac51599
20992 Bulk Product 33a8fa4a Electronics $709.45 363 1.2 15 BULK-62c9d929
20993 Bulk Product 6924b0cc Clothing $363.37 163 2.1 14 BULK-0e901087
20994 Bulk Product 45428dc7 Clothing $353.56 293 3.3 42 BULK-2d3d65e4
20995 Bulk Product 7224fff5 Toys & Games $236.84 416 3.1 39 BULK-548015e2
20996 Bulk Product 8f31a95a Home & Garden $965.38 184 3.0 15 BULK-fdc4d5bf
20997 Bulk Product 5a9c77e0 Clothing $248.64 443 2.9 10 BULK-670b553b
20998 Bulk Product 4f91e026 Toys & Games $934.45 344 5.0 0 BULK-88728727
20999 Bulk Product 02ad7fb8 Sports & Outdoors $12.43 145 3.6 86 BULK-646934e6
21000 Bulk Product d93cdfbe Toys & Games $399.20 442 0.0 11 BULK-7001f010
21001 Bulk Product 2ae3c84b Clothing $337.43 329 1.0 27 BULK-09ae050a
21002 Bulk Product 06ced327 Sports & Outdoors $842.00 419 1.7 0 BULK-9d6eaa3a
21003 Bulk Product 098d9d3f Clothing $144.43 280 1.6 56 BULK-54dfd71d
21004 Bulk Product e949edd0 Sports & Outdoors $96.49 404 2.9 49 BULK-b82bc140
21005 Bulk Product 0feb65f3 Clothing $190.91 485 1.2 47 BULK-da66b8a7
21006 Bulk Product 4ad6b309 Toys & Games $1,006.83 130 1.0 96 BULK-9fd0e89b
21007 Bulk Product 0fcd4988 Books $424.93 167 0.0 68 BULK-fe758b01
21008 Bulk Product 744c1903 Home & Garden $234.88 350 0.1 99 BULK-7b9bbf5d
21009 Bulk Product a4f74e05 Clothing $775.15 70 1.1 91 BULK-756eef0b
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