Allow temporal period properties to be mapped to CLR properties#38110
Merged
Allow temporal period properties to be mapped to CLR properties#38110
Conversation
Remove the shadow-property validation enforcement in SqlServerModelValidator, allowing temporal period properties (PeriodStart/PeriodEnd) to be mapped to CLR properties instead of requiring them to be shadow properties. Add lambda-based HasPeriodStart/HasPeriodEnd overloads on TemporalTableBuilder<TEntity> and OwnedNavigationTemporalTableBuilder<TOwner, TDependentEntity> for strongly-typed period property configuration. Scaffolding behavior is unchanged: period columns are still excluded from the column query and scaffolded as shadow properties by default. Fixes #26463 Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
There was a problem hiding this comment.
Pull request overview
Removes the restriction that SQL Server temporal period properties must be shadow properties, allowing them to be mapped to CLR properties, and adds strongly-typed (lambda) configuration APIs for temporal period properties.
Changes:
- Removed temporal period “shadow-only” validation from
SqlServerModelValidator. - Added lambda-based
HasPeriodStart/HasPeriodEndoverloads for temporal table builders. - Updated/added tests across validator, model building, scaffolding, and functional temporal query scenarios to cover CLR period properties.
Reviewed changes
Copilot reviewed 9 out of 10 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| test/EFCore.SqlServer.Tests/Infrastructure/SqlServerModelValidatorTest.cs | Updates validator test to accept CLR-mapped period properties. |
| test/EFCore.SqlServer.FunctionalTests/Query/TemporalTableSqlServerTest.cs | Adds functional coverage for CLR period properties (including temporal queries). |
| test/EFCore.SqlServer.FunctionalTests/ModelBuilding/SqlServerModelBuilderTestBase.cs | Adds model-building tests and test-builder support for lambda-based period configuration. |
| test/EFCore.Design.Tests/Scaffolding/Internal/CSharpDbContextGeneratorTest.cs | Updates scaffolding test to validate temporal metadata without expecting a validator exception. |
| src/EFCore.SqlServer/Metadata/Builders/TemporalTableBuilder`.cs | Adds lambda overloads for period start/end configuration on generic temporal builder. |
| src/EFCore.SqlServer/Metadata/Builders/OwnedNavigationTemporalTableBuilder``.cs | Adds lambda overloads for period start/end configuration on generic owned-navigation temporal builder. |
| src/EFCore.SqlServer/Infrastructure/Internal/SqlServerModelValidator.cs | Removes the check enforcing period properties to be shadow properties. |
| src/EFCore.SqlServer/Design/Internal/SqlServerAnnotationCodeGenerator.cs | Updates comment to reflect rev-eng behavior (period properties remain shadow by default). |
Files not reviewed (1)
- src/EFCore.SqlServer/Properties/SqlServerStrings.Designer.cs: Language not supported
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
AndriySvyryd
approved these changes
Apr 15, 2026
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Contributor
API review baseline changes for
|
roji
added a commit
to roji/EntityFramework.Docs
that referenced
this pull request
Apr 16, 2026
Document the new EF Core 11 feature that allows temporal period properties (PeriodStart/PeriodEnd) to be mapped to CLR properties instead of being restricted to shadow properties. Updates: - temporal-tables.md: New 'Mapping period columns to CLR properties' section with lambda and string-based configuration examples - temporal-tables.md: Updated existing text to note shadow properties are the default, with links to the new section - whatsnew.md (EF Core 11): New subsection under SQL Server Relates to dotnet/efcore#38110 Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
This was referenced Apr 16, 2026
roji
added a commit
to roji/EntityFramework.Docs
that referenced
this pull request
Apr 16, 2026
Document the new EF Core 11 feature that allows temporal period properties (PeriodStart/PeriodEnd) to be mapped to CLR properties instead of being restricted to shadow properties. Updates: - temporal-tables.md: New 'Mapping period columns to CLR properties' section with lambda and string-based configuration examples - temporal-tables.md: Updated existing text to note shadow properties are the default, with links to the new section - whatsnew.md (EF Core 11): New subsection under SQL Server Relates to dotnet/efcore#38110 Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
roji
added a commit
to dotnet/EntityFramework.Docs
that referenced
this pull request
Apr 16, 2026
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 #26463
Summary
Temporal period properties (
PeriodStart/PeriodEnd) were previously required to be shadow properties. This PR removes that restriction, allowing them to be mapped to CLR properties on the entity type.Changes
Product code
SqlServerModelValidator— theIsShadowProperty()check on period properties is no longer enforced.HasPeriodStart/HasPeriodEndoverloads onTemporalTableBuilder<TEntity>andOwnedNavigationTemporalTableBuilder<TOwner, TDependentEntity>for strongly-typed configuration:Scaffolding
No change — period columns are still excluded from the scaffolding column query and generated as shadow properties by default.
Why it just works
SqlServerTemporalConventionalready discovers existing CLR properties viaentityTypeBuilder.Property(typeof(DateTime), periodPropertyName).ValueGenerated.OnAddOrUpdate, which setsBeforeSaveBehaviortoIgnore— so they're automatically excluded from INSERT/UPDATE even as CLR properties.Tests