Skip to content

Fix TODATETIMEOFFSET translation in projection - #39223

Open
Aziz-Dhiab wants to merge 6 commits into
dotnet:mainfrom
Aziz-Dhiab:fix-todatetimeoffset-in-projection
Open

Aziz-Dhiab wants to merge 6 commits into
dotnet:mainfrom
Aziz-Dhiab:fix-todatetimeoffset-in-projection

Conversation

@Aziz-Dhiab

Copy link
Copy Markdown
Contributor

fixes #38083

Support constructor translation in projection by routing any NewExpression to TranslateProjection in index-based binding, this is only done when the NewExpression has no parameters because without parameters, there's nothing to project.

This change caused potentially translatable new expressions with constant parameters in projection to cause an InvalidCastException similar to #35826 so I added a similar fix for index-based binding

Added tests to make sure the translation to TODATETIMEOFFSET is correct and tests for the InvalidCastException scenario

@Aziz-Dhiab
Aziz-Dhiab requested a review from a team as a code owner October 11, 2026 07:43
@Aziz-Dhiab Aziz-Dhiab changed the title fixes #38083 Fix TODATETIMEOFFSET translation in projection Oct 11, 2026

Copilot AI 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.

🟡 Changes recommended

The new index-based constant-conversion path lacks a regression test for the Guid materialization failure it is intended to prevent.

1 open finding
What changed in this PR

This PR enables relational constructor translation in projections, addressing the DateTimeOffset case in #38083 while preserving typed constant materialization.

Changes:

  • Route eligible constructors through SQL projection translation and apply explicit conversion to supported constants in both binding paths.
  • Add shared projection tests and provider-specific SQL assertions; update affected SQL Server baselines.
File Description
test/​EFCore.SqlServer.FunctionalTests/​Query/​Translations/​Temporal/​DateTimeOffsetTranslationsSqlServerTest.cs Asserts TODATETIMEOFFSET projection SQL.
test/​EFCore.SqlServer.FunctionalTests/​Query/​TemporalGearsOfWarQuerySqlServerTest.cs Asserts temporal date-constructor SQL.
test/​EFCore.SqlServer.FunctionalTests/​Query/​NorthwindSelectQuerySqlServerTest.cs Updates constant-conversion SQL baselines.
test/​EFCore.SqlServer.FunctionalTests/​Query/​Inheritance/​TPTGearsOfWarQuerySqlServerTest.cs Asserts TPT date-constructor SQL.
test/​EFCore.SqlServer.FunctionalTests/​Query/​Inheritance/​TPCGearsOfWarQuerySqlServerTest.cs Asserts TPC date-constructor SQL.
test/​EFCore.SqlServer.FunctionalTests/​Query/​GearsOfWarQuerySqlServerTest.cs Asserts date-constructor SQL.
test/​EFCore.Sqlite.FunctionalTests/​Query/​Translations/​Temporal/​DateTimeOffsetTranslationsSqliteTest.cs Asserts SQLite projection SQL.
test/​EFCore.Sqlite.FunctionalTests/​Query/​GearsOfWarQuerySqliteTest.cs Asserts SQLite date-constructor SQL.
test/​EFCore.Specification.Tests/​Query/​Translations/​Temporal/​DateTimeOffsetTranslationsTestBase.cs Adds a shared DateTimeOffset projection test.
test/​EFCore.Specification.Tests/​Query/​GearsOfWarQueryTestBase.cs Adds shared date-constructor projection coverage.
test/​EFCore.Cosmos.FunctionalTests/​Query/​Translations/​Temporal/​DateTimeOffsetTranslationsCosmosTest.cs Asserts Cosmos projection SQL.
src/​EFCore.Relational/​Query/​Internal/​RelationalProjectionBindingExpressionVisitor.cs Changes constructor routing and constant conversion.

🧠 Review effort: Lite

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.

NewExpression constructor translations (e.g. new DateTimeOffset) don't work in projections (Select)

2 participants