Tutorials ADO.NET Core Tutorial
DataReader Optimization — Complete Guide
DataReader Optimization — Complete Guide: free step-by-step lesson with examples, common mistakes, and interview tips — part of ADO.NET Core Tutorial on Toolliyo Academy.
On this page
ADO.NET Core Tutorial · Lesson 45 of 100
DataReader Optimization
Foundations ✓ → SQL & safety → Production → Projects
SQL & safety · 2 — Procs, tx, performance · ~6 min · Module 5: Performance Optimization
What is this?
Optimize readers with ordinals cached, sequential access for wide rows, and CommandBehavior.SequentialAccess when streaming large columns.
Why should you care?
ShopNest invoice PDF columns must not be loaded for list screens.
See it live — copy this example
Use a .NET console or API project with SQL Server LocalDB. Run dotnet run after pasting.
await using var reader = await cmd.ExecuteReaderAsync(
System.Data.CommandBehavior.SequentialAccess, ct);
var id = reader.GetOrdinal("Id");
while (await reader.ReadAsync(ct))
{
var orderId = reader.GetInt32(id);
// read large columns in order if present
}
What happened?
- Don’t SELECT blobs on list queries.
- SequentialAccess helps large streams.
- Cache ordinals.
Practice next
- Split list vs detail queries.
- Use SequentialAccess for PDF stream.
- Cache ordinals.
- Two queries: list vs detail.
- GetBytes loop for file stream.
Remember
Lean SELECT lists. SequentialAccess for big columns. Ordinals once.
ShopNest invoice streaming
PDF downloaded with SequentialAccess.
Outcome: List API stays light.
Interview prep for this lesson
Practice these questions aloud after reading—each links to a full structured answer.
Sign in to ask a question or upvote helpful answers.
No questions yet — be the first to ask!