The Repository Method Name Is the Query
Why a real repository is an interface, not a class, and how declaring a method with the right name is enough for the ORM to generate its query, with no implementation code at all.
A hand-written repository, without any framework behind it, is really just a map from an ID to the object it belongs to. An ORM-backed repository is the exact same idea, declared instead of built by hand.
A Repository Is an Interface, Not a Class
The framework's own repository is an interface, extending a base type shaped almost exactly like that same map, just with the two type parameters reversed: an object type, then its ID type, instead of an ID type mapping to an object. Extending that interface is the entire implementation. No method bodies, no queries, nothing to write beyond declaring what the repository is for.
Declaring a Method Name Is Enough to Generate the Query
From there, adding a new way to query just means declaring a method whose name follows a fixed pattern, describing the field and the condition in plain words. The framework reads that name, parses what it's asking for, and builds the actual query automatically, with no implementation code at all. A method that reads like "find every row where this field is between two values" gets turned directly into the equivalent real query, purely from its name.
This is the identical idea already covered earlier in this series about what a framework actually buys you: it doesn't add a new capability, it removes the work of writing a query by hand. Declaring the method signature is the whole job. The framework writes everything underneath it.
Where This Convention Actually Stops Being Enough
This convention has real limits worth naming honestly. A method name can only express so much before it stops mapping cleanly to a real query, and plenty of production codebases end up hand-writing a large share of their queries once performance or genuine complexity enters the picture, rather than leaning on a method name to generate every one of them. The convention is a real win for the straightforward cases. It was never meant to replace writing a query by hand for the rest.
Keep reading