Entity Framework Core Interview Question #45
What is a single query in EF Core?
Relationships, Navigation Properties & Loading Data Junior Beginner
Quick Interview Answer
A single query retrieves an included entity graph through one SQL query, typically using joins. This avoids the multiple round trips associated with split queries.
Detailed Explanation
A single query retrieves an included entity graph through one SQL query, typically using joins. This avoids the multiple round trips associated with split queries.
However, including multiple collections in one query can duplicate row data and create a cartesian explosion, increasing network traffic and processing.
Developers should inspect generated SQL and measure both strategies for important queries.
Code Example
var blogs = await db.Blogs
.Include(b => b.Posts)
.Include(b => b.Contributors)
.AsSingleQuery()
.ToListAsync();