Efficient Pagination with Skip/Take

Efficient pagination using OFFSET-FETCH on SQL Server.

Execution Time

39 ms

Page Size

25

Current Page

218 / 978

Total Records

24441

Items per page: 25 50 100 200

Page 218 Results Showing 5426 - 5450 of 24441

ID Name Category Price Stock Rating Reviews SKU
5985 Bulk Product ecd12cbf Toys & Games $144.51 372 2.7 35 BULK-12346c72
5986 Bulk Product 2208a952 Toys & Games $446.02 407 1.3 86 BULK-55b8b576
5987 Bulk Product b2a5f01e Sports & Outdoors $576.54 44 5.0 14 BULK-4b7d03c1
5988 Bulk Product ee83c5e9 Clothing $177.74 465 2.0 49 BULK-3501e5b4
5989 Bulk Product a4bf40bb Sports & Outdoors $13.57 335 1.6 91 BULK-efb88cce
5990 Bulk Product 7d70cebc Clothing $770.04 407 4.2 41 BULK-aed911e4
5991 Bulk Product 8df6cd85 Toys & Games $281.22 481 2.5 23 BULK-c06ff89c
5992 Bulk Product 47f0bafe Clothing $966.89 418 2.1 70 BULK-eddc01cf
5993 Bulk Product 565601ff Clothing $649.90 230 0.3 49 BULK-583eee68
5994 Bulk Product 0083ec2d Electronics $780.38 462 1.1 74 BULK-36d4d5b4
5995 Bulk Product 627a449a Sports & Outdoors $269.20 162 3.9 0 BULK-6524e9ce
5996 Bulk Product 6730934a Toys & Games $37.30 278 4.0 55 BULK-66b3b2bb
5997 Bulk Product 60617a42 Toys & Games $255.13 435 2.2 81 BULK-22c25b68
5998 Bulk Product a284db50 Electronics $421.62 21 2.2 56 BULK-63896bd9
5999 Bulk Product ab6c73c0 Clothing $77.43 217 0.3 40 BULK-2fe32846
6000 Bulk Product 4dc8139b Books $293.25 148 4.1 7 BULK-2a5540de
6001 Bulk Product d011fb9e Electronics $408.96 4 4.2 63 BULK-66ec542b
6002 Bulk Product 54ba7a16 Sports & Outdoors $799.50 442 1.5 74 BULK-81b8d541
6003 Bulk Product 0a6d7eba Books $37.52 136 4.5 43 BULK-1d4df702
6004 Bulk Product 273970c1 Sports & Outdoors $565.24 153 0.0 9 BULK-d24f2635
6005 Bulk Product 44d6cea0 Books $452.41 308 3.7 41 BULK-0a1bc124
6006 Bulk Product f32005ea Electronics $937.63 444 4.6 8 BULK-f30ee279
6007 Bulk Product 08b6b957 Clothing $519.60 203 2.2 69 BULK-6b1c829e
6008 Bulk Product 932599b3 Clothing $301.77 213 0.4 92 BULK-5d2dd385
6009 Bulk Product b739eaad Sports & Outdoors $249.13 493 2.6 82 BULK-6d1de922
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