Efficient Pagination with Skip/Take

Efficient pagination using OFFSET-FETCH on SQL Server.

Execution Time

14 ms

Page Size

25

Current Page

826 / 978

Total Records

24441

Items per page: 25 50 100 200

Page 826 Results Showing 20626 - 20650 of 24441

ID Name Category Price Stock Rating Reviews SKU
21185 Bulk Product db0afeea Toys & Games $623.40 334 0.5 68 BULK-9846ddea
21186 Bulk Product b7fbfdf9 Electronics $510.59 142 1.1 43 BULK-e2c883fa
21187 Bulk Product 17fc2805 Sports & Outdoors $1,004.17 314 4.4 52 BULK-3199eb46
21188 Bulk Product 60b5e217 Sports & Outdoors $182.23 385 3.2 79 BULK-3d793bad
21189 Bulk Product 273c7ff3 Home & Garden $105.18 379 1.4 5 BULK-c28f2018
21190 Bulk Product 20a02cd4 Books $730.85 420 2.2 34 BULK-260ef3a1
21191 Bulk Product 4692a802 Clothing $179.88 318 4.4 69 BULK-839a292f
21192 Bulk Product a72e4212 Electronics $628.43 51 1.7 58 BULK-8d89fa8c
21193 Bulk Product 73349663 Clothing $289.06 263 0.3 10 BULK-c34da662
21194 Bulk Product 9638dc75 Sports & Outdoors $654.84 326 4.6 68 BULK-fddfb91b
21195 Bulk Product 020e1bdf Toys & Games $53.49 335 4.8 47 BULK-3f25686c
21196 Bulk Product 9a76e29a Clothing $299.36 230 4.8 88 BULK-39da69b6
21197 Bulk Product 23c1d182 Toys & Games $414.33 368 0.1 19 BULK-266fff2d
21198 Bulk Product d6cbbdd6 Home & Garden $358.21 85 1.6 87 BULK-ebc50254
21199 Bulk Product 0cb01e99 Sports & Outdoors $62.56 445 4.2 84 BULK-d15d6ff8
21200 Bulk Product d9c992c5 Toys & Games $727.19 45 1.9 7 BULK-02e9e5e8
21201 Bulk Product 308bfc41 Home & Garden $118.48 345 0.2 14 BULK-8b2b52e3
21202 Bulk Product 31b77b6d Clothing $416.06 289 1.7 4 BULK-699a86e3
21203 Bulk Product 9872eb70 Home & Garden $523.54 122 1.9 30 BULK-10b388d7
21204 Bulk Product 9c726d65 Sports & Outdoors $587.40 266 4.1 98 BULK-6d6ffb68
21205 Bulk Product 5d1f806f Sports & Outdoors $791.70 133 3.6 94 BULK-75b9693b
21206 Bulk Product 00d7b1a4 Home & Garden $432.69 255 3.4 31 BULK-2e7c545d
21207 Bulk Product e8fa0e2d Clothing $910.68 220 4.2 71 BULK-f7fc584b
21208 Bulk Product 0c5a6779 Toys & Games $895.92 11 0.3 22 BULK-bffe87da
21209 Bulk Product 4dc64f80 Electronics $174.98 60 3.8 30 BULK-48e3126c
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