Efficient Pagination with Skip/Take

Efficient pagination using OFFSET-FETCH on SQL Server.

Execution Time

15 ms

Page Size

25

Current Page

465 / 978

Total Records

24441

Items per page: 25 50 100 200

Page 465 Results Showing 11601 - 11625 of 24441

ID Name Category Price Stock Rating Reviews SKU
12160 Bulk Product a2097f4d Electronics $859.93 421 4.7 26 BULK-386755e4
12161 Bulk Product 9d65de69 Sports & Outdoors $197.56 497 3.0 38 BULK-46b760ee
12162 Bulk Product b36dfcea Books $455.98 331 3.2 5 BULK-d0074787
12163 Bulk Product 8ea02ab0 Sports & Outdoors $16.30 272 4.3 93 BULK-6e59da6a
12164 Bulk Product 3a4c0f5c Toys & Games $412.15 275 4.5 62 BULK-f93be770
12165 Bulk Product 50872afb Books $919.28 34 4.0 73 BULK-d6f992e1
12166 Bulk Product 57e46bbf Home & Garden $826.74 283 3.9 21 BULK-d4f7dae4
12167 Bulk Product d5b2c73d Sports & Outdoors $687.37 205 3.8 68 BULK-6362a882
12168 Bulk Product 35dab363 Books $613.89 90 0.6 91 BULK-9d569f3c
12169 Bulk Product cd003940 Electronics $914.95 373 4.9 59 BULK-69c2b3ab
12170 Bulk Product 523e9a70 Sports & Outdoors $534.79 165 1.1 2 BULK-e2cafd23
12171 Bulk Product 6ac89aa9 Clothing $427.57 420 0.4 44 BULK-a61df72f
12172 Bulk Product 8e12c11d Toys & Games $797.68 246 1.1 13 BULK-532a3207
12173 Bulk Product e1266e01 Electronics $636.83 330 0.1 36 BULK-5cbb44d4
12174 Bulk Product 6bf507ba Sports & Outdoors $948.01 158 1.2 28 BULK-2f9378dd
12175 Bulk Product db59108c Books $817.36 473 1.7 4 BULK-cb8ba04b
12176 Bulk Product b56a4511 Books $864.17 211 2.4 18 BULK-5ed7811b
12177 Bulk Product 1ab79505 Electronics $649.10 452 0.7 66 BULK-33e0116c
12178 Bulk Product 84c17095 Sports & Outdoors $130.77 79 2.0 75 BULK-0a5865aa
12179 Bulk Product f2c3ae0e Home & Garden $271.40 462 3.6 94 BULK-a031adf7
12180 Bulk Product e053dbb7 Toys & Games $669.66 252 3.2 39 BULK-00ae5c63
12181 Bulk Product e385bcfa Toys & Games $23.64 364 0.9 59 BULK-2f982af1
12182 Bulk Product cde99991 Toys & Games $712.25 141 0.1 32 BULK-55942d0a
12183 Bulk Product 1eb2e3b3 Electronics $404.62 379 3.5 2 BULK-18f63036
12184 Bulk Product 1471e2eb Books $291.24 92 3.1 50 BULK-0a451d35
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