Efficient Pagination with Skip/Take

Efficient pagination using OFFSET-FETCH on SQL Server.

Execution Time

20 ms

Page Size

25

Current Page

896 / 978

Total Records

24441

Items per page: 25 50 100 200

Page 896 Results Showing 22376 - 22400 of 24441

ID Name Category Price Stock Rating Reviews SKU
22935 Bulk Product 53f880f6 Home & Garden $806.86 344 1.1 34 BULK-202dcfd6
22936 Bulk Product 3d1425c3 Books $673.13 197 2.6 74 BULK-69e59027
22937 Bulk Product 1dcc3349 Home & Garden $384.02 88 1.5 4 BULK-8861ccaa
22938 Bulk Product fa015074 Sports & Outdoors $661.48 464 1.4 85 BULK-8bbaebea
22939 Bulk Product cbc770d0 Books $192.74 473 0.3 87 BULK-d089c35d
22940 Bulk Product b2b338d5 Clothing $337.09 215 2.3 5 BULK-e5f399c2
22941 Bulk Product 2a28a027 Electronics $751.83 171 1.7 88 BULK-933ca73f
22942 Bulk Product ea36a8c3 Electronics $998.41 470 4.1 93 BULK-8ae5739a
22943 Bulk Product 5ef9b416 Sports & Outdoors $729.69 497 1.4 74 BULK-c806a371
22944 Bulk Product 39098860 Electronics $272.04 258 3.9 4 BULK-8f4923f2
22945 Bulk Product 94b196ec Home & Garden $731.83 211 3.4 79 BULK-cf404d6b
22946 Bulk Product 84f37e54 Electronics $151.51 116 2.5 77 BULK-9d5bb89d
22947 Bulk Product 64808320 Books $365.47 116 3.8 89 BULK-8212e4dc
22948 Bulk Product 54958b17 Clothing $603.25 98 3.7 71 BULK-1b60250a
22949 Bulk Product 7ff21faf Home & Garden $885.06 63 3.2 93 BULK-02735574
22950 Bulk Product 83393223 Toys & Games $460.56 210 0.0 64 BULK-0398d728
22951 Bulk Product d874b0a8 Sports & Outdoors $44.00 308 3.3 20 BULK-67980398
22952 Bulk Product d7dc507e Home & Garden $145.02 388 3.9 83 BULK-94a58e2c
22953 Bulk Product 16c0455a Books $298.20 400 4.2 38 BULK-d4845e8e
22954 Bulk Product a7edbf39 Toys & Games $1,002.25 9 2.8 81 BULK-31abbc6d
22955 Bulk Product 4c6abac4 Toys & Games $153.38 184 2.2 51 BULK-25a4119e
22956 Bulk Product 22d586fe Clothing $255.72 79 5.0 65 BULK-85fae57d
22957 Bulk Product 2fed60ae Books $486.80 358 1.0 7 BULK-1f0deb8e
22958 Bulk Product c40152e4 Toys & Games $924.19 219 3.9 29 BULK-fc25539b
22959 Bulk Product 0d9a7892 Clothing $418.57 436 1.5 40 BULK-1acd29dd
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