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 shows the SQL it generates on the sample tests, with its query count and timing, and 5 of the 8 also capture the plan.
No signup or setup. Try Project Only the Names, then explore the full Pro path.
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.
Section 1
Stop fetching rows and fixing the result in application memory.
Move the predicate before materialization.
Read the brief: Filter Before You FetchSelect only the column the caller needs.
Read the brief: Project Only the NamesUse an existence query when the count is irrelevant.
Read the brief: Existence Without LoadingExpress absence without loading both sides.
Read the brief: Customers Without OrdersSection 2
Make grouping, totals, and rankings happen in one round trip.
Group and sum without falling back to client evaluation.
Read the brief: Customer Order TotalsAggregate, order, and limit as one server query.
Read the brief: Top Spending CustomersFilter groups with more than one qualifying row.
Group by a related column and rank the totals in one query.
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. Read IQueryable vs IEnumerable for where that boundary sits and multiple enumeration in LINQ for what deferred execution costs.
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(t => t.TappedAt.AddHours(offset).Year == year && t.TappedAt.AddHours(offset).Month == month)
Sort (by id)
Seq Scan on taps
60,000 rows read · ⚠ full table read
✗ 1 / 3 plan rules hold
The sargable rewrite
.Where(t => t.TappedAt >= start && t.TappedAt < end)
Sort (by id)
Index Scan on taps using ix_taps_tapped_at
100 rows read · ✓
✓ 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.
Sign in to 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. Revealing needs an account, and daily reveal limits depend on your plan.
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, and timing, plus the execution plan on katas with plan rules, rather than mocking database behavior.
Want to go deeper after the LINQ sequence? Continue through all 19 exercises in the Learning Path, or explore the broader EF Core practice catalog.
6 of these 8 exercises are free, no signup needed. Pro adds the complete 19-exercise path through LINQ, SQL, query plans, indexes, and analytical queries.
Try a free LINQ exercise