Model building and change tracking changes to avoid loading vector properties#37829
Merged
AndriySvyryd merged 3 commits intomainfrom Mar 3, 2026
Merged
Model building and change tracking changes to avoid loading vector properties#37829AndriySvyryd merged 3 commits intomainfrom
AndriySvyryd merged 3 commits intomainfrom
Conversation
There was a problem hiding this comment.
Pull request overview
Adds core infrastructure to support partial (non-auto) property loading, allowing properties to be marked as not automatically loaded and then treated as “not loaded” by change tracking/update generation (initially aimed at vector properties).
Changes:
- Introduces
IsAutoLoadedmetadata on properties (mutable/convention/runtime) plus conventions/validation for disallowed scenarios (keys/FKs/concurrency/discriminator, JSON-mapped, Cosmos). - Adds change-tracking/update support for “not loaded” scalar properties (
PropertyEntry.IsLoaded,IUpdateEntry.IsLoaded, new internal state flag) and adjusts update SQL generation to skip unloaded properties. - Adds SQL Server convention to mark vector properties as not auto-loaded by default, plus extensive test/baseline updates.
Reviewed changes
Copilot reviewed 59 out of 62 changed files in this pull request and generated 4 comments.
Show a summary per file
| File | Description |
|---|---|
| test/EFCore.Tests/Metadata/Internal/PropertyTest.cs | Adds unit tests for Property.IsAutoLoaded default and toggling. |
| test/EFCore.Tests/Metadata/Internal/InternalPropertyBuilderTest.cs | Tests configuration-source precedence for IsAutoLoaded. |
| test/EFCore.Tests/Metadata/Conventions/ConventionDispatcherTest.cs | Verifies new OnPropertyAutoLoadChanged convention dispatch behavior. |
| test/EFCore.Tests/Infrastructure/ModelValidatorTest.cs | Adds validation tests for disallowed IsAutoLoaded = false scenarios (key/FK/etc.). |
| test/EFCore.Tests/ExceptionTest.cs | Updates fake IUpdateEntry implementation for new interface member. |
| test/EFCore.Tests/ChangeTracking/PropertyEntryTest.cs | Adds change-tracking tests around unloaded properties and sentinels. |
| test/EFCore.Tests/ChangeTracking/Internal/StateDataTest.cs | Extends internal state-flag manipulation tests for new property flag. |
| test/EFCore.Sqlite.FunctionalTests/Scaffolding/Baselines/No_NativeAOT/ManyTypesEntityType.cs | Updates compiled-model baseline to emit autoLoaded: false. |
| test/EFCore.Sqlite.FunctionalTests/Scaffolding/Baselines/BigModel_with_JSON_columns/ManyTypesEntityType.cs | Same baseline update for big model (JSON columns variant). |
| test/EFCore.Sqlite.FunctionalTests/Scaffolding/Baselines/BigModel/ManyTypesEntityType.cs | Same baseline update for big model. |
| test/EFCore.SqlServer.Tests/Metadata/Conventions/SqlServerAutoLoadConventionTest.cs | New tests for SQL Server vector autoload convention behavior. |
| test/EFCore.SqlServer.Tests/Infrastructure/SqlServerModelValidatorTest.cs | Adjusts expected validation error around JSON/vector/autoload interaction. |
| test/EFCore.SqlServer.FunctionalTests/Update/NonSharedModelUpdatesSqlServerTest.cs | Adds provider-specific SQL baselines validating unloaded columns are skipped on UPDATE. |
| test/EFCore.SqlServer.FunctionalTests/Scaffolding/Baselines/No_NativeAOT/ManyTypesEntityType.cs | Updates compiled-model baseline to emit autoLoaded: false. |
| test/EFCore.SqlServer.FunctionalTests/Scaffolding/Baselines/BigModel_with_JSON_columns/ManyTypesEntityType.cs | Same baseline update for big model (JSON columns variant). |
| test/EFCore.SqlServer.FunctionalTests/Scaffolding/Baselines/BigModel/ManyTypesEntityType.cs | Same baseline update for big model. |
| test/EFCore.Specification.Tests/Scaffolding/CompiledModelTestBase.cs | Configures a property as not auto-loaded and asserts compiled model reflects it. |
| test/EFCore.Relational.Tests/Infrastructure/RelationalModelValidatorTest.cs | Adds relational validation for JSON-mapped properties disallowing not-auto-loaded. |
| test/EFCore.Relational.Specification.Tests/Update/NonSharedModelUpdatesTestBase.cs | Adds cross-provider tests verifying UPDATE skips unloaded scalar/primitive-collection columns. |
| test/EFCore.Relational.Specification.Tests/Scaffolding/CompiledModelRelationalTestBase.cs | Asserts compiled relational model contains IsAutoLoaded = false. |
| test/EFCore.InMemory.FunctionalTests/Scaffolding/Baselines/No_NativeAOT/ManyTypesEntityType.cs | Updates compiled-model baseline to emit autoLoaded: false. |
| test/EFCore.InMemory.FunctionalTests/Scaffolding/Baselines/BigModel/ManyTypesEntityType.cs | Same baseline update for big model. |
| test/EFCore.Cosmos.Tests/Infrastructure/CosmosModelValidatorTest.cs | Adds Cosmos validation test disallowing not-auto-loaded properties. |
| test/EFCore.Cosmos.FunctionalTests/TestUtilities/CosmosTestStore.cs | Updates fake IUpdateEntry implementation for new interface member. |
| test/EFCore.Cosmos.FunctionalTests/Scaffolding/CompiledModelCosmosTest.cs | Forces Cosmos compiled model to keep property auto-loaded (provider doesn’t support feature). |
| src/EFCore/Update/IUpdateEntry.cs | Adds IsLoaded(IProperty) contract used by update pipeline. |
| src/EFCore/Properties/CoreStrings.resx | Adds new core validation messages for auto-load restrictions. |
| src/EFCore/Properties/CoreStrings.Designer.cs | Generated accessors for new core validation messages. |
| src/EFCore/Metadata/RuntimeTypeBase.cs | Extends runtime property creation API with autoLoaded argument. |
| src/EFCore/Metadata/RuntimeProperty.cs | Stores runtime IsAutoLoaded and exposes it via IReadOnlyProperty. |
| src/EFCore/Metadata/Internal/Property.cs | Adds mutable/convention IsAutoLoaded metadata with configuration source tracking + convention dispatch. |
| src/EFCore/Metadata/Internal/InternalPropertyBuilder.cs | Adds builder APIs to configure IsAutoLoaded and copy it when rebuilding properties. |
| src/EFCore/Metadata/IReadOnlyProperty.cs | Introduces IsAutoLoaded (default true) and includes it in debug string output. |
| src/EFCore/Metadata/IMutableProperty.cs | Adds mutable IsAutoLoaded surface. |
| src/EFCore/Metadata/IConventionProperty.cs | Adds convention SetIsAutoLoaded and configuration source accessor. |
| src/EFCore/Metadata/Conventions/RuntimeModelConvention.cs | Ensures runtime model captures IsAutoLoaded into RuntimeProperty. |
| src/EFCore/Metadata/Conventions/Internal/ConventionDispatcher.cs | Adds dispatch point for property auto-load changes. |
| src/EFCore/Metadata/Conventions/Internal/ConventionDispatcher.ImmediateConventionScope.cs | Implements immediate execution for property auto-load changed conventions. |
| src/EFCore/Metadata/Conventions/Internal/ConventionDispatcher.DelayedConventionScope.cs | Adds delayed-scope node for property auto-load change. |
| src/EFCore/Metadata/Conventions/Internal/ConventionDispatcher.ConventionScope.cs | Adds abstract hook for property auto-load change. |
| src/EFCore/Metadata/Conventions/Infrastructure/ProviderConventionSetBuilder.cs | Registers new AutoLoadConvention in the default convention set. |
| src/EFCore/Metadata/Conventions/IPropertyAutoLoadChangedConvention.cs | New convention interface for reacting to auto-load changes. |
| src/EFCore/Metadata/Conventions/ConventionSet.cs | Wires up storage/replace/remove for IPropertyAutoLoadChangedConvention. |
| src/EFCore/Metadata/Conventions/AutoLoadConvention.cs | New model-finalizing convention that can set IsAutoLoaded based on provider heuristics. |
| src/EFCore/Metadata/Builders/IConventionPropertyBuilder.cs | Adds IsAutoLoaded fluent configuration for conventions. |
| src/EFCore/Infrastructure/ModelValidator.cs | Adds base validation blocking not-auto-loaded for key/FK/concurrency/discriminator. |
| src/EFCore/ChangeTracking/PropertyEntry.cs | Adds PropertyEntry.IsLoaded API for scalar properties. |
| src/EFCore/ChangeTracking/Internal/InternalEntryBase.cs | Tracks per-property “not loaded” state and integrates it with modified-state logic. |
| src/EFCore/ChangeTracking/Internal/InternalEntryBase.StateData.cs | Adds new IsPropertyNotLoaded state flag. |
| src/EFCore/ChangeTracking/Internal/IInternalEntry.cs | Extends internal entry contract with scalar-property IsLoaded/SetIsLoaded. |
| src/EFCore/ChangeTracking/Internal/ChangeDetector.cs | Adjusts change detection to skip unloaded properties and detect transition away from sentinel. |
| src/EFCore.SqlServer/Metadata/Conventions/SqlServerConventionSetBuilder.cs | Replaces base autoload convention with SQL Server-specific version. |
| src/EFCore.SqlServer/Metadata/Conventions/SqlServerAutoLoadConvention.cs | New convention marking vector properties as not auto-loaded by default. |
| src/EFCore.SqlServer/Infrastructure/Internal/SqlServerModelValidator.cs | Reorders vector validation relative to base property validation. |
| src/EFCore.Relational/Update/ModificationCommand.cs | Skips writing column values for unloaded properties. |
| src/EFCore.Relational/Properties/RelationalStrings.resx | Adds relational validation message for JSON-mapped properties and autoload. |
| src/EFCore.Relational/Properties/RelationalStrings.Designer.cs | Generated accessor for new relational validation message. |
| src/EFCore.Relational/Infrastructure/RelationalModelValidator.cs | Adds relational validation blocking not-auto-loaded properties for JSON mapping. |
| src/EFCore.Design/Scaffolding/Internal/CSharpRuntimeModelCodeGenerator.cs | Emits autoLoaded: false into generated compiled models. |
| src/EFCore.Cosmos/Properties/CosmosStrings.resx | Adds Cosmos validation message disallowing partial property loading. |
| src/EFCore.Cosmos/Properties/CosmosStrings.Designer.cs | Generated accessor for new Cosmos validation message. |
| src/EFCore.Cosmos/Infrastructure/Internal/CosmosModelValidator.cs | Adds Cosmos validation blocking any not-auto-loaded properties. |
Files not reviewed (3)
- src/EFCore.Cosmos/Properties/CosmosStrings.Designer.cs: Language not supported
- src/EFCore.Relational/Properties/RelationalStrings.Designer.cs: Language not supported
- src/EFCore/Properties/CoreStrings.Designer.cs: Language not supported
test/EFCore.Specification.Tests/Scaffolding/CompiledModelTestBase.cs
Outdated
Show resolved
Hide resolved
test/EFCore.SqlServer.Tests/Infrastructure/SqlServerModelValidatorTest.cs
Show resolved
Hide resolved
Adds infrastructure for **partial property loading** — the ability to mark entity properties as "not auto-loaded" so they can be excluded from queries and skipped during change tracking. This is the foundation for lazy-loading individual properties (e.g., large BLOBs, vectors) without loading the entire entity. After this is checked in query should provide sentinel values for not loaded properties. Cosmos support not implemented. Vector-specific model building API will be added as part of #36350 Model building Fluent API, explicit loading API and query overrides (Include) will be added in #1387
roji
approved these changes
Mar 3, 2026
Member
roji
left a comment
There was a problem hiding this comment.
Great to see ths - see some minor comments. Will work on the query side once this is merged.
src/EFCore.SqlServer/Metadata/Conventions/SqlServerAutoLoadConvention.cs
Outdated
Show resolved
Hide resolved
src/EFCore.SqlServer/Metadata/Conventions/SqlServerAutoLoadConvention.cs
Outdated
Show resolved
Hide resolved
test/EFCore.Cosmos.FunctionalTests/Scaffolding/CompiledModelCosmosTest.cs
Outdated
Show resolved
Hide resolved
test/EFCore.Relational.Specification.Tests/Update/NonSharedModelUpdatesTestBase.cs
Outdated
Show resolved
Hide resolved
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 58 out of 61 changed files in this pull request and generated 5 comments.
Files not reviewed (3)
- src/EFCore.Cosmos/Properties/CosmosStrings.Designer.cs: Language not supported
- src/EFCore.Relational/Properties/RelationalStrings.Designer.cs: Language not supported
- src/EFCore/Properties/CoreStrings.Designer.cs: Language not supported
src/EFCore.SqlServer/Metadata/Conventions/SqlServerAutoLoadConvention.cs
Outdated
Show resolved
Hide resolved
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.
Fixes #37278
Part of #37277
Adds infrastructure for partial property loading — the ability to mark entity properties as "not auto-loaded" so they can be excluded from queries and skipped during change tracking. This is the foundation for lazy-loading individual properties (e.g., large BLOBs, vectors) without loading the entire entity.
After this Query should provide sentinel values for not loaded properties.
Cosmos support not implemented.
Vector-specific model building API will be added as part of #36350
Model building Fluent API, explicit loading API and query overrides (Include) will be added in #1387