Repository navigation
Add enum and comparison translators for Cosmos - #35405
Conversation
249ae47 to
6b86657
Compare
|
@ChrisJollyAU Do you still plan to finish this at some point? |
|
@AndriySvyryd Yes. There is just one test I had still outstanding. a Comos NULL issue probably Microsoft.EntityFrameworkCore.Query.Translations.EnumTranslationsCosmosTest.ToString_nullable_enum_property_projection(async: True) Message: |
|
@ChrisJollyAU There have been a lot of Cosmos changes in main, perhaps it works now |
…string Nullable<TEnum>.ToString() returns an empty string when there is no value, but the enum translator's else branch used CoalesceUndefined, which lowers to Cosmos' ?? operator. That only substitutes for undefined, not for null, so a null enum was projected as null. The guard also has to sit on the instance rather than on the converted value: unlike SQL's CAST(NULL AS nvarchar), Cosmos' ToString(null) yields the string "null" rather than propagating the null, so there is nothing left to coalesce afterwards. Updates the four affected baselines. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
|
@AndriySvyryd Found my problem. Now everything passes |
There was a problem hiding this comment.
Pull request overview
Adds Cosmos query translation support for enum method patterns (HasFlag, ToString) and comparison methods (Compare, CompareTo) by introducing CASE/IIF SQL expression support in the Cosmos query pipeline, and reshuffling/expanding translation tests accordingly.
Changes:
- Add Cosmos method-call translators for enum methods and comparison methods.
- Introduce
CaseExpression/CaseWhenClauseand implement CASE construction/type-mapping + SQL generation via nestedIIF(...). - Move/add enum
ToStringtranslation tests intoEnumTranslationsTestBaseand update provider-specific assertions; enable Cosmos comparison translation tests with new SQL baselines.
Reviewed changes
Copilot reviewed 23 out of 23 changed files in this pull request and generated 5 comments.
Show a summary per file
| File | Description |
|---|---|
| test/EFCore.SqlServer.FunctionalTests/Query/Translations/EnumTranslationsSqlServerTest.cs | Adds SQL Server assertions for enum ToString translations on basic-types model. |
| test/EFCore.SqlServer.FunctionalTests/Query/TemporalGearsOfWarQuerySqlServerTest.cs | Removes enum ToString overrides now moved out of GearsOfWar test base. |
| test/EFCore.SqlServer.FunctionalTests/Query/Inheritance/TPTGearsOfWarQuerySqlServerTest.cs | Removes enum ToString overrides now moved out of GearsOfWar test base. |
| test/EFCore.SqlServer.FunctionalTests/Query/Inheritance/TPCGearsOfWarQuerySqlServerTest.cs | Removes enum ToString overrides now moved out of GearsOfWar test base. |
| test/EFCore.SqlServer.FunctionalTests/Query/GearsOfWarQuerySqlServerTest.cs | Removes enum ToString overrides now moved out of GearsOfWar test base. |
| test/EFCore.Sqlite.FunctionalTests/Query/Translations/EnumTranslationsSqliteTest.cs | Adds SQLite assertions for enum ToString translations on basic-types model. |
| test/EFCore.Sqlite.FunctionalTests/Query/GearsOfWarQuerySqliteTest.cs | Removes enum ToString overrides now moved out of GearsOfWar test base. |
| test/EFCore.Specification.Tests/Query/Translations/EnumTranslationsTestBase.cs | Adds new enum ToString test coverage to the shared spec base. |
| test/EFCore.Specification.Tests/Query/GearsOfWarQueryTestBase.cs | Removes enum ToString tests from GearsOfWar spec base (moved to enum translations base). |
| test/EFCore.Cosmos.FunctionalTests/Query/Translations/StringTranslationsCosmosTest.cs | Updates Cosmos string comparison translation tests to assert generated IIF(...) SQL. |
| test/EFCore.Cosmos.FunctionalTests/Query/Translations/MiscellaneousTranslationsCosmosTest.cs | Updates Cosmos non-string comparison translation tests to assert generated IIF(...) SQL. |
| test/EFCore.Cosmos.FunctionalTests/Query/Translations/EnumTranslationsCosmosTest.cs | Enables Cosmos enum HasFlag and adds Cosmos enum ToString SQL assertions. |
| src/EFCore.Cosmos/Query/Internal/Translators/CosmosEnumMethodTranslator.cs | New Cosmos translator for enum HasFlag/ToString. |
| src/EFCore.Cosmos/Query/Internal/Translators/CosmosComparisonTranslator.cs | New Cosmos translator for Compare/CompareTo patterns producing CASE expressions. |
| src/EFCore.Cosmos/Query/Internal/SqlExpressionFactory.cs | Adds type-mapping support and factory methods for CASE expressions. |
| src/EFCore.Cosmos/Query/Internal/ISqlExpressionFactory.cs | Adds CASE factory APIs to Cosmos SQL expression factory interface. |
| src/EFCore.Cosmos/Query/Internal/Expressions/StructuralTypeProjectionExpression.cs | Adjusts scalar property access expression CLR type handling (nullable unwrap). |
| src/EFCore.Cosmos/Query/Internal/Expressions/CaseWhenClause.cs | Introduces Cosmos CASE WHEN clause expression node. |
| src/EFCore.Cosmos/Query/Internal/Expressions/CaseExpression.cs | Introduces Cosmos CASE expression node. |
| src/EFCore.Cosmos/Query/Internal/CosmosSqlTranslatingExpressionVisitor.cs | Adjusts parameter expression creation (notably around type/nullability handling). |
| src/EFCore.Cosmos/Query/Internal/CosmosQuerySqlGenerator.cs | Adds SQL generation for CASE by emitting nested IIF(...). |
| src/EFCore.Cosmos/Query/Internal/CosmosMethodCallTranslatorProvider.cs | Wires new enum/comparison translators into Cosmos method-call translator provider. |
| src/EFCore.Cosmos/EFCore.Cosmos.csproj | Suppresses EF9100 warning and annotates experimental precompiled-query warning. |
|
@AndriySvyryd Fixed the minor issues (mostly formatting stuff) and all still pass |
AndriySvyryd
left a comment
There was a problem hiding this comment.
Thanks for your contribution. I will merge this once main is open for v12 work
| /// <param name="caseExpression">The <see cref="CaseExpression" /> for which to generate SQL.</param> | ||
| protected virtual Expression VisitCase(CaseExpression caseExpression) | ||
| { | ||
| //using (_sqlBuilder.Indent()) |
|
@ChrisJollyAU Rebase on latest main please |
AndriySvyryd
left a comment
There was a problem hiding this comment.
Thanks for your contribution!
Adds the EnumMethod and Comparison translators to Cosmos.
HasFlagandToString.CompareTo(in comparison)The above translators are almost the same as the relational version.
With the expressions, I needed to add in the
CaseExpressionwhich is straight from the relational version (easier if it ends up both having a common base in the future).Query sql generator: Ouputs an
IIFstatement when processing aCaseExpressionMoved the respective tests to the new test classes.
Making this a draft as some of the enum
ToStringtests don't work yet. The below line (71) currently only returnsnullwhereas in relational it is a unary convert node. I suspect if combined with #35000 that should be fine after thatFixes #35317
Also continues #17246