Efficient Pagination with Skip/Take

Efficient pagination using OFFSET-FETCH on SQL Server.

Execution Time

20 ms

Page Size

25

Current Page

306 / 978

Total Records

24441

Items per page: 25 50 100 200

Page 306 Results Showing 7626 - 7650 of 24441

ID Name Category Price Stock Rating Reviews SKU
8185 Bulk Product 3bd4b8f5 Sports & Outdoors $25.54 237 4.8 5 BULK-b5f24054
8186 Bulk Product a23a5af6 Books $681.11 23 4.6 48 BULK-b14dd2a7
8187 Bulk Product fd97111e Toys & Games $86.15 34 4.6 12 BULK-20caa535
8188 Bulk Product c14d23d5 Home & Garden $611.12 126 3.0 22 BULK-f088764c
8189 Bulk Product ee535e5e Home & Garden $308.62 472 2.3 59 BULK-e25cb533
8190 Bulk Product e7934b44 Sports & Outdoors $22.39 90 3.4 79 BULK-916a3e23
8191 Bulk Product b7ab1c91 Electronics $367.02 111 3.6 72 BULK-702cdba0
8192 Bulk Product a030c6bd Clothing $438.17 476 4.2 68 BULK-63c2210b
8193 Bulk Product 5db17b91 Electronics $382.44 13 3.9 34 BULK-1b2e3a88
8194 Bulk Product c0191e5b Toys & Games $618.71 402 4.6 47 BULK-44bb467c
8195 Bulk Product 8a94686f Home & Garden $975.30 406 0.5 81 BULK-013a7843
8196 Bulk Product 21b71cf0 Electronics $218.24 39 4.7 86 BULK-d88c09df
8197 Bulk Product c7604300 Books $431.08 220 0.0 83 BULK-47266a8f
8198 Bulk Product c49f9579 Sports & Outdoors $661.45 3 0.1 3 BULK-745177d0
8199 Bulk Product 5961dec3 Toys & Games $134.43 406 3.6 29 BULK-c9a6bd90
8200 Bulk Product 9ca0c6ac Clothing $539.49 456 0.4 69 BULK-fc3f8969
8201 Bulk Product f26244c4 Electronics $710.54 284 3.1 39 BULK-51eaf3f5
8202 Bulk Product c3a19d83 Electronics $865.57 305 0.2 83 BULK-3d136afd
8203 Bulk Product 7ea3ce42 Clothing $630.08 57 2.1 84 BULK-a8943006
8204 Bulk Product f1100a73 Electronics $939.78 80 0.3 5 BULK-5707652a
8205 Bulk Product 54ad700d Home & Garden $55.79 135 3.3 81 BULK-f2d67128
8206 Bulk Product 5f9f91cb Electronics $464.51 351 1.0 43 BULK-4848e516
8207 Bulk Product 63a5637f Sports & Outdoors $13.52 380 2.3 72 BULK-38505ba9
8208 Bulk Product 32b61c0d Clothing $690.37 101 3.1 14 BULK-307ce6a3
8209 Bulk Product 2ec6092f Electronics $593.92 457 1.5 38 BULK-b0a736f0
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