Entity Framework Core Interview Question #44

What is a split query in EF Core?

Relationships, Navigation Properties & Loading Data Junior Beginner

Quick Interview Answer

A split query loads certain included collection relationships using multiple SQL queries instead of one large joined query.

Detailed Explanation

A split query loads certain included collection relationships using multiple SQL queries instead of one large joined query.

This can avoid cartesian explosion when multiple collection navigations are included. The trade-off is additional database round trips and potential consistency considerations between the separate queries.

AsSplitQuery should be selected based on the shape and performance characteristics of the query rather than applied universally.

Code Example

var blogs = await db.Blogs
    .Include(b => b.Posts)
    .Include(b => b.Contributors)
    .AsSplitQuery()
    .ToListAsync();