Skip to content

Implement partial property loading in relational query#37857

Merged
roji merged 1 commit intodotnet:mainfrom
roji:PartialLoadingQuery
Mar 6, 2026
Merged

Implement partial property loading in relational query#37857
roji merged 1 commit intodotnet:mainfrom
roji:PartialLoadingQuery

Conversation

@roji
Copy link
Member

@roji roji commented Mar 5, 2026

Closes #37279

@roji roji force-pushed the PartialLoadingQuery branch from eb525c8 to f768fbc Compare March 5, 2026 15:15
@roji roji marked this pull request as ready for review March 5, 2026 15:54
@roji roji requested a review from a team as a code owner March 5, 2026 15:54
Copilot AI review requested due to automatic review settings March 5, 2026 15:54
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR implements partial property loading for the relational query pipeline (#37279), the first step toward supporting "stop loading vector properties" optimization. Non-auto-loaded properties (those with IsAutoLoaded = false) are now excluded from SQL SELECT projections and properly handled during materialization and change tracking. The primary use case is SQL Server vector properties (SqlVector<T>), which should not be fetched by default as they can be large.

Changes:

  • Non-auto-loaded properties are excluded from SQL entity projections and post-construction materialization; shadow properties get their sentinel value instead of a value buffer read.
  • A model validator is added to prevent constructor-bound properties from being configured as non-auto-loaded.
  • The SqlServerAutoLoadConvention is fixed to also handle nullable vector types (SqlVector<float>?) by calling UnwrapNullableType() before checking for the SqlVector<> open generic.

Reviewed changes

Copilot reviewed 12 out of 13 changed files in this pull request and generated no comments.

Show a summary per file
File Description
src/EFCore.Relational/Query/SqlExpressions/SelectExpression.cs Skips non-auto-loaded properties when building the entity projection into the SELECT list
src/EFCore/Query/Internal/StructuralTypeMaterializerSource.cs Excludes non-auto-loaded properties from the set of properties assigned after construction
src/EFCore/Query/ShapedQueryCompilingExpressionVisitor.cs Uses sentinel value for non-auto-loaded shadow properties instead of reading from value buffer
src/EFCore/Infrastructure/ModelValidator.cs Adds validation that constructor-bound properties cannot be non-auto-loaded
src/EFCore/Properties/CoreStrings.resx Adds AutoLoadedConstructorProperty error message resource (also in .Designer.cs)
src/EFCore.SqlServer/Metadata/Conventions/SqlServerAutoLoadConvention.cs Bug fix: adds UnwrapNullableType() to correctly detect nullable SqlVector<T>? types
test/EFCore.Relational.Specification.Tests/Update/NonSharedModelUpdatesTestBase.cs Adds new test cases for the not-auto-loaded query scenarios; updates existing assertions to reflect new behavior (Description/Tags not materialized)
test/EFCore.SqlServer.FunctionalTests/Update/NonSharedModelUpdatesSqlServerTest.cs SQL baselines for new and updated test methods
test/EFCore.Tests/Infrastructure/ModelValidatorTest.cs Unit test for the new constructor-bound validation
test/EFCore.SqlServer.FunctionalTests/Query/Translations/VectorTranslationsSqlServerTest.cs Updated SQL baselines: vector column excluded from SELECT
test/EFCore.SqlServer.FunctionalTests/Scaffolding/CompiledModelSqlServerTest.cs Asserts IsAutoLoaded=false on the vector property in the compiled model test
test/EFCore.SqlServer.FunctionalTests/Scaffolding/Baselines/Vector_index/VectorIndexEntityEntityType.cs Compiled model baseline: adds autoLoaded: false to vector property registration
Files not reviewed (1)
  • src/EFCore/Properties/CoreStrings.Designer.cs: Language not supported

You can also share your feedback on Copilot code review. Take the survey.

@roji
Copy link
Member Author

roji commented Mar 5, 2026

/azp run

@azure-pipelines
Copy link

Azure Pipelines successfully started running 1 pipeline(s).


var typeName = structuralType.DisplayName();

foreach (var consumedProperty in structuralType.ConstructorBinding.ParameterBindings
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Move this to ValidateAutoLoaded since it's rare to have a non-autoloaded property

Comment on lines +78 to 79
structuralType.GetProperties().Cast<IPropertyBase>().Where(p => !p.IsShadowProperty() && p is not IProperty { IsAutoLoaded: false })
.Concat(structuralType.GetComplexProperties().Where(p => !p.IsShadowProperty())));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
structuralType.GetProperties().Cast<IPropertyBase>().Where(p => !p.IsShadowProperty() && p is not IProperty { IsAutoLoaded: false })
.Concat(structuralType.GetComplexProperties().Where(p => !p.IsShadowProperty())));
structuralType.GetProperties().Where(p => !p.IsShadowProperty() && !p.IsAutoLoaded).Cast<IPropertyBase>()
.Concat(structuralType.GetComplexProperties().Where(p => !p.IsShadowProperty())));

@AndriySvyryd AndriySvyryd assigned roji and unassigned AndriySvyryd Mar 5, 2026
@roji roji merged commit 3817d73 into dotnet:main Mar 6, 2026
14 checks passed
@roji roji deleted the PartialLoadingQuery branch March 6, 2026 22:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Stop loading vector properties - relational query pipeline

3 participants