dotnet / dotnet/efcore

Translate embedded IQueryables to common table expressions (CTEs)

Open
#29,918 14 comments 14 reactions 0 assignees View on GitHub
area-query blocked customer-reported
Dominant language
C#
Stars
14.8k
Forks
3.4k
PR merge metrics
PR metrics pending

Description

When reusing a separate `IQueryable` in operations, e.g. `.Where(obj => otherQuery.Contains(obj))`, EF Core generates a subquery (as expected). However, in these cases, manually reviewing generated SQL in debug logs becomes more difficult to visually/mentally parse and damages the readability of the code, especially when a given `IQueryable` is injected multiple times and/or the generated SQL is especially large.

I would like to have the ability to request that applicable queries replace all injected subqueries of this nature with common table expressions named after the injected `IQueryable`'s symbol (like `otherQuery` in the previous example). This would in turn make reading the debug logs of executed SQL statements more readable.

This could just be an opt-in optional behavior specifically for use in debug contexts. One could apply this strategy individually via something like `AsNoTracking()` or app-wide via the `DbContextOptionsBuilder` like with `EnableDetailedErrors()`.

Related Issues: #26486 (CTEs via a special LINQ operator, including recursive)

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.