IQueryable<T> represents a query over elements of type T. With Entity Framework Core (EF Core), it lets you assemble a database query in memory before executing it. For example, ApplicationDbContext.BoardGames is a DbSet<BoardGame>, and DbSet<T> implements IQueryable<T>. You can therefore use LINQ operators on BoardGames without writing SQL yourself. section 5.1.3 section 5.0
A board-game API read operation follows three steps:
- Start with _context.BoardGames to represent the board-game records. section 5.1.3
- Compose the query with LINQ operators. Where(b => b.Year == 2020) restricts the results; OrderBy(b => b.Name) sorts them. You can chain the operators or add them on separate lines. section 5.1.3
- Execute the query when you need its results. ToArray() makes EF Core fetch the records and return an array of BoardGame entities. section 5.1.3 section 5.2
The composed representation is an expression tree. EF Core translates it into a database query when the IQueryable<T> is executed, rather than when each operator is added. Against SQL Server, filtering by year and ordering by name corresponds to a SELECT with WHERE and ORDER BY clauses. In a controller, constructor injection makes ApplicationDbContext available to action methods, allowing a real database query to replace manually generated response data. section 5.1.3 section 5.2
var query = _context.BoardGames .Where(b => b.Year == 2020) .OrderBy(b => b.Name);
This listing shows a query built by chaining a year filter and a name sort; it does not execute the query. section 5.1.3
IQueryable<T> can also be returned from a GraphQL query method. A method returning context.BoardGames gives the HotChocolate runtime a queryable source; its paging, projection, filtering, and sorting attributes let the runtime shape database queries. This keeps the DbSet as the starting point while the GraphQL request determines which supported operations are applied. section 10.2.3



