Closes #27974: Optional entity splitting fragments - #38749
Open
anasik wants to merge 12 commits into
Open
Conversation
…rom tracked values Part of dotnet#27974
There was a problem hiding this comment.
Pull request overview
This PR adds support for optional entity-splitting mapping fragments in EF Core Relational: a split table row can be considered optional (absent unless at least one non-key value exists), affecting query join shape, validation, update pipeline behavior, runtime model metadata, scaffolding/snapshot generation, and migrations diagnostics.
Changes:
- Introduces fragment optionality metadata (
IsOptional/IsSplitFragmentOptional) and flows it through runtime model building and code generation. - Updates relational query translation to use
LEFT JOINand nullable projections for optional fragments. - Adjusts update batching and migrations/model validation to account for optional fragments, with added tests and diagnostics (new warning + event payload).
Reviewed changes
Copilot reviewed 40 out of 41 changed files in this pull request and generated 4 comments.
Show a summary per file
| File | Description |
|---|---|
| test/EFCore.SqlServer.FunctionalTests/Update/SqlServerUpdateSqlGeneratorTest.cs | Adds new usings (currently appear unused). |
| test/EFCore.SqlServer.FunctionalTests/Scaffolding/Baselines/No_NativeAOT/OwnedTypeEntityType.cs | Updates scaffold baseline for new runtime fragment ctor parameter. |
| test/EFCore.SqlServer.FunctionalTests/Scaffolding/Baselines/BigModel/OwnedTypeEntityType.cs | Updates scaffold baseline for new runtime fragment ctor parameter. |
| test/EFCore.Sqlite.FunctionalTests/Scaffolding/Baselines/No_NativeAOT/OwnedTypeEntityType.cs | Updates scaffold baseline for new runtime fragment ctor parameter. |
| test/EFCore.Sqlite.FunctionalTests/Scaffolding/Baselines/BigModel/OwnedTypeEntityType.cs | Updates scaffold baseline for new runtime fragment ctor parameter. |
| test/EFCore.Sqlite.FunctionalTests/Query/OptionalEntitySplittingQuerySqliteTest.cs | Adds query coverage for missing vs optional fragment rows and join shape. |
| test/EFCore.Sqlite.FunctionalTests/OptionalEntitySplittingSqliteTest.cs | Adds SaveChanges coverage for optional fragment insert/update/delete scenarios. |
| test/EFCore.Relational.Tests/Migrations/Internal/MigrationsModelDifferTestBase.cs | Updates MigrationsModelDiffer construction for new logger dependency. |
| test/EFCore.Relational.Tests/Migrations/Internal/MigrationsModelDifferTest.cs | Adds test for optionality-change warning during migration diffing. |
| test/EFCore.Relational.Tests/Infrastructure/RelationalModelValidatorTest.cs | Adds validation tests for optional fragments (nullable enforcement, mixed fragments). |
| test/EFCore.Relational.Specification.Tests/ModelBuilding/RelationalModelBuilderTest.cs | Adds model-building tests and test builders for IsOptional() on split tables. |
| test/EFCore.Design.Tests/Migrations/Design/MigrationScaffolderTest.cs | Updates MigrationsModelDiffer construction for new logger dependency. |
| src/EFCore.Relational/Update/ModificationCommand.cs | Adds optional-fragment helpers and changes Modified→Added decision logic. |
| src/EFCore.Relational/Update/Internal/CommandBatchPreparer.cs | Skips optional-fragment insert/delete commands when fragment row is effectively absent. |
| src/EFCore.Relational/Query/RelationalQueryableMethodTranslatingExpressionVisitor.CreateSelect.cs | Uses LEFT JOIN and nullable projections for optional fragments. |
| src/EFCore.Relational/Properties/RelationalStrings.resx | Adds new validation error strings and a migrations warning message. |
| src/EFCore.Relational/Properties/RelationalStrings.Designer.cs | Adds strongly-typed accessors and logging definition wiring for new resources. |
| src/EFCore.Relational/Migrations/Internal/MigrationsModelDiffer.cs | Injects migrations logger and emits optionality-change warning. |
| src/EFCore.Relational/Metadata/RuntimeEntityTypeMappingFragment.cs | Adds optionality to runtime mapping fragments and exposes it. |
| src/EFCore.Relational/Metadata/RelationalAnnotationNames.cs | Adds annotation name for fragment optionality. |
| src/EFCore.Relational/Metadata/ITableMappingBase.cs | Adds IsSplitFragmentOptional to table mapping metadata (debug string support). |
| src/EFCore.Relational/Metadata/IReadOnlyEntityTypeMappingFragment.cs | Adds IsOptional to fragment metadata (debug string support). |
| src/EFCore.Relational/Metadata/Internal/TableMappingBase.cs | Implements IsSplitFragmentOptional on internal mapping base. |
| src/EFCore.Relational/Metadata/Internal/RelationalModel.cs | Propagates fragment optionality into relational table/view mappings. |
| src/EFCore.Relational/Metadata/Internal/InternalEntityTypeMappingFragmentBuilder.cs | Adds internal builder APIs to set/check fragment optionality. |
| src/EFCore.Relational/Metadata/Internal/EntityTypeMappingFragment.cs | Stores optionality + configuration source and merges it during model building. |
| src/EFCore.Relational/Metadata/IMutableEntityTypeMappingFragment.cs | Adds mutable IsOptional API surface. |
| src/EFCore.Relational/Metadata/IConventionEntityTypeMappingFragment.cs | Adds convention API surface for fragment optionality. |
| src/EFCore.Relational/Metadata/Conventions/RelationalRuntimeModelConvention.cs | Emits runtime fragments with optionality propagated. |
| src/EFCore.Relational/Metadata/Builders/SplitTableBuilder`.cs | Adds public generic IsOptional() builder API. |
| src/EFCore.Relational/Metadata/Builders/SplitTableBuilder.cs | Adds non-generic IsOptional() builder API. |
| src/EFCore.Relational/Metadata/Builders/OwnedNavigationSplitTableBuilder``.cs | Adds public generic IsOptional() builder API for owned navigations. |
| src/EFCore.Relational/Metadata/Builders/OwnedNavigationSplitTableBuilder.cs | Adds non-generic IsOptional() builder API for owned navigations. |
| src/EFCore.Relational/Infrastructure/RelationalModelValidator.cs | Validates optional fragment constraints (nullable properties, no shared-table splitting). |
| src/EFCore.Relational/EFCore.Relational.baseline.json | Updates API baseline for new public APIs and signature changes. |
| src/EFCore.Relational/Diagnostics/RelationalLoggingDefinitions.cs | Adds logging definition slot for new migrations warning. |
| src/EFCore.Relational/Diagnostics/RelationalLoggerExtensions.cs | Adds logger extension emitting warning + DiagnosticSource payload. |
| src/EFCore.Relational/Diagnostics/RelationalEventId.cs | Adds new migrations event id for optionality-change warning. |
| src/EFCore.Relational/Diagnostics/EntityTypeMappingFragmentEventData.cs | Adds new DiagnosticSource payload type for fragment-related events. |
| src/EFCore.Relational/Design/Internal/RelationalCSharpRuntimeAnnotationCodeGenerator.cs | Emits IsSplitFragmentOptional and runtime fragment optionality into generated runtime model. |
| src/EFCore.Design/Migrations/Design/CSharpSnapshotGenerator.cs | Emits t.IsOptional() in snapshots for optional split fragments. |
Files not reviewed (1)
- src/EFCore.Relational/Properties/RelationalStrings.Designer.cs: Generated file
Co-authored-by: Copilot Autofix powered by AI <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.
Uh oh!
There was an error while loading. Please reload this page.