Add AsExpandedProperties IQueryable extension method#199
Draft
Add AsExpandedProperties IQueryable extension method#199
Conversation
…napshots Agent-Logs-Url: https://github.com/EFNext/EntityFrameworkCore.Projectables/sessions/284833b5-1b68-4d3f-aa18-7cba618c9de8 Co-authored-by: PhenX <42170+PhenX@users.noreply.github.com>
Copilot created this pull request from a session on behalf of
PhenX
April 11, 2026 07:45
View session
Contributor
There was a problem hiding this comment.
Pull request overview
Adds an opt-in IQueryable<T> extension (AsExpandedProperties<TModel>()) to force projectable-property select injection even on tracking queries, along with functional test coverage and snapshots to validate the generated SQL.
Changes:
- Add
AsExpandedProperties<TModel>()toQueryableExtensionsas a user-facing API for explicit expanded-property projection. - Add functional tests covering tracking query root, tracking +
Where, and no-tracking behavior. - Add Verify snapshots for the new functional tests across
net8.0,net9.0, andnet10.0.
Reviewed changes
Copilot reviewed 11 out of 11 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
| src/EntityFrameworkCore.Projectables/Extensions/QueryableExtensions.cs | Adds AsExpandedProperties<TModel>() with XML docs; currently delegates to ExpandProjectables(). |
| tests/EntityFrameworkCore.Projectables.FunctionalTests/AsExpandedPropertiesTests.cs | New functional tests validating SQL projection injection behavior for tracking and no-tracking queries. |
| tests/EntityFrameworkCore.Projectables.FunctionalTests/AsExpandedPropertiesTests.TrackingContext_QueryRoot_InjectsWritableProjectableProperties.DotNet8_0.verified.txt | Snapshot for tracking query-root case (net8). |
| tests/EntityFrameworkCore.Projectables.FunctionalTests/AsExpandedPropertiesTests.TrackingContext_QueryRoot_InjectsWritableProjectableProperties.DotNet9_0.verified.txt | Snapshot for tracking query-root case (net9). |
| tests/EntityFrameworkCore.Projectables.FunctionalTests/AsExpandedPropertiesTests.TrackingContext_QueryRoot_InjectsWritableProjectableProperties.DotNet10_0.verified.txt | Snapshot for tracking query-root case (net10). |
| tests/EntityFrameworkCore.Projectables.FunctionalTests/AsExpandedPropertiesTests.TrackingContext_WithWhere_InjectsProjectablePropertiesAfterFilter.DotNet8_0.verified.txt | Snapshot for tracking + Where case (net8). |
| tests/EntityFrameworkCore.Projectables.FunctionalTests/AsExpandedPropertiesTests.TrackingContext_WithWhere_InjectsProjectablePropertiesAfterFilter.DotNet9_0.verified.txt | Snapshot for tracking + Where case (net9). |
| tests/EntityFrameworkCore.Projectables.FunctionalTests/AsExpandedPropertiesTests.TrackingContext_WithWhere_InjectsProjectablePropertiesAfterFilter.DotNet10_0.verified.txt | Snapshot for tracking + Where case (net10). |
| tests/EntityFrameworkCore.Projectables.FunctionalTests/AsExpandedPropertiesTests.NoTrackingContext_QueryRoot_InjectsProjectableProperties.DotNet8_0.verified.txt | Snapshot for no-tracking query-root case (net8). |
| tests/EntityFrameworkCore.Projectables.FunctionalTests/AsExpandedPropertiesTests.NoTrackingContext_QueryRoot_InjectsProjectableProperties.DotNet9_0.verified.txt | Snapshot for no-tracking query-root case (net9). |
| tests/EntityFrameworkCore.Projectables.FunctionalTests/AsExpandedPropertiesTests.NoTrackingContext_QueryRoot_InjectsProjectableProperties.DotNet10_0.verified.txt | Snapshot for no-tracking query-root case (net10). |
tests/EntityFrameworkCore.Projectables.FunctionalTests/AsExpandedPropertiesTests.cs
Show resolved
Hide resolved
src/EntityFrameworkCore.Projectables/Extensions/QueryableExtensions.cs
Outdated
Show resolved
Hide resolved
src/EntityFrameworkCore.Projectables/Extensions/QueryableExtensions.cs
Outdated
Show resolved
Hide resolved
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Adds
AsExpandedProperties<TModel>()toQueryableExtensions— anIQueryable<T>extension that auto-injects a SELECT projection containing all EF-mapped columns plus the expression-expanded values of every writable[Projectable]property.Problem
On a tracking
DbContextthe existing auto-inject logic is intentionally suppressed (to preserve change-tracking semantics):The fix proposed in the architecture analysis: expose a method that explicitly opts into the auto-inject regardless of tracking mode.
Solution
AsExpandedProperties()delegates toExpandProjectables(), which uses a freshProjectableExpressionReplacerwithtrackByDefault: false. This forces the select injection before the expression tree is handed to EF Core's query compiler, so the compiler's own tracking guard never triggers.Read-only projectable properties (those without a setter) are excluded from the injected projection because EF Core's materialiser cannot set them; only writable projectables appear in the generated
SELECT.Recommended usage: call
AsExpandedProperties()afterWhere/OrderByand before terminal operators (FirstAsync,ToListAsync, etc.):Changes
src/.../Extensions/QueryableExtensions.csAsExpandedProperties<TModel>()with XML documentationtests/.../AsExpandedPropertiesTests.cstests/.../*.verified.txt× 9Snapshots
Tracking context (the new case):
Tracking context with WHERE: