Efficient Pagination with Skip/Take

Efficient pagination using OFFSET-FETCH on SQL Server.

Execution Time

11 ms

Page Size

25

Current Page

253 / 978

Total Records

24441

Items per page: 25 50 100 200

Page 253 Results Showing 6301 - 6325 of 24441

ID Name Category Price Stock Rating Reviews SKU
6860 Bulk Product ca4dd5ef Clothing $541.66 379 1.4 21 BULK-65705ec3
6861 Bulk Product 9225376e Sports & Outdoors $762.69 88 3.1 51 BULK-cc79e9fa
6862 Bulk Product 63b95404 Sports & Outdoors $895.05 234 1.0 97 BULK-62ef6d4d
6863 Bulk Product 25d56e15 Clothing $411.97 251 4.4 62 BULK-b751fbfb
6864 Bulk Product e882336d Toys & Games $915.40 332 2.8 87 BULK-2314693a
6865 Bulk Product a527746c Sports & Outdoors $482.42 318 0.5 39 BULK-aee1d480
6866 Bulk Product 3e21df94 Sports & Outdoors $261.96 382 4.2 39 BULK-bd0ccad4
6867 Bulk Product 0625c67a Books $591.60 79 1.6 85 BULK-6cc043a1
6868 Bulk Product 555c0da4 Clothing $95.35 490 3.8 13 BULK-dae42f93
6869 Bulk Product 23bfb6db Books $899.23 93 4.2 1 BULK-ac5ae737
6870 Bulk Product cde7b369 Home & Garden $676.63 441 4.7 43 BULK-4353834f
6871 Bulk Product 729e2227 Electronics $186.23 42 2.7 55 BULK-a321384b
6872 Bulk Product 3cbe261d Clothing $537.97 395 1.7 53 BULK-af552a86
6873 Bulk Product 2c0ae475 Books $292.98 424 0.7 52 BULK-dc8c693b
6874 Bulk Product 580d5bee Home & Garden $327.24 157 3.7 4 BULK-d289cd40
6875 Bulk Product ac6c71ce Home & Garden $860.49 211 0.7 24 BULK-89c74d6c
6876 Bulk Product dc8d9d9c Electronics $12.74 333 0.9 83 BULK-5940e619
6877 Bulk Product 08e5f82f Clothing $246.48 33 3.0 19 BULK-8c06dc98
6878 Bulk Product 7d289e9d Clothing $706.27 460 3.7 45 BULK-8742c98c
6879 Bulk Product 9e8fe3b1 Toys & Games $158.88 29 3.7 83 BULK-83126554
6880 Bulk Product 05b66620 Electronics $872.50 426 2.5 21 BULK-a6237adf
6881 Bulk Product f52b0848 Sports & Outdoors $392.95 371 3.6 94 BULK-c0cf6412
6882 Bulk Product e2f79364 Clothing $281.66 13 0.0 90 BULK-6f27bc22
6883 Bulk Product cfcdf710 Sports & Outdoors $555.50 224 4.1 7 BULK-d5a43efb
6884 Bulk Product 3135acac Toys & Games $873.68 489 3.0 85 BULK-ef1af487
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