Hidden datasets
Larger data exposes materializing too early and N+1 loops that look fine on five rows.
C# LINQ practice on a real database
Practice filtering, projection, existence checks, grouping, and aggregates in your browser. Your C# runs through EF Core against PostgreSQL, so every exercise can show the generated SQL, query count, timing, and plan behind the result.
Nothing to install. Reference solutions are available when you need them.
The exercise list
These are the first two sections of the real High-Performance Data Access path. Each starts with working or plausible code that does the wrong amount of work. Your job is to keep the result correct while changing where and how the work happens.
01
Stop fetching rows and fixing the result in application memory.
Move the predicate before materialization.
Select only the column the caller needs.
Use an existence query when the count is irrelevant.
Express absence without loading both sides.
02
Make grouping, totals, and rankings happen in one round trip.
Group and sum without falling back to client evaluation.
Aggregate, order, and limit as one server query.
Filter groups with more than one qualifying row.
Compute per-device averages without N+1 queries.
What you will practice
Two expressions can return the same rows while producing radically different database work. The exercises train you to predict the boundary before production traffic finds it.
Only matching rows cross the wire
Filtering stays in SQL instead of loading a table into application memory.
Generated SQL requests only the needed columns
Less data is transferred and fewer entities are materialized.
The database answers one existence question
The query can stop at the first match and return one Boolean value.
One translated aggregate query
Reporting work stays set-based and avoids an N+1 round-trip loop.
Ordering and limiting appear in SQL
The database ranks the rows and returns only the requested result window.
Executable feedback
A static exercise can compare your final rows with an answer. Katabench can also prove that the filter stayed server-side, the aggregate used one round trip, and the access path did not scan work you never asked for.
The obvious filter
.Where(o => o.PlacedAt.Year == 2024 && o.PlacedAt.Month == 3)
Sort (by id)
└ Seq Scan on orders
~60,000 rows · ⚠ full table read
✗ 1 / 3 plan rules hold
The sargable rewrite
.Where(o => o.PlacedAt >= start && o.PlacedAt < end)
Sort (by id)
└ Index Scan using ix_orders_placed_at
~1,017 rows · ✓
✓ 3 / 3 plan rules hold
Same rows returned. Same green tests. Only one earns the index scan, and the grade.
Larger data exposes materializing too early and N+1 loops that look fine on five rows.
See whether Where, Select, OrderBy, Take, and aggregates translated where you expected.
Reveal a correct implementation after your attempt, then reset and reproduce it yourself.
LINQ exercise FAQ
Yes. You write C# in the browser, then Katabench compiles and runs the solution in an isolated server-side environment. You do not need the .NET SDK or PostgreSQL installed locally.
This sequence focuses on LINQ-to-Entities with EF Core: filtering, projection, existence checks, grouping, aggregates, ordering, and query shaping. The grader shows how the expression translates to SQL and what the database did with it.
Every exercise includes a correct reference solution you can reveal after attempting it. Hidden tests and database feedback still let you discover why a solution works instead of only copying an answer from a static list.
The guided sequence starts with Easy query-shaping exercises and moves into Medium aggregation and N+1 problems. It assumes you already know basic C# syntax and want practical LINQ and EF Core experience.
Yes. Each submission runs against a temporary PostgreSQL database with seeded data. Katabench captures generated SQL, query counts, timing, and execution-plan evidence rather than mocking database behavior.
Want to go deeper after the LINQ sequence? Continue through all 19 exercises in the guided path, or explore the broader EF Core practice catalog.
Start with 8 ordered LINQ exercises, then continue through SQL, query plans, indexes, and analytical queries in the complete 19-exercise path.
Start High-Performance Data AccessA short note when fresh kata land, plus the C# and performance tricks behind the grading. No spam, unsubscribe anytime.