Skip to content

Closes #27974: Optional entity splitting fragments - #38749

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

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

Conversation

@anasik

@anasik anasik 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

@anasik
anasik requested a review from a team as a code owner August 5, 2026 08:19
@AndriySvyryd
AndriySvyryd requested a review from Copilot August 5, 2026 18:56
@AndriySvyryd AndriySvyryd self-assigned this Aug 5, 2026
@AndriySvyryd AndriySvyryd added this to the 12.0.0 milestone Aug 5, 2026

Copilot AI left a comment

Copy link
Copy Markdown

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
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

Comment thread test/EFCore.SqlServer.FunctionalTests/Update/SqlServerUpdateSqlGeneratorTest.cs Outdated
Comment thread test/EFCore.Sqlite.FunctionalTests/OptionalEntitySplittingSqliteTest.cs Outdated
Comment thread src/EFCore.Relational/Update/ModificationCommand.cs
anasik and others added 2 commits August 6, 2026 09:16
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Sign up for free to 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