Entity Framework Core Interview Question #133

When should AsSplitQuery be considered?

Performance, Raw SQL, Stored Procedures & Advanced Queries Senior Advanced

Quick Interview Answer

AsSplitQuery can help when eager-loading multiple collections would create a very large joined result and duplicate substantial data. It uses multiple SQL queries for relevant included collections instead of one large join. The trade-off is additional round trips and possible consistency considerations between queries, so measure both strategies for important workloads.

Detailed Explanation

AsSplitQuery can help when eager-loading multiple collections would create a very large joined result and duplicate substantial data. It uses multiple SQL queries for relevant included collections instead of one large join. The trade-off is additional round trips and possible consistency considerations between queries, so measure both strategies for important workloads.

Code Example

var orders = await db.Orders
    .Include(o => o.Items)
    .Include(o => o.Payments)
    .AsSplitQuery()
    .ToListAsync();