Skip to content

Closes #27974: Optional entity splitting fragments - #38749

Open
anasik wants to merge 13 commits into
dotnet:mainfrom
anasik:optional-entity-splitting-fragments
Open

Closes #27974: Optional entity splitting fragments#38749
anasik wants to merge 13 commits into
dotnet:mainfrom
anasik:optional-entity-splitting-fragments

Conversation

@anasik

@anasikanasik commented Aug 5, 2026

Copy link
Copy Markdown
  • I've read the guidelines for contributing and seen the walkthrough
  • I've posted a comment on an issue with a detailed description of how I am planning to contribute and got approval from a member of the team
  • The code builds and tests pass locally (also verified by our automated build checks)
  • Commit messages follow this format:
 Summary of the changes
- Detail 1
- Detail 2
Fixes #bugnumber
  • Tests for the changes have been added (for bug fixes / features)
  • Code follows the same patterns and style as existing code in this repo

CopilotAI left a comment

Copy link
Copy Markdown
Contributor

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 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 JOIN and 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
FileDescription
test/EFCore.SqlServer.FunctionalTests/Update/SqlServerUpdateSqlGeneratorTest.csAdds new usings (currently appear unused).
test/EFCore.SqlServer.FunctionalTests/Scaffolding/Baselines/No_NativeAOT/OwnedTypeEntityType.csUpdates scaffold baseline for new runtime fragment ctor parameter.
test/EFCore.SqlServer.FunctionalTests/Scaffolding/Baselines/BigModel/OwnedTypeEntityType.csUpdates scaffold baseline for new runtime fragment ctor parameter.
test/EFCore.Sqlite.FunctionalTests/Scaffolding/Baselines/No_NativeAOT/OwnedTypeEntityType.csUpdates scaffold baseline for new runtime fragment ctor parameter.
test/EFCore.Sqlite.FunctionalTests/Scaffolding/Baselines/BigModel/OwnedTypeEntityType.csUpdates scaffold baseline for new runtime fragment ctor parameter.
test/EFCore.Sqlite.FunctionalTests/Query/OptionalEntitySplittingQuerySqliteTest.csAdds query coverage for missing vs optional fragment rows and join shape.
test/EFCore.Sqlite.FunctionalTests/OptionalEntitySplittingSqliteTest.csAdds SaveChanges coverage for optional fragment insert/update/delete scenarios.
test/EFCore.Relational.Tests/Migrations/Internal/MigrationsModelDifferTestBase.csUpdates MigrationsModelDiffer construction for new logger dependency.
test/EFCore.Relational.Tests/Migrations/Internal/MigrationsModelDifferTest.csAdds test for optionality-change warning during migration diffing.
test/EFCore.Relational.Tests/Infrastructure/RelationalModelValidatorTest.csAdds validation tests for optional fragments (nullable enforcement, mixed fragments).
test/EFCore.Relational.Specification.Tests/ModelBuilding/RelationalModelBuilderTest.csAdds model-building tests and test builders for IsOptional() on split tables.
test/EFCore.Design.Tests/Migrations/Design/MigrationScaffolderTest.csUpdates MigrationsModelDiffer construction for new logger dependency.
src/EFCore.Relational/Update/ModificationCommand.csAdds optional-fragment helpers and changes Modified→Added decision logic.
src/EFCore.Relational/Update/Internal/CommandBatchPreparer.csSkips optional-fragment insert/delete commands when fragment row is effectively absent.
src/EFCore.Relational/Query/RelationalQueryableMethodTranslatingExpressionVisitor.CreateSelect.csUses LEFT JOIN and nullable projections for optional fragments.
src/EFCore.Relational/Properties/RelationalStrings.resxAdds new validation error strings and a migrations warning message.
src/EFCore.Relational/Properties/RelationalStrings.Designer.csAdds strongly-typed accessors and logging definition wiring for new resources.
src/EFCore.Relational/Migrations/Internal/MigrationsModelDiffer.csInjects migrations logger and emits optionality-change warning.
src/EFCore.Relational/Metadata/RuntimeEntityTypeMappingFragment.csAdds optionality to runtime mapping fragments and exposes it.
src/EFCore.Relational/Metadata/RelationalAnnotationNames.csAdds annotation name for fragment optionality.
src/EFCore.Relational/Metadata/ITableMappingBase.csAdds IsSplitFragmentOptional to table mapping metadata (debug string support).
src/EFCore.Relational/Metadata/IReadOnlyEntityTypeMappingFragment.csAdds IsOptional to fragment metadata (debug string support).
src/EFCore.Relational/Metadata/Internal/TableMappingBase.csImplements IsSplitFragmentOptional on internal mapping base.
src/EFCore.Relational/Metadata/Internal/RelationalModel.csPropagates fragment optionality into relational table/view mappings.
src/EFCore.Relational/Metadata/Internal/InternalEntityTypeMappingFragmentBuilder.csAdds internal builder APIs to set/check fragment optionality.
src/EFCore.Relational/Metadata/Internal/EntityTypeMappingFragment.csStores optionality + configuration source and merges it during model building.
src/EFCore.Relational/Metadata/IMutableEntityTypeMappingFragment.csAdds mutable IsOptional API surface.
src/EFCore.Relational/Metadata/IConventionEntityTypeMappingFragment.csAdds convention API surface for fragment optionality.
src/EFCore.Relational/Metadata/Conventions/RelationalRuntimeModelConvention.csEmits runtime fragments with optionality propagated.
src/EFCore.Relational/Metadata/Builders/SplitTableBuilder`.csAdds public generic IsOptional() builder API.
src/EFCore.Relational/Metadata/Builders/SplitTableBuilder.csAdds non-generic IsOptional() builder API.
src/EFCore.Relational/Metadata/Builders/OwnedNavigationSplitTableBuilder``.csAdds public generic IsOptional() builder API for owned navigations.
src/EFCore.Relational/Metadata/Builders/OwnedNavigationSplitTableBuilder.csAdds non-generic IsOptional() builder API for owned navigations.
src/EFCore.Relational/Infrastructure/RelationalModelValidator.csValidates optional fragment constraints (nullable properties, no shared-table splitting).
src/EFCore.Relational/EFCore.Relational.baseline.jsonUpdates API baseline for new public APIs and signature changes.
src/EFCore.Relational/Diagnostics/RelationalLoggingDefinitions.csAdds logging definition slot for new migrations warning.
src/EFCore.Relational/Diagnostics/RelationalLoggerExtensions.csAdds logger extension emitting warning + DiagnosticSource payload.
src/EFCore.Relational/Diagnostics/RelationalEventId.csAdds new migrations event id for optionality-change warning.
src/EFCore.Relational/Diagnostics/EntityTypeMappingFragmentEventData.csAdds new DiagnosticSource payload type for fragment-related events.
src/EFCore.Relational/Design/Internal/RelationalCSharpRuntimeAnnotationCodeGenerator.csEmits IsSplitFragmentOptional and runtime fragment optionality into generated runtime model.
src/EFCore.Design/Migrations/Design/CSharpSnapshotGenerator.csEmits t.IsOptional() in snapshots for optional split fragments.
Files not reviewed (1)
  • src/EFCore.Relational/Properties/RelationalStrings.Designer.cs: Generated file

Comment threadtest/EFCore.Sqlite.FunctionalTests/OptionalEntitySplittingSqliteTest.cs Outdated
Comment threadsrc/EFCore.Relational/Update/ModificationCommand.cs
anasikand others added 3 commits August 6, 2026 09:16
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants

@anasik@AndriySvyryd